nsASocketHandler.h (3058B)
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 5 #ifndef nsASocketHandler_h__ 6 #define nsASocketHandler_h__ 7 8 #include "nsError.h" 9 #include "nsINetAddr.h" 10 #include "nsISupports.h" 11 #include "prio.h" 12 13 // socket handler used by nsISocketTransportService. 14 // methods are only called on the socket thread. 15 16 class nsASocketHandler : public nsISupports { 17 public: 18 nsASocketHandler() = default; 19 20 // 21 // this condition variable will be checked to determine if the socket 22 // handler should be detached. it must only be accessed on the socket 23 // thread. 24 // 25 nsresult mCondition{NS_OK}; 26 27 // 28 // these flags can only be modified on the socket transport thread. 29 // the socket transport service will check these flags before calling 30 // PR_Poll. 31 // 32 uint16_t mPollFlags{0}; 33 34 // 35 // this value specifies the maximum amount of time in seconds that may be 36 // spent waiting for activity on this socket. if this timeout is reached, 37 // then OnSocketReady will be called with outFlags = -1. 38 // 39 // the default value for this member is UINT16_MAX, which disables the 40 // timeout error checking. (i.e., a timeout value of UINT16_MAX is 41 // never reached.) 42 // 43 uint16_t mPollTimeout{UINT16_MAX}; 44 45 bool mIsPrivate{false}; 46 47 // 48 // called to service a socket 49 // 50 // params: 51 // socketRef - socket identifier 52 // fd - socket file descriptor 53 // outFlags - value of PR_PollDesc::out_flags after PR_Poll returns 54 // or -1 if a timeout occurred 55 // 56 virtual void OnSocketReady(PRFileDesc* fd, int16_t outFlags) = 0; 57 58 // 59 // called when a socket is no longer under the control of the socket 60 // transport service. the socket handler may close the socket at this 61 // point. after this call returns, the handler will no longer be owned 62 // by the socket transport service. 63 // 64 virtual void OnSocketDetached(PRFileDesc* fd) = 0; 65 66 // 67 // called to determine if the socket is for a local peer. 68 // when used for server sockets, indicates if it only accepts local 69 // connections. 70 // 71 virtual void IsLocal(bool* aIsLocal) = 0; 72 73 // 74 // called to determine if this socket should not be terminated when Gecko 75 // is turned offline. This is mostly useful for the debugging server 76 // socket. 77 // 78 virtual void KeepWhenOffline(bool* aKeepWhenOffline) { 79 *aKeepWhenOffline = false; 80 } 81 82 // 83 // called when global pref for keepalive has changed. 84 // 85 virtual void OnKeepaliveEnabledPrefChange(bool aEnabled) {} 86 87 // 88 // called to determine the NetAddr. addr can only be assumed to be initialized 89 // when NS_OK is returned 90 // 91 virtual nsresult GetRemoteAddr(mozilla::net::NetAddr* addr) { 92 return NS_ERROR_NOT_IMPLEMENTED; 93 } 94 95 // 96 // returns the number of bytes sent/transmitted over the socket 97 // 98 virtual uint64_t ByteCountSent() = 0; 99 virtual uint64_t ByteCountReceived() = 0; 100 }; 101 102 #endif // !nsASocketHandler_h__