michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsASocketHandler_h__ michael@0: #define nsASocketHandler_h__ michael@0: michael@0: // socket handler used by nsISocketTransportService. michael@0: // methods are only called on the socket thread. michael@0: michael@0: class nsASocketHandler : public nsISupports michael@0: { michael@0: public: michael@0: nsASocketHandler() michael@0: : mCondition(NS_OK) michael@0: , mPollFlags(0) michael@0: , mPollTimeout(UINT16_MAX) michael@0: , mIsPrivate(false) michael@0: {} michael@0: michael@0: // michael@0: // this condition variable will be checked to determine if the socket michael@0: // handler should be detached. it must only be accessed on the socket michael@0: // thread. michael@0: // michael@0: nsresult mCondition; michael@0: michael@0: // michael@0: // these flags can only be modified on the socket transport thread. michael@0: // the socket transport service will check these flags before calling michael@0: // PR_Poll. michael@0: // michael@0: uint16_t mPollFlags; michael@0: michael@0: // michael@0: // this value specifies the maximum amount of time in seconds that may be michael@0: // spent waiting for activity on this socket. if this timeout is reached, michael@0: // then OnSocketReady will be called with outFlags = -1. michael@0: // michael@0: // the default value for this member is UINT16_MAX, which disables the michael@0: // timeout error checking. (i.e., a timeout value of UINT16_MAX is michael@0: // never reached.) michael@0: // michael@0: uint16_t mPollTimeout; michael@0: michael@0: bool mIsPrivate; michael@0: michael@0: // michael@0: // called to service a socket michael@0: // michael@0: // params: michael@0: // socketRef - socket identifier michael@0: // fd - socket file descriptor michael@0: // outFlags - value of PR_PollDesc::out_flags after PR_Poll returns michael@0: // or -1 if a timeout occurred michael@0: // michael@0: virtual void OnSocketReady(PRFileDesc *fd, int16_t outFlags) = 0; michael@0: michael@0: // michael@0: // called when a socket is no longer under the control of the socket michael@0: // transport service. the socket handler may close the socket at this michael@0: // point. after this call returns, the handler will no longer be owned michael@0: // by the socket transport service. michael@0: // michael@0: virtual void OnSocketDetached(PRFileDesc *fd) = 0; michael@0: michael@0: // michael@0: // called to determine if the socket is for a local peer. michael@0: // when used for server sockets, indicates if it only accepts local michael@0: // connections. michael@0: // michael@0: virtual void IsLocal(bool *aIsLocal) = 0; michael@0: michael@0: // michael@0: // called to determine if this socket should not be terminated when Gecko michael@0: // is turned offline. This is mostly useful for the debugging server michael@0: // socket. michael@0: // michael@0: virtual void KeepWhenOffline(bool *aKeepWhenOffline) michael@0: { michael@0: *aKeepWhenOffline = false; michael@0: } michael@0: michael@0: // michael@0: // called when global pref for keepalive has changed. michael@0: // michael@0: virtual void OnKeepaliveEnabledPrefChange(bool aEnabled) { } michael@0: michael@0: // michael@0: // returns the number of bytes sent/transmitted over the socket michael@0: // michael@0: virtual uint64_t ByteCountSent() = 0; michael@0: virtual uint64_t ByteCountReceived() = 0; michael@0: }; michael@0: michael@0: #endif // !nsASocketHandler_h__