1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is the Netscape Portable Runtime (NSPR).
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998-2000
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | /*
|
---|
39 | ** File: pprio.h
|
---|
40 | **
|
---|
41 | ** Description: Private definitions for I/O related structures
|
---|
42 | */
|
---|
43 |
|
---|
44 | #ifndef pprio_h___
|
---|
45 | #define pprio_h___
|
---|
46 |
|
---|
47 | #include "prtypes.h"
|
---|
48 | #include "prio.h"
|
---|
49 |
|
---|
50 | #ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
|
---|
51 | #define PR_GetFileMethods VBoxNsprPR_GetFileMethods
|
---|
52 | #define PR_GetTCPMethods VBoxNsprPR_GetTCPMethods
|
---|
53 | #define PR_GetUDPMethods VBoxNsprPR_GetUDPMethods
|
---|
54 | #define PR_GetPipeMethods VBoxNsprPR_GetPipeMethods
|
---|
55 | #define PR_FileDesc2NativeHandle VBoxNsprPR_FileDesc2NativeHandle
|
---|
56 | #define PR_ChangeFileDescNativeHandle VBoxNsprPR_ChangeFileDescNativeHandle
|
---|
57 | #define PR_AllocFileDesc VBoxNsprPR_AllocFileDesc
|
---|
58 | #define PR_FreeFileDesc VBoxNsprPR_FreeFileDesc
|
---|
59 | #define PR_ImportFile VBoxNsprPR_ImportFile
|
---|
60 | #define PR_ImportPipe VBoxNsprPR_ImportPipe
|
---|
61 | #define PR_ImportTCPSocket VBoxNsprPR_ImportTCPSocket
|
---|
62 | #define PR_ImportUDPSocket VBoxNsprPR_ImportUDPSocket
|
---|
63 | #define PR_CreateSocketPollFd VBoxNsprPR_CreateSocketPollFd
|
---|
64 | #define PR_DestroySocketPollFd VBoxNsprPR_DestroySocketPollFd
|
---|
65 | #define PR_Socket VBoxNsprPR_Socket
|
---|
66 | #define PR_LockFile VBoxNsprPR_LockFile
|
---|
67 | #define PR_TLockFile VBoxNsprPR_TLockFile
|
---|
68 | #define PR_UnlockFile VBoxNsprPR_UnlockFile
|
---|
69 | #define PR_EmulateAcceptRead VBoxNsprPR_EmulateAcceptRead
|
---|
70 | #define PR_EmulateSendFile VBoxNsprPR_EmulateSendFile
|
---|
71 | #define PR_NTFast_AcceptRead VBoxNsprPR_NTFast_AcceptRead
|
---|
72 | #define PR_NTFast_AcceptRead_WithTimeoutCallback VBoxNsprPR_NTFast_AcceptRead_WithTimeoutCallback
|
---|
73 | #define PR_NTFast_Accept VBoxNsprPR_NTFast_Accept
|
---|
74 | #define PR_NTFast_UpdateAcceptContext VBoxNsprPR_NTFast_UpdateAcceptContext
|
---|
75 | #define PR_NT_CancelIo VBoxNsprPR_NT_CancelIo
|
---|
76 | #define PR_Init_Log VBoxNsprPR_Init_Log
|
---|
77 | #endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
|
---|
78 |
|
---|
79 | PR_BEGIN_EXTERN_C
|
---|
80 |
|
---|
81 | /************************************************************************/
|
---|
82 | /************************************************************************/
|
---|
83 |
|
---|
84 | /* Return the method tables for files, tcp sockets and udp sockets */
|
---|
85 | NSPR_API(const PRIOMethods*) PR_GetFileMethods(void);
|
---|
86 | NSPR_API(const PRIOMethods*) PR_GetTCPMethods(void);
|
---|
87 | NSPR_API(const PRIOMethods*) PR_GetUDPMethods(void);
|
---|
88 | NSPR_API(const PRIOMethods*) PR_GetPipeMethods(void);
|
---|
89 |
|
---|
90 | /*
|
---|
91 | ** Convert a NSPR Socket Handle to a Native Socket handle.
|
---|
92 | ** This function will be obsoleted with the next release; avoid using it.
|
---|
93 | */
|
---|
94 | NSPR_API(PRInt32) PR_FileDesc2NativeHandle(PRFileDesc *);
|
---|
95 | NSPR_API(void) PR_ChangeFileDescNativeHandle(PRFileDesc *, PRInt32);
|
---|
96 | NSPR_API(PRFileDesc*) PR_AllocFileDesc(PRInt32 osfd,
|
---|
97 | const PRIOMethods *methods);
|
---|
98 | NSPR_API(void) PR_FreeFileDesc(PRFileDesc *fd);
|
---|
99 | /*
|
---|
100 | ** Import an existing OS file to NSPR.
|
---|
101 | */
|
---|
102 | NSPR_API(PRFileDesc*) PR_ImportFile(PRInt32 osfd);
|
---|
103 | NSPR_API(PRFileDesc*) PR_ImportPipe(PRInt32 osfd);
|
---|
104 | NSPR_API(PRFileDesc*) PR_ImportTCPSocket(PRInt32 osfd);
|
---|
105 | NSPR_API(PRFileDesc*) PR_ImportUDPSocket(PRInt32 osfd);
|
---|
106 |
|
---|
107 |
|
---|
108 | /*
|
---|
109 | *************************************************************************
|
---|
110 | * FUNCTION: PR_CreateSocketPollFd
|
---|
111 | * DESCRIPTION:
|
---|
112 | * Create a PRFileDesc wrapper for a native socket handle, for use with
|
---|
113 | * PR_Poll only
|
---|
114 | * INPUTS:
|
---|
115 | * None
|
---|
116 | * OUTPUTS:
|
---|
117 | * None
|
---|
118 | * RETURN: PRFileDesc*
|
---|
119 | * Upon successful completion, PR_CreateSocketPollFd returns a pointer
|
---|
120 | * to the PRFileDesc created for the native socket handle
|
---|
121 | * Returns a NULL pointer if the create of a new PRFileDesc failed
|
---|
122 | *
|
---|
123 | **************************************************************************
|
---|
124 | */
|
---|
125 |
|
---|
126 | NSPR_API(PRFileDesc*) PR_CreateSocketPollFd(PRInt32 osfd);
|
---|
127 |
|
---|
128 | /*
|
---|
129 | *************************************************************************
|
---|
130 | * FUNCTION: PR_DestroySocketPollFd
|
---|
131 | * DESCRIPTION:
|
---|
132 | * Destroy the PRFileDesc wrapper created by PR_CreateSocketPollFd
|
---|
133 | * INPUTS:
|
---|
134 | * None
|
---|
135 | * OUTPUTS:
|
---|
136 | * None
|
---|
137 | * RETURN: PRFileDesc*
|
---|
138 | * Upon successful completion, PR_DestroySocketPollFd returns
|
---|
139 | * PR_SUCCESS, else PR_FAILURE
|
---|
140 | *
|
---|
141 | **************************************************************************
|
---|
142 | */
|
---|
143 |
|
---|
144 | NSPR_API(PRStatus) PR_DestroySocketPollFd(PRFileDesc *fd);
|
---|
145 |
|
---|
146 |
|
---|
147 | /*
|
---|
148 | ** Macros for PR_Socket
|
---|
149 | **
|
---|
150 | ** Socket types: PR_SOCK_STREAM, PR_SOCK_DGRAM
|
---|
151 | */
|
---|
152 |
|
---|
153 | #ifdef WIN32
|
---|
154 |
|
---|
155 | #define PR_SOCK_STREAM 1
|
---|
156 | #define PR_SOCK_DGRAM 2
|
---|
157 |
|
---|
158 | #else /* WIN32 */
|
---|
159 |
|
---|
160 | #define PR_SOCK_STREAM SOCK_STREAM
|
---|
161 | #define PR_SOCK_DGRAM SOCK_DGRAM
|
---|
162 |
|
---|
163 | #endif /* WIN32 */
|
---|
164 |
|
---|
165 | /*
|
---|
166 | ** Create a new Socket; this function is obsolete.
|
---|
167 | */
|
---|
168 | NSPR_API(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto);
|
---|
169 |
|
---|
170 | /* FUNCTION: PR_LockFile
|
---|
171 | ** DESCRIPTION:
|
---|
172 | ** Lock a file for exclusive access.
|
---|
173 | ** RETURNS:
|
---|
174 | ** PR_SUCCESS when the lock is held
|
---|
175 | ** PR_FAILURE otherwise
|
---|
176 | */
|
---|
177 | NSPR_API(PRStatus) PR_LockFile(PRFileDesc *fd);
|
---|
178 |
|
---|
179 | /* FUNCTION: PR_TLockFile
|
---|
180 | ** DESCRIPTION:
|
---|
181 | ** Test and Lock a file for exclusive access. Do not block if the
|
---|
182 | ** file cannot be locked immediately.
|
---|
183 | ** RETURNS:
|
---|
184 | ** PR_SUCCESS when the lock is held
|
---|
185 | ** PR_FAILURE otherwise
|
---|
186 | */
|
---|
187 | NSPR_API(PRStatus) PR_TLockFile(PRFileDesc *fd);
|
---|
188 |
|
---|
189 | /* FUNCTION: PR_UnlockFile
|
---|
190 | ** DESCRIPTION:
|
---|
191 | ** Unlock a file which has been previously locked successfully by this
|
---|
192 | ** process.
|
---|
193 | ** RETURNS:
|
---|
194 | ** PR_SUCCESS when the lock is released
|
---|
195 | ** PR_FAILURE otherwise
|
---|
196 | */
|
---|
197 | NSPR_API(PRStatus) PR_UnlockFile(PRFileDesc *fd);
|
---|
198 |
|
---|
199 | /*
|
---|
200 | ** Emulate acceptread by accept and recv.
|
---|
201 | */
|
---|
202 | NSPR_API(PRInt32) PR_EmulateAcceptRead(PRFileDesc *sd, PRFileDesc **nd,
|
---|
203 | PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime timeout);
|
---|
204 |
|
---|
205 | /*
|
---|
206 | ** Emulate sendfile by reading from the file and writing to the socket.
|
---|
207 | ** The file is memory-mapped if memory-mapped files are supported.
|
---|
208 | */
|
---|
209 | NSPR_API(PRInt32) PR_EmulateSendFile(
|
---|
210 | PRFileDesc *networkSocket, PRSendFileData *sendData,
|
---|
211 | PRTransmitFileFlags flags, PRIntervalTime timeout);
|
---|
212 |
|
---|
213 | #ifdef WIN32
|
---|
214 | /* FUNCTION: PR_NTFast_AcceptRead
|
---|
215 | ** DESCRIPTION:
|
---|
216 | ** NT has the notion of an "accept context", which is only needed in
|
---|
217 | ** order to make certain calls. By default, a socket connected via
|
---|
218 | ** AcceptEx can only do a limited number of things without updating
|
---|
219 | ** the acceptcontext. The generic version of PR_AcceptRead always
|
---|
220 | ** updates the accept context. This version does not.
|
---|
221 | **/
|
---|
222 | NSPR_API(PRInt32) PR_NTFast_AcceptRead(PRFileDesc *sd, PRFileDesc **nd,
|
---|
223 | PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime t);
|
---|
224 |
|
---|
225 | typedef void (*_PR_AcceptTimeoutCallback)(void *);
|
---|
226 |
|
---|
227 | /* FUNCTION: PR_NTFast_AcceptRead_WithTimeoutCallback
|
---|
228 | ** DESCRIPTION:
|
---|
229 | ** The AcceptEx call combines the accept with the read function. However,
|
---|
230 | ** our daemon threads need to be able to wakeup and reliably flush their
|
---|
231 | ** log buffers if the Accept times out. However, with the current blocking
|
---|
232 | ** interface to AcceptRead, there is no way for us to timeout the Accept;
|
---|
233 | ** this is because when we timeout the Read, we can close the newly
|
---|
234 | ** socket and continue; but when we timeout the accept itself, there is no
|
---|
235 | ** new socket to timeout. So instead, this version of the function is
|
---|
236 | ** provided. After the initial timeout period elapses on the accept()
|
---|
237 | ** portion of the function, it will call the callback routine and then
|
---|
238 | ** continue the accept. If the timeout occurs on the read, it will
|
---|
239 | ** close the connection and return error.
|
---|
240 | */
|
---|
241 | NSPR_API(PRInt32) PR_NTFast_AcceptRead_WithTimeoutCallback(
|
---|
242 | PRFileDesc *sd,
|
---|
243 | PRFileDesc **nd,
|
---|
244 | PRNetAddr **raddr,
|
---|
245 | void *buf,
|
---|
246 | PRInt32 amount,
|
---|
247 | PRIntervalTime t,
|
---|
248 | _PR_AcceptTimeoutCallback callback,
|
---|
249 | void *callback_arg);
|
---|
250 |
|
---|
251 | /* FUNCTION: PR_NTFast_Accept
|
---|
252 | ** DESCRIPTION:
|
---|
253 | ** NT has the notion of an "accept context", which is only needed in
|
---|
254 | ** order to make certain calls. By default, a socket connected via
|
---|
255 | ** AcceptEx can only do a limited number of things without updating
|
---|
256 | ** the acceptcontext. The generic version of PR_Accept always
|
---|
257 | ** updates the accept context. This version does not.
|
---|
258 | **/
|
---|
259 | NSPR_API(PRFileDesc*) PR_NTFast_Accept(PRFileDesc *fd, PRNetAddr *addr,
|
---|
260 | PRIntervalTime timeout);
|
---|
261 |
|
---|
262 | /* FUNCTION: PR_NTFast_Update
|
---|
263 | ** DESCRIPTION:
|
---|
264 | ** For sockets accepted with PR_NTFast_Accept or PR_NTFastAcceptRead,
|
---|
265 | ** this function will update the accept context for those sockets,
|
---|
266 | ** so that the socket can make general purpose socket calls.
|
---|
267 | ** Without calling this, the only operations supported on the socket
|
---|
268 | ** Are PR_Read, PR_Write, PR_Transmitfile, and PR_Close.
|
---|
269 | */
|
---|
270 | NSPR_API(void) PR_NTFast_UpdateAcceptContext(PRFileDesc *acceptSock,
|
---|
271 | PRFileDesc *listenSock);
|
---|
272 |
|
---|
273 |
|
---|
274 | /* FUNCTION: PR_NT_CancelIo
|
---|
275 | ** DESCRIPTION:
|
---|
276 | ** Cancel IO operations on fd.
|
---|
277 | */
|
---|
278 | NSPR_API(PRStatus) PR_NT_CancelIo(PRFileDesc *fd);
|
---|
279 |
|
---|
280 |
|
---|
281 | #endif /* WIN32 */
|
---|
282 |
|
---|
283 | /*
|
---|
284 | ** Need external access to this on Mac so we can first set up our faux
|
---|
285 | ** environment vars
|
---|
286 | */
|
---|
287 | #ifdef XP_MAC
|
---|
288 | NSPR_API(void) PR_Init_Log(void);
|
---|
289 | #endif
|
---|
290 |
|
---|
291 |
|
---|
292 | PR_END_EXTERN_C
|
---|
293 |
|
---|
294 | #endif /* pprio_h___ */
|
---|