netwerk/base/public/nsASocketHandler.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial