PageRenderTime 242ms CodeModel.GetById 181ms app.highlight 9ms RepoModel.GetById 21ms app.codeStats 1ms

/gecko_api/include/private/pprio.h

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