nsServerSocket.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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/. */
  5. #ifndef nsServerSocket_h__
  6. #define nsServerSocket_h__
  7. #include "prio.h"
  8. #include "nsASocketHandler.h"
  9. #include "nsIServerSocket.h"
  10. #include "mozilla/Mutex.h"
  11. //-----------------------------------------------------------------------------
  12. class nsIEventTarget;
  13. namespace mozilla { namespace net {
  14. union NetAddr;
  15. class nsServerSocket : public nsASocketHandler
  16. , public nsIServerSocket
  17. {
  18. public:
  19. NS_DECL_THREADSAFE_ISUPPORTS
  20. NS_DECL_NSISERVERSOCKET
  21. // nsASocketHandler methods:
  22. virtual void OnSocketReady(PRFileDesc *fd, int16_t outFlags) override;
  23. virtual void OnSocketDetached(PRFileDesc *fd) override;
  24. virtual void IsLocal(bool *aIsLocal) override;
  25. virtual void KeepWhenOffline(bool *aKeepWhenOffline) override;
  26. virtual uint64_t ByteCountSent() override { return 0; }
  27. virtual uint64_t ByteCountReceived() override { return 0; }
  28. nsServerSocket();
  29. virtual void CreateClientTransport(PRFileDesc* clientFD,
  30. const mozilla::net::NetAddr& clientAddr);
  31. virtual nsresult SetSocketDefaults() { return NS_OK; }
  32. virtual nsresult OnSocketListen() { return NS_OK; }
  33. protected:
  34. virtual ~nsServerSocket();
  35. PRFileDesc* mFD;
  36. nsCOMPtr<nsIServerSocketListener> mListener;
  37. private:
  38. void OnMsgClose();
  39. void OnMsgAttach();
  40. // try attaching our socket (mFD) to the STS's poll list.
  41. nsresult TryAttach();
  42. // lock protects access to mListener; so it is not cleared while being used.
  43. mozilla::Mutex mLock;
  44. PRNetAddr mAddr;
  45. nsCOMPtr<nsIEventTarget> mListenerTarget;
  46. bool mAttached;
  47. bool mKeepWhenOffline;
  48. };
  49. } // namespace net
  50. } // namespace mozilla
  51. //-----------------------------------------------------------------------------
  52. #endif // nsServerSocket_h__