netwerk/base/src/nsUDPSocket.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* vim:set ts=2 sw=2 et cindent: */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef nsUDPSocket_h__
     7 #define nsUDPSocket_h__
     9 #include "nsIUDPSocket.h"
    10 #include "mozilla/Mutex.h"
    11 #include "nsIOutputStream.h"
    12 #include "nsAutoPtr.h"
    13 #include "nsCycleCollectionParticipant.h"
    15 //-----------------------------------------------------------------------------
    17 class nsUDPSocket : public nsASocketHandler
    18                   , public nsIUDPSocket
    19 {
    20 public:
    21   NS_DECL_THREADSAFE_ISUPPORTS
    22   NS_DECL_NSIUDPSOCKET
    24   // nsASocketHandler methods:
    25   virtual void OnSocketReady(PRFileDesc* fd, int16_t outFlags);
    26   virtual void OnSocketDetached(PRFileDesc* fd);
    27   virtual void IsLocal(bool* aIsLocal);
    29   uint64_t ByteCountSent() { return mByteWriteCount; }
    30   uint64_t ByteCountReceived() { return mByteReadCount; }
    32   void AddOutputBytes(uint64_t aBytes);
    34   nsUDPSocket();
    36   // This must be public to support older compilers (xlC_r on AIX)
    37   virtual ~nsUDPSocket();
    39 private:
    40   void OnMsgClose();
    41   void OnMsgAttach();
    43   // try attaching our socket (mFD) to the STS's poll list.
    44   nsresult TryAttach();
    46   // lock protects access to mListener;
    47   // so mListener is not cleared while being used/locked.
    48   mozilla::Mutex                       mLock;
    49   PRFileDesc                           *mFD;
    50   mozilla::net::NetAddr                mAddr;
    51   nsCOMPtr<nsIUDPSocketListener>       mListener;
    52   nsCOMPtr<nsIEventTarget>             mListenerTarget;
    53   bool                                 mAttached;
    54   nsRefPtr<nsSocketTransportService>   mSts;
    56   uint64_t   mByteReadCount;
    57   uint64_t   mByteWriteCount;
    58 };
    60 //-----------------------------------------------------------------------------
    62 class nsUDPMessage : public nsIUDPMessage
    63 {
    64 public:
    65   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    66   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsUDPMessage)
    67   NS_DECL_NSIUDPMESSAGE
    69   nsUDPMessage(mozilla::net::NetAddr* aAddr,
    70                nsIOutputStream* aOutputStream,
    71                FallibleTArray<uint8_t>& aData);
    73 private:
    74   virtual ~nsUDPMessage();
    76   mozilla::net::NetAddr mAddr;
    77   nsCOMPtr<nsIOutputStream> mOutputStream;
    78   FallibleTArray<uint8_t> mData;
    79   JS::Heap<JSObject*> mJsobj;
    80 };
    83 //-----------------------------------------------------------------------------
    85 class nsUDPOutputStream : public nsIOutputStream
    86 {
    87 public:
    88   NS_DECL_THREADSAFE_ISUPPORTS
    89   NS_DECL_NSIOUTPUTSTREAM
    91   nsUDPOutputStream(nsUDPSocket* aSocket,
    92                     PRFileDesc* aFD,
    93                     PRNetAddr& aPrClientAddr);
    94   virtual ~nsUDPOutputStream();
    96 private:
    97   nsRefPtr<nsUDPSocket>       mSocket;
    98   PRFileDesc                  *mFD;
    99   PRNetAddr                   mPrClientAddr;
   100   bool                        mIsClosed;
   101 };
   103 #endif // nsUDPSocket_h__

mercurial