Source code

Revision control

Other Tools

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