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