nsASocketHandler.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #ifndef nsASocketHandler_h__
  5. #define nsASocketHandler_h__
  6. // socket handler used by nsISocketTransportService.
  7. // methods are only called on the socket thread.
  8. class nsASocketHandler : public nsISupports
  9. {
  10. public:
  11. nsASocketHandler()
  12. : mCondition(NS_OK)
  13. , mPollFlags(0)
  14. , mPollTimeout(UINT16_MAX)
  15. , mIsPrivate(false)
  16. {}
  17. //
  18. // this condition variable will be checked to determine if the socket
  19. // handler should be detached. it must only be accessed on the socket
  20. // thread.
  21. //
  22. nsresult mCondition;
  23. //
  24. // these flags can only be modified on the socket transport thread.
  25. // the socket transport service will check these flags before calling
  26. // PR_Poll.
  27. //
  28. uint16_t mPollFlags;
  29. //
  30. // this value specifies the maximum amount of time in seconds that may be
  31. // spent waiting for activity on this socket. if this timeout is reached,
  32. // then OnSocketReady will be called with outFlags = -1.
  33. //
  34. // the default value for this member is UINT16_MAX, which disables the
  35. // timeout error checking. (i.e., a timeout value of UINT16_MAX is
  36. // never reached.)
  37. //
  38. uint16_t mPollTimeout;
  39. bool mIsPrivate;
  40. //
  41. // called to service a socket
  42. //
  43. // params:
  44. // socketRef - socket identifier
  45. // fd - socket file descriptor
  46. // outFlags - value of PR_PollDesc::out_flags after PR_Poll returns
  47. // or -1 if a timeout occurred
  48. //
  49. virtual void OnSocketReady(PRFileDesc *fd, int16_t outFlags) = 0;
  50. //
  51. // called when a socket is no longer under the control of the socket
  52. // transport service. the socket handler may close the socket at this
  53. // point. after this call returns, the handler will no longer be owned
  54. // by the socket transport service.
  55. //
  56. virtual void OnSocketDetached(PRFileDesc *fd) = 0;
  57. //
  58. // called to determine if the socket is for a local peer.
  59. // when used for server sockets, indicates if it only accepts local
  60. // connections.
  61. //
  62. virtual void IsLocal(bool *aIsLocal) = 0;
  63. //
  64. // called to determine if this socket should not be terminated when Gecko
  65. // is turned offline. This is mostly useful for the debugging server
  66. // socket.
  67. //
  68. virtual void KeepWhenOffline(bool *aKeepWhenOffline)
  69. {
  70. *aKeepWhenOffline = false;
  71. }
  72. //
  73. // called when global pref for keepalive has changed.
  74. //
  75. virtual void OnKeepaliveEnabledPrefChange(bool aEnabled) { }
  76. //
  77. // returns the number of bytes sent/transmitted over the socket
  78. //
  79. virtual uint64_t ByteCountSent() = 0;
  80. virtual uint64_t ByteCountReceived() = 0;
  81. };
  82. #endif // !nsASocketHandler_h__