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 | PR_BEGIN_EXTERN_C
|
---|
51 |
|
---|
52 | /************************************************************************/
|
---|
53 | /************************************************************************/
|
---|
54 |
|
---|
55 | /* Return the method tables for files, tcp sockets and udp sockets */
|
---|
56 | NSPR_API(const PRIOMethods*) PR_GetFileMethods(void);
|
---|
57 | NSPR_API(const PRIOMethods*) PR_GetTCPMethods(void);
|
---|
58 | NSPR_API(const PRIOMethods*) PR_GetUDPMethods(void);
|
---|
59 | NSPR_API(const PRIOMethods*) PR_GetPipeMethods(void);
|
---|
60 |
|
---|
61 | /*
|
---|
62 | ** Convert a NSPR Socket Handle to a Native Socket handle.
|
---|
63 | ** This function will be obsoleted with the next release; avoid using it.
|
---|
64 | */
|
---|
65 | NSPR_API(PRInt32) PR_FileDesc2NativeHandle(PRFileDesc *);
|
---|
66 | NSPR_API(void) PR_ChangeFileDescNativeHandle(PRFileDesc *, PRInt32);
|
---|
67 | NSPR_API(PRFileDesc*) PR_AllocFileDesc(PRInt32 osfd,
|
---|
68 | const PRIOMethods *methods);
|
---|
69 | NSPR_API(void) PR_FreeFileDesc(PRFileDesc *fd);
|
---|
70 | /*
|
---|
71 | ** Import an existing OS file to NSPR.
|
---|
72 | */
|
---|
73 | NSPR_API(PRFileDesc*) PR_ImportFile(PRInt32 osfd);
|
---|
74 | NSPR_API(PRFileDesc*) PR_ImportPipe(PRInt32 osfd);
|
---|
75 | NSPR_API(PRFileDesc*) PR_ImportTCPSocket(PRInt32 osfd);
|
---|
76 | NSPR_API(PRFileDesc*) PR_ImportUDPSocket(PRInt32 osfd);
|
---|
77 |
|
---|
78 |
|
---|
79 | /*
|
---|
80 | *************************************************************************
|
---|
81 | * FUNCTION: PR_CreateSocketPollFd
|
---|
82 | * DESCRIPTION:
|
---|
83 | * Create a PRFileDesc wrapper for a native socket handle, for use with
|
---|
84 | * PR_Poll only
|
---|
85 | * INPUTS:
|
---|
86 | * None
|
---|
87 | * OUTPUTS:
|
---|
88 | * None
|
---|
89 | * RETURN: PRFileDesc*
|
---|
90 | * Upon successful completion, PR_CreateSocketPollFd returns a pointer
|
---|
91 | * to the PRFileDesc created for the native socket handle
|
---|
92 | * Returns a NULL pointer if the create of a new PRFileDesc failed
|
---|
93 | *
|
---|
94 | **************************************************************************
|
---|
95 | */
|
---|
96 |
|
---|
97 | NSPR_API(PRFileDesc*) PR_CreateSocketPollFd(PRInt32 osfd);
|
---|
98 |
|
---|
99 | /*
|
---|
100 | *************************************************************************
|
---|
101 | * FUNCTION: PR_DestroySocketPollFd
|
---|
102 | * DESCRIPTION:
|
---|
103 | * Destroy the PRFileDesc wrapper created by PR_CreateSocketPollFd
|
---|
104 | * INPUTS:
|
---|
105 | * None
|
---|
106 | * OUTPUTS:
|
---|
107 | * None
|
---|
108 | * RETURN: PRFileDesc*
|
---|
109 | * Upon successful completion, PR_DestroySocketPollFd returns
|
---|
110 | * PR_SUCCESS, else PR_FAILURE
|
---|
111 | *
|
---|
112 | **************************************************************************
|
---|
113 | */
|
---|
114 |
|
---|
115 | NSPR_API(PRStatus) PR_DestroySocketPollFd(PRFileDesc *fd);
|
---|
116 |
|
---|
117 |
|
---|
118 | /*
|
---|
119 | ** Macros for PR_Socket
|
---|
120 | **
|
---|
121 | ** Socket types: PR_SOCK_STREAM, PR_SOCK_DGRAM
|
---|
122 | */
|
---|
123 |
|
---|
124 | #ifdef WIN32
|
---|
125 |
|
---|
126 | #define PR_SOCK_STREAM 1
|
---|
127 | #define PR_SOCK_DGRAM 2
|
---|
128 |
|
---|
129 | #else /* WIN32 */
|
---|
130 |
|
---|
131 | #define PR_SOCK_STREAM SOCK_STREAM
|
---|
132 | #define PR_SOCK_DGRAM SOCK_DGRAM
|
---|
133 |
|
---|
134 | #endif /* WIN32 */
|
---|
135 |
|
---|
136 | /*
|
---|
137 | ** Create a new Socket; this function is obsolete.
|
---|
138 | */
|
---|
139 | NSPR_API(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto);
|
---|
140 |
|
---|
141 | /* FUNCTION: PR_LockFile
|
---|
142 | ** DESCRIPTION:
|
---|
143 | ** Lock a file for exclusive access.
|
---|
144 | ** RETURNS:
|
---|
145 | ** PR_SUCCESS when the lock is held
|
---|
146 | ** PR_FAILURE otherwise
|
---|
147 | */
|
---|
148 | NSPR_API(PRStatus) PR_LockFile(PRFileDesc *fd);
|
---|
149 |
|
---|
150 | /* FUNCTION: PR_TLockFile
|
---|
151 | ** DESCRIPTION:
|
---|
152 | ** Test and Lock a file for exclusive access. Do not block if the
|
---|
153 | ** file cannot be locked immediately.
|
---|
154 | ** RETURNS:
|
---|
155 | ** PR_SUCCESS when the lock is held
|
---|
156 | ** PR_FAILURE otherwise
|
---|
157 | */
|
---|
158 | NSPR_API(PRStatus) PR_TLockFile(PRFileDesc *fd);
|
---|
159 |
|
---|
160 | /* FUNCTION: PR_UnlockFile
|
---|
161 | ** DESCRIPTION:
|
---|
162 | ** Unlock a file which has been previously locked successfully by this
|
---|
163 | ** process.
|
---|
164 | ** RETURNS:
|
---|
165 | ** PR_SUCCESS when the lock is released
|
---|
166 | ** PR_FAILURE otherwise
|
---|
167 | */
|
---|
168 | NSPR_API(PRStatus) PR_UnlockFile(PRFileDesc *fd);
|
---|
169 |
|
---|
170 | /*
|
---|
171 | ** Emulate acceptread by accept and recv.
|
---|
172 | */
|
---|
173 | NSPR_API(PRInt32) PR_EmulateAcceptRead(PRFileDesc *sd, PRFileDesc **nd,
|
---|
174 | PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime timeout);
|
---|
175 |
|
---|
176 | /*
|
---|
177 | ** Emulate sendfile by reading from the file and writing to the socket.
|
---|
178 | ** The file is memory-mapped if memory-mapped files are supported.
|
---|
179 | */
|
---|
180 | NSPR_API(PRInt32) PR_EmulateSendFile(
|
---|
181 | PRFileDesc *networkSocket, PRSendFileData *sendData,
|
---|
182 | PRTransmitFileFlags flags, PRIntervalTime timeout);
|
---|
183 |
|
---|
184 | #ifdef WIN32
|
---|
185 | /* FUNCTION: PR_NTFast_AcceptRead
|
---|
186 | ** DESCRIPTION:
|
---|
187 | ** NT has the notion of an "accept context", which is only needed in
|
---|
188 | ** order to make certain calls. By default, a socket connected via
|
---|
189 | ** AcceptEx can only do a limited number of things without updating
|
---|
190 | ** the acceptcontext. The generic version of PR_AcceptRead always
|
---|
191 | ** updates the accept context. This version does not.
|
---|
192 | **/
|
---|
193 | NSPR_API(PRInt32) PR_NTFast_AcceptRead(PRFileDesc *sd, PRFileDesc **nd,
|
---|
194 | PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime t);
|
---|
195 |
|
---|
196 | typedef void (*_PR_AcceptTimeoutCallback)(void *);
|
---|
197 |
|
---|
198 | /* FUNCTION: PR_NTFast_AcceptRead_WithTimeoutCallback
|
---|
199 | ** DESCRIPTION:
|
---|
200 | ** The AcceptEx call combines the accept with the read function. However,
|
---|
201 | ** our daemon threads need to be able to wakeup and reliably flush their
|
---|
202 | ** log buffers if the Accept times out. However, with the current blocking
|
---|
203 | ** interface to AcceptRead, there is no way for us to timeout the Accept;
|
---|
204 | ** this is because when we timeout the Read, we can close the newly
|
---|
205 | ** socket and continue; but when we timeout the accept itself, there is no
|
---|
206 | ** new socket to timeout. So instead, this version of the function is
|
---|
207 | ** provided. After the initial timeout period elapses on the accept()
|
---|
208 | ** portion of the function, it will call the callback routine and then
|
---|
209 | ** continue the accept. If the timeout occurs on the read, it will
|
---|
210 | ** close the connection and return error.
|
---|
211 | */
|
---|
212 | NSPR_API(PRInt32) PR_NTFast_AcceptRead_WithTimeoutCallback(
|
---|
213 | PRFileDesc *sd,
|
---|
214 | PRFileDesc **nd,
|
---|
215 | PRNetAddr **raddr,
|
---|
216 | void *buf,
|
---|
217 | PRInt32 amount,
|
---|
218 | PRIntervalTime t,
|
---|
219 | _PR_AcceptTimeoutCallback callback,
|
---|
220 | void *callback_arg);
|
---|
221 |
|
---|
222 | /* FUNCTION: PR_NTFast_Accept
|
---|
223 | ** DESCRIPTION:
|
---|
224 | ** NT has the notion of an "accept context", which is only needed in
|
---|
225 | ** order to make certain calls. By default, a socket connected via
|
---|
226 | ** AcceptEx can only do a limited number of things without updating
|
---|
227 | ** the acceptcontext. The generic version of PR_Accept always
|
---|
228 | ** updates the accept context. This version does not.
|
---|
229 | **/
|
---|
230 | NSPR_API(PRFileDesc*) PR_NTFast_Accept(PRFileDesc *fd, PRNetAddr *addr,
|
---|
231 | PRIntervalTime timeout);
|
---|
232 |
|
---|
233 | /* FUNCTION: PR_NTFast_Update
|
---|
234 | ** DESCRIPTION:
|
---|
235 | ** For sockets accepted with PR_NTFast_Accept or PR_NTFastAcceptRead,
|
---|
236 | ** this function will update the accept context for those sockets,
|
---|
237 | ** so that the socket can make general purpose socket calls.
|
---|
238 | ** Without calling this, the only operations supported on the socket
|
---|
239 | ** Are PR_Read, PR_Write, PR_Transmitfile, and PR_Close.
|
---|
240 | */
|
---|
241 | NSPR_API(void) PR_NTFast_UpdateAcceptContext(PRFileDesc *acceptSock,
|
---|
242 | PRFileDesc *listenSock);
|
---|
243 |
|
---|
244 |
|
---|
245 | /* FUNCTION: PR_NT_CancelIo
|
---|
246 | ** DESCRIPTION:
|
---|
247 | ** Cancel IO operations on fd.
|
---|
248 | */
|
---|
249 | NSPR_API(PRStatus) PR_NT_CancelIo(PRFileDesc *fd);
|
---|
250 |
|
---|
251 |
|
---|
252 | #endif /* WIN32 */
|
---|
253 |
|
---|
254 | /*
|
---|
255 | ** Need external access to this on Mac so we can first set up our faux
|
---|
256 | ** environment vars
|
---|
257 | */
|
---|
258 | #ifdef XP_MAC
|
---|
259 | NSPR_API(void) PR_Init_Log(void);
|
---|
260 | #endif
|
---|
261 |
|
---|
262 |
|
---|
263 | PR_END_EXTERN_C
|
---|
264 |
|
---|
265 | #endif /* pprio_h___ */
|
---|