netwerk/base/public/nsASocketHandler.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/base/public/nsASocketHandler.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,96 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef nsASocketHandler_h__
     1.9 +#define nsASocketHandler_h__
    1.10 +
    1.11 +// socket handler used by nsISocketTransportService.
    1.12 +// methods are only called on the socket thread.
    1.13 +
    1.14 +class nsASocketHandler : public nsISupports
    1.15 +{
    1.16 +public:
    1.17 +    nsASocketHandler()
    1.18 +        : mCondition(NS_OK)
    1.19 +        , mPollFlags(0)
    1.20 +        , mPollTimeout(UINT16_MAX)
    1.21 +        , mIsPrivate(false)
    1.22 +        {}
    1.23 +
    1.24 +    //
    1.25 +    // this condition variable will be checked to determine if the socket
    1.26 +    // handler should be detached.  it must only be accessed on the socket
    1.27 +    // thread.
    1.28 +    //
    1.29 +    nsresult mCondition;
    1.30 +
    1.31 +    //
    1.32 +    // these flags can only be modified on the socket transport thread.
    1.33 +    // the socket transport service will check these flags before calling
    1.34 +    // PR_Poll.
    1.35 +    //
    1.36 +    uint16_t mPollFlags;
    1.37 +
    1.38 +    //
    1.39 +    // this value specifies the maximum amount of time in seconds that may be
    1.40 +    // spent waiting for activity on this socket.  if this timeout is reached,
    1.41 +    // then OnSocketReady will be called with outFlags = -1.
    1.42 +    //
    1.43 +    // the default value for this member is UINT16_MAX, which disables the
    1.44 +    // timeout error checking.  (i.e., a timeout value of UINT16_MAX is
    1.45 +    // never reached.)
    1.46 +    //
    1.47 +    uint16_t mPollTimeout;
    1.48 +
    1.49 +    bool mIsPrivate;
    1.50 +
    1.51 +    //
    1.52 +    // called to service a socket
    1.53 +    // 
    1.54 +    // params:
    1.55 +    //   socketRef - socket identifier
    1.56 +    //   fd        - socket file descriptor
    1.57 +    //   outFlags  - value of PR_PollDesc::out_flags after PR_Poll returns
    1.58 +    //               or -1 if a timeout occurred
    1.59 +    //
    1.60 +    virtual void OnSocketReady(PRFileDesc *fd, int16_t outFlags) = 0;
    1.61 +
    1.62 +    //
    1.63 +    // called when a socket is no longer under the control of the socket
    1.64 +    // transport service.  the socket handler may close the socket at this
    1.65 +    // point.  after this call returns, the handler will no longer be owned
    1.66 +    // by the socket transport service.
    1.67 +    //
    1.68 +    virtual void OnSocketDetached(PRFileDesc *fd) = 0;
    1.69 +
    1.70 +    //
    1.71 +    // called to determine if the socket is for a local peer.
    1.72 +    // when used for server sockets, indicates if it only accepts local
    1.73 +    // connections.
    1.74 +    //
    1.75 +    virtual void IsLocal(bool *aIsLocal) = 0;
    1.76 +
    1.77 +    //
    1.78 +    // called to determine if this socket should not be terminated when Gecko
    1.79 +    // is turned offline. This is mostly useful for the debugging server
    1.80 +    // socket.
    1.81 +    //
    1.82 +    virtual void KeepWhenOffline(bool *aKeepWhenOffline)
    1.83 +    {
    1.84 +        *aKeepWhenOffline = false;
    1.85 +    }
    1.86 +
    1.87 +    //
    1.88 +    // called when global pref for keepalive has changed.
    1.89 +    //
    1.90 +    virtual void OnKeepaliveEnabledPrefChange(bool aEnabled) { }
    1.91 +
    1.92 +    //
    1.93 +    // returns the number of bytes sent/transmitted over the socket
    1.94 +    //
    1.95 +    virtual uint64_t ByteCountSent() = 0;
    1.96 +    virtual uint64_t ByteCountReceived() = 0;
    1.97 +};
    1.98 +
    1.99 +#endif // !nsASocketHandler_h__

mercurial