Back to index

lightning-sunbird  0.9+nobinonly
pprio.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039 ** File:      pprio.h
00040 **
00041 ** Description:      Private definitions for I/O related structures
00042 */
00043 
00044 #ifndef pprio_h___
00045 #define pprio_h___
00046 
00047 #include "prtypes.h"
00048 #include "prio.h"
00049 
00050 PR_BEGIN_EXTERN_C
00051 
00052 /************************************************************************/
00053 /************************************************************************/
00054 
00055 /* Return the method tables for files, tcp sockets and udp sockets */
00056 NSPR_API(const PRIOMethods*)    PR_GetFileMethods(void);
00057 NSPR_API(const PRIOMethods*)    PR_GetTCPMethods(void);
00058 NSPR_API(const PRIOMethods*)    PR_GetUDPMethods(void);
00059 NSPR_API(const PRIOMethods*)    PR_GetPipeMethods(void);
00060 
00061 /*
00062 ** Convert a NSPR Socket Handle to a Native Socket handle.
00063 ** This function will be obsoleted with the next release; avoid using it.
00064 */
00065 NSPR_API(PRInt32)      PR_FileDesc2NativeHandle(PRFileDesc *);
00066 NSPR_API(void)         PR_ChangeFileDescNativeHandle(PRFileDesc *, PRInt32);
00067 NSPR_API(PRFileDesc*)  PR_AllocFileDesc(PRInt32 osfd,
00068                                          const PRIOMethods *methods);
00069 NSPR_API(void)         PR_FreeFileDesc(PRFileDesc *fd);
00070 /*
00071 ** Import an existing OS file to NSPR. 
00072 */
00073 NSPR_API(PRFileDesc*)  PR_ImportFile(PRInt32 osfd);
00074 NSPR_API(PRFileDesc*)  PR_ImportPipe(PRInt32 osfd);
00075 NSPR_API(PRFileDesc*)  PR_ImportTCPSocket(PRInt32 osfd);
00076 NSPR_API(PRFileDesc*)  PR_ImportUDPSocket(PRInt32 osfd);
00077 
00078 
00079 /*
00080  *************************************************************************
00081  * FUNCTION: PR_CreateSocketPollFd
00082  * DESCRIPTION:
00083  *     Create a PRFileDesc wrapper for a native socket handle, for use with
00084  *        PR_Poll only
00085  * INPUTS:
00086  *     None
00087  * OUTPUTS:
00088  *     None
00089  * RETURN: PRFileDesc*
00090  *     Upon successful completion, PR_CreateSocketPollFd returns a pointer
00091  *     to the PRFileDesc created for the native socket handle
00092  *     Returns a NULL pointer if the create of a new PRFileDesc failed
00093  *
00094  **************************************************************************
00095  */
00096 
00097 NSPR_API(PRFileDesc*)       PR_CreateSocketPollFd(PRInt32 osfd);
00098 
00099 /*
00100  *************************************************************************
00101  * FUNCTION: PR_DestroySocketPollFd
00102  * DESCRIPTION:
00103  *     Destroy the PRFileDesc wrapper created by PR_CreateSocketPollFd
00104  * INPUTS:
00105  *     None
00106  * OUTPUTS:
00107  *     None
00108  * RETURN: PRFileDesc*
00109  *     Upon successful completion, PR_DestroySocketPollFd returns
00110  *        PR_SUCCESS, else PR_FAILURE
00111  *
00112  **************************************************************************
00113  */
00114 
00115 NSPR_API(PRStatus) PR_DestroySocketPollFd(PRFileDesc *fd);
00116 
00117 
00118 /*
00119 ** Macros for PR_Socket
00120 **
00121 ** Socket types: PR_SOCK_STREAM, PR_SOCK_DGRAM
00122 */
00123 
00124 #ifdef WIN32
00125 
00126 #define PR_SOCK_STREAM 1
00127 #define PR_SOCK_DGRAM 2
00128 
00129 #else /* WIN32 */
00130 
00131 #define PR_SOCK_STREAM SOCK_STREAM
00132 #define PR_SOCK_DGRAM SOCK_DGRAM
00133 
00134 #endif /* WIN32 */
00135 
00136 /*
00137 ** Create a new Socket; this function is obsolete.
00138 */
00139 NSPR_API(PRFileDesc*)       PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto);
00140 
00141 /* FUNCTION: PR_LockFile
00142 ** DESCRIPTION:
00143 **    Lock a file for exclusive access.
00144 ** RETURNS:
00145 **    PR_SUCCESS when the lock is held
00146 **    PR_FAILURE otherwise
00147 */
00148 NSPR_API(PRStatus) PR_LockFile(PRFileDesc *fd);
00149 
00150 /* FUNCTION: PR_TLockFile
00151 ** DESCRIPTION:
00152 **    Test and Lock a file for exclusive access.  Do not block if the
00153 **    file cannot be locked immediately.
00154 ** RETURNS:
00155 **    PR_SUCCESS when the lock is held
00156 **    PR_FAILURE otherwise
00157 */
00158 NSPR_API(PRStatus) PR_TLockFile(PRFileDesc *fd);
00159 
00160 /* FUNCTION: PR_UnlockFile
00161 ** DESCRIPTION:
00162 **    Unlock a file which has been previously locked successfully by this
00163 **    process.
00164 ** RETURNS:
00165 **    PR_SUCCESS when the lock is released
00166 **    PR_FAILURE otherwise
00167 */
00168 NSPR_API(PRStatus) PR_UnlockFile(PRFileDesc *fd);
00169 
00170 /*
00171 ** Emulate acceptread by accept and recv.
00172 */
00173 NSPR_API(PRInt32) PR_EmulateAcceptRead(PRFileDesc *sd, PRFileDesc **nd,
00174     PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime timeout);
00175 
00176 /*
00177 ** Emulate sendfile by reading from the file and writing to the socket.
00178 ** The file is memory-mapped if memory-mapped files are supported.
00179 */
00180 NSPR_API(PRInt32) PR_EmulateSendFile(
00181     PRFileDesc *networkSocket, PRSendFileData *sendData,
00182     PRTransmitFileFlags flags, PRIntervalTime timeout);
00183 
00184 #ifdef WIN32
00185 /* FUNCTION: PR_NTFast_AcceptRead
00186 ** DESCRIPTION:
00187 **    NT has the notion of an "accept context", which is only needed in
00188 **    order to make certain calls.  By default, a socket connected via
00189 **    AcceptEx can only do a limited number of things without updating
00190 **    the acceptcontext.  The generic version of PR_AcceptRead always
00191 **    updates the accept context.  This version does not.
00192 **/
00193 NSPR_API(PRInt32) PR_NTFast_AcceptRead(PRFileDesc *sd, PRFileDesc **nd,
00194               PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime t);
00195 
00196 typedef void (*_PR_AcceptTimeoutCallback)(void *);
00197 
00198 /* FUNCTION: PR_NTFast_AcceptRead_WithTimeoutCallback
00199 ** DESCRIPTION:
00200 **    The AcceptEx call combines the accept with the read function.  However,
00201 **    our daemon threads need to be able to wakeup and reliably flush their
00202 **    log buffers if the Accept times out.  However, with the current blocking
00203 **    interface to AcceptRead, there is no way for us to timeout the Accept;
00204 **    this is because when we timeout the Read, we can close the newly 
00205 **    socket and continue; but when we timeout the accept itself, there is no
00206 **    new socket to timeout.  So instead, this version of the function is
00207 **    provided.  After the initial timeout period elapses on the accept()
00208 **    portion of the function, it will call the callback routine and then
00209 **    continue the accept.   If the timeout occurs on the read, it will 
00210 **    close the connection and return error.
00211 */
00212 NSPR_API(PRInt32) PR_NTFast_AcceptRead_WithTimeoutCallback(
00213               PRFileDesc *sd, 
00214               PRFileDesc **nd,
00215               PRNetAddr **raddr, 
00216               void *buf, 
00217               PRInt32 amount, 
00218               PRIntervalTime t,
00219               _PR_AcceptTimeoutCallback callback, 
00220               void *callback_arg);
00221 
00222 /* FUNCTION: PR_NTFast_Accept
00223 ** DESCRIPTION:
00224 **    NT has the notion of an "accept context", which is only needed in
00225 **    order to make certain calls.  By default, a socket connected via
00226 **    AcceptEx can only do a limited number of things without updating
00227 **    the acceptcontext.  The generic version of PR_Accept always
00228 **    updates the accept context.  This version does not.
00229 **/
00230 NSPR_API(PRFileDesc*)       PR_NTFast_Accept(PRFileDesc *fd, PRNetAddr *addr,
00231                                                 PRIntervalTime timeout);
00232 
00233 /* FUNCTION: PR_NTFast_Update
00234 ** DESCRIPTION:
00235 **    For sockets accepted with PR_NTFast_Accept or PR_NTFastAcceptRead,
00236 **    this function will update the accept context for those sockets,
00237 **    so that the socket can make general purpose socket calls.
00238 **    Without calling this, the only operations supported on the socket
00239 **    Are PR_Read, PR_Write, PR_Transmitfile, and PR_Close.
00240 */
00241 NSPR_API(void) PR_NTFast_UpdateAcceptContext(PRFileDesc *acceptSock, 
00242                                         PRFileDesc *listenSock);
00243 
00244 
00245 /* FUNCTION: PR_NT_CancelIo
00246 ** DESCRIPTION:
00247 **    Cancel IO operations on fd.
00248 */
00249 NSPR_API(PRStatus) PR_NT_CancelIo(PRFileDesc *fd);
00250 
00251 
00252 #endif /* WIN32 */
00253 
00254 /*
00255 ** Need external access to this on Mac so we can first set up our faux
00256 ** environment vars
00257 */
00258 #ifdef XP_MAC
00259 NSPR_API(void) PR_Init_Log(void);
00260 #endif
00261 
00262 
00263 PR_END_EXTERN_C
00264 
00265 #endif /* pprio_h___ */