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