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

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

mercurial