|
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 { |
|
13 public: |
|
14 nsASocketHandler() |
|
15 : mCondition(NS_OK) |
|
16 , mPollFlags(0) |
|
17 , mPollTimeout(UINT16_MAX) |
|
18 , mIsPrivate(false) |
|
19 {} |
|
20 |
|
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; |
|
27 |
|
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; |
|
34 |
|
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; |
|
45 |
|
46 bool mIsPrivate; |
|
47 |
|
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; |
|
58 |
|
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; |
|
66 |
|
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; |
|
73 |
|
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 } |
|
83 |
|
84 // |
|
85 // called when global pref for keepalive has changed. |
|
86 // |
|
87 virtual void OnKeepaliveEnabledPrefChange(bool aEnabled) { } |
|
88 |
|
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 }; |
|
95 |
|
96 #endif // !nsASocketHandler_h__ |