1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/base/src/nsUDPSocket.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 1.4 +/* vim:set ts=2 sw=2 et cindent: */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsUDPSocket_h__ 1.10 +#define nsUDPSocket_h__ 1.11 + 1.12 +#include "nsIUDPSocket.h" 1.13 +#include "mozilla/Mutex.h" 1.14 +#include "nsIOutputStream.h" 1.15 +#include "nsAutoPtr.h" 1.16 +#include "nsCycleCollectionParticipant.h" 1.17 + 1.18 +//----------------------------------------------------------------------------- 1.19 + 1.20 +class nsUDPSocket : public nsASocketHandler 1.21 + , public nsIUDPSocket 1.22 +{ 1.23 +public: 1.24 + NS_DECL_THREADSAFE_ISUPPORTS 1.25 + NS_DECL_NSIUDPSOCKET 1.26 + 1.27 + // nsASocketHandler methods: 1.28 + virtual void OnSocketReady(PRFileDesc* fd, int16_t outFlags); 1.29 + virtual void OnSocketDetached(PRFileDesc* fd); 1.30 + virtual void IsLocal(bool* aIsLocal); 1.31 + 1.32 + uint64_t ByteCountSent() { return mByteWriteCount; } 1.33 + uint64_t ByteCountReceived() { return mByteReadCount; } 1.34 + 1.35 + void AddOutputBytes(uint64_t aBytes); 1.36 + 1.37 + nsUDPSocket(); 1.38 + 1.39 + // This must be public to support older compilers (xlC_r on AIX) 1.40 + virtual ~nsUDPSocket(); 1.41 + 1.42 +private: 1.43 + void OnMsgClose(); 1.44 + void OnMsgAttach(); 1.45 + 1.46 + // try attaching our socket (mFD) to the STS's poll list. 1.47 + nsresult TryAttach(); 1.48 + 1.49 + // lock protects access to mListener; 1.50 + // so mListener is not cleared while being used/locked. 1.51 + mozilla::Mutex mLock; 1.52 + PRFileDesc *mFD; 1.53 + mozilla::net::NetAddr mAddr; 1.54 + nsCOMPtr<nsIUDPSocketListener> mListener; 1.55 + nsCOMPtr<nsIEventTarget> mListenerTarget; 1.56 + bool mAttached; 1.57 + nsRefPtr<nsSocketTransportService> mSts; 1.58 + 1.59 + uint64_t mByteReadCount; 1.60 + uint64_t mByteWriteCount; 1.61 +}; 1.62 + 1.63 +//----------------------------------------------------------------------------- 1.64 + 1.65 +class nsUDPMessage : public nsIUDPMessage 1.66 +{ 1.67 +public: 1.68 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.69 + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsUDPMessage) 1.70 + NS_DECL_NSIUDPMESSAGE 1.71 + 1.72 + nsUDPMessage(mozilla::net::NetAddr* aAddr, 1.73 + nsIOutputStream* aOutputStream, 1.74 + FallibleTArray<uint8_t>& aData); 1.75 + 1.76 +private: 1.77 + virtual ~nsUDPMessage(); 1.78 + 1.79 + mozilla::net::NetAddr mAddr; 1.80 + nsCOMPtr<nsIOutputStream> mOutputStream; 1.81 + FallibleTArray<uint8_t> mData; 1.82 + JS::Heap<JSObject*> mJsobj; 1.83 +}; 1.84 + 1.85 + 1.86 +//----------------------------------------------------------------------------- 1.87 + 1.88 +class nsUDPOutputStream : public nsIOutputStream 1.89 +{ 1.90 +public: 1.91 + NS_DECL_THREADSAFE_ISUPPORTS 1.92 + NS_DECL_NSIOUTPUTSTREAM 1.93 + 1.94 + nsUDPOutputStream(nsUDPSocket* aSocket, 1.95 + PRFileDesc* aFD, 1.96 + PRNetAddr& aPrClientAddr); 1.97 + virtual ~nsUDPOutputStream(); 1.98 + 1.99 +private: 1.100 + nsRefPtr<nsUDPSocket> mSocket; 1.101 + PRFileDesc *mFD; 1.102 + PRNetAddr mPrClientAddr; 1.103 + bool mIsClosed; 1.104 +}; 1.105 + 1.106 +#endif // nsUDPSocket_h__