home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-e.zip / nspr30-e / include / private / pprio.h next >
C/C++ Source or Header  |  1998-11-02  |  7KB  |  203 lines

  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 Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /*
  20. ** File:    pprio.h
  21. **
  22. ** Description:    Private definitions for I/O related structures
  23. */
  24.  
  25. #ifndef pprio_h___
  26. #define pprio_h___
  27.  
  28. #include "prtypes.h"
  29. #include "prio.h"
  30.  
  31. PR_BEGIN_EXTERN_C
  32.  
  33. /*
  34. ** File descriptors of the NSPR layer can be in one of the
  35. ** following states (stored in the 'state' field of struct
  36. ** PRFilePrivate):
  37. ** - _PR_FILEDESC_OPEN: The OS fd is open.
  38. ** - _PR_FILEDESC_CLOSED: The OS fd is closed.  The PRFileDesc
  39. **   is still open but is unusable.  The only operation allowed
  40. **   on the PRFileDesc is PR_Close().
  41. ** - _PR_FILEDESC_FREED: The OS fd is closed and the PRFileDesc
  42. **   structure is freed.
  43. */
  44.  
  45. #define _PR_FILEDESC_OPEN       0xaaaaaaaa    /* 1010101... */
  46. #define _PR_FILEDESC_CLOSED     0x55555555    /* 0101010... */
  47. #define _PR_FILEDESC_FREED      0x11111111
  48.  
  49. /************************************************************************/
  50. /************************************************************************/
  51.  
  52. /* Return the method tables for files, tcp sockets and udp sockets */
  53. PR_EXTERN(const PRIOMethods*)    PR_GetFileMethods(void);
  54. PR_EXTERN(const PRIOMethods*)    PR_GetTCPMethods(void);
  55. PR_EXTERN(const PRIOMethods*)    PR_GetUDPMethods(void);
  56.  
  57. /*
  58. ** Convert a NSPR Socket Handle to a Native Socket handle.
  59. ** This function will be obsoleted with the next release; avoid using it.
  60. */
  61. PR_EXTERN(PRInt32)      PR_FileDesc2NativeHandle(PRFileDesc *);
  62. PR_EXTERN(void)         PR_ChangeFileDescNativeHandle(PRFileDesc *, PRInt32);
  63. PR_EXTERN(PRFileDesc*)  PR_AllocFileDesc(PRInt32 osfd,
  64.                                          const PRIOMethods *methods);
  65. PR_EXTERN(void)         PR_FreeFileDesc(PRFileDesc *fd);
  66. /*
  67. ** Import an existing OS file to NSPR. 
  68. */
  69. PR_EXTERN(PRFileDesc*)  PR_ImportFile(PRInt32 osfd);
  70. PR_EXTERN(PRFileDesc*)  PR_ImportTCPSocket(PRInt32 osfd);
  71. PR_EXTERN(PRFileDesc*)  PR_ImportUDPSocket(PRInt32 osfd);
  72.  
  73. /*
  74. ** Macros for PR_Socket
  75. **
  76. ** Socket types: PR_SOCK_STREAM, PR_SOCK_DGRAM
  77. */
  78.  
  79. #ifdef WIN32
  80.  
  81. #define PR_SOCK_STREAM 1
  82. #define PR_SOCK_DGRAM 2
  83.  
  84. #else /* WIN32 */
  85.  
  86. #define PR_SOCK_STREAM SOCK_STREAM
  87. #define PR_SOCK_DGRAM SOCK_DGRAM
  88.  
  89. #endif /* WIN32 */
  90.  
  91. /*
  92. ** Create a new Socket; this function is obsolete.
  93. */
  94. PR_EXTERN(PRFileDesc*)    PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto);
  95.  
  96. /* FUNCTION: PR_LockFile
  97. ** DESCRIPTION:
  98. **    Lock a file for exclusive access.
  99. ** RETURNS:
  100. **    PR_SUCCESS when the lock is held
  101. **    PR_FAILURE otherwise
  102. */
  103. PR_EXTERN(PRStatus) PR_LockFile(PRFileDesc *fd);
  104.  
  105. /* FUNCTION: PR_TLockFile
  106. ** DESCRIPTION:
  107. **    Test and Lock a file for exclusive access.  Do not block if the
  108. **    file cannot be locked immediately.
  109. ** RETURNS:
  110. **    PR_SUCCESS when the lock is held
  111. **    PR_FAILURE otherwise
  112. */
  113. PR_EXTERN(PRStatus) PR_TLockFile(PRFileDesc *fd);
  114.  
  115. /* FUNCTION: PR_UnlockFile
  116. ** DESCRIPTION:
  117. **    Unlock a file which has been previously locked successfully by this
  118. **    process.
  119. ** RETURNS:
  120. **    PR_SUCCESS when the lock is released
  121. **    PR_FAILURE otherwise
  122. */
  123. PR_EXTERN(PRStatus) PR_UnlockFile(PRFileDesc *fd);
  124.  
  125. #ifdef WIN32
  126. /* FUNCTION: PR_NTFast_AcceptRead
  127. ** DESCRIPTION:
  128. **    NT has the notion of an "accept context", which is only needed in
  129. **    order to make certain calls.  By default, a socket connected via
  130. **    AcceptEx can only do a limited number of things without updating
  131. **    the acceptcontext.  The generic version of PR_AcceptRead always
  132. **    updates the accept context.  This version does not.
  133. **/
  134. PR_EXTERN(PRInt32) PR_NTFast_AcceptRead(PRFileDesc *sd, PRFileDesc **nd,
  135.               PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime t);
  136.  
  137. typedef void (*_PR_AcceptTimeoutCallback)(void *);
  138.  
  139. /* FUNCTION: PR_NTFast_AcceptRead_WithTimeoutCallback
  140. ** DESCRIPTION:
  141. **    The AcceptEx call combines the accept with the read function.  However,
  142. **    our daemon threads need to be able to wakeup and reliably flush their
  143. **    log buffers if the Accept times out.  However, with the current blocking
  144. **    interface to AcceptRead, there is no way for us to timeout the Accept;
  145. **    this is because when we timeout the Read, we can close the newly 
  146. **    socket and continue; but when we timeout the accept itself, there is no
  147. **    new socket to timeout.  So instead, this version of the function is
  148. **    provided.  After the initial timeout period elapses on the accept()
  149. **    portion of the function, it will call the callback routine and then
  150. **    continue the accept.   If the timeout occurs on the read, it will 
  151. **    close the connection and return error.
  152. */
  153. PR_EXTERN(PRInt32) PR_NTFast_AcceptRead_WithTimeoutCallback(
  154.               PRFileDesc *sd, 
  155.               PRFileDesc **nd,
  156.               PRNetAddr **raddr, 
  157.               void *buf, 
  158.               PRInt32 amount, 
  159.               PRIntervalTime t,
  160.               _PR_AcceptTimeoutCallback callback, 
  161.               void *callback_arg);
  162.  
  163. /* FUNCTION: PR_NTFast_Accept
  164. ** DESCRIPTION:
  165. **    NT has the notion of an "accept context", which is only needed in
  166. **    order to make certain calls.  By default, a socket connected via
  167. **    AcceptEx can only do a limited number of things without updating
  168. **    the acceptcontext.  The generic version of PR_Accept always
  169. **    updates the accept context.  This version does not.
  170. **/
  171. PR_EXTERN(PRFileDesc*)    PR_NTFast_Accept(PRFileDesc *fd, PRNetAddr *addr,
  172.                                                 PRIntervalTime timeout);
  173.  
  174. /* FUNCTION: PR_NTFast_Update
  175. ** DESCRIPTION:
  176. **    For sockets accepted with PR_NTFast_Accept or PR_NTFastAcceptRead,
  177. **    this function will update the accept context for those sockets,
  178. **    so that the socket can make general purpose socket calls.
  179. **    Without calling this, the only operations supported on the socket
  180. **    Are PR_Read, PR_Write, PR_Transmitfile, and PR_Close.
  181. */
  182. PR_EXTERN(void) PR_NTFast_UpdateAcceptContext(PRFileDesc *acceptSock, 
  183.                                         PRFileDesc *listenSock);
  184.  
  185.  
  186. /* FUNCTION: PR_NT_UseNonblock
  187. ** DESCRIPTION:
  188. **    This function only works on NT.  It tells nspr to use nonblocking io
  189. **    rather than async IO.  There is no way to use some of each.  This 
  190. **    function should be called immediately after calling PR_Init().
  191. **
  192. **    WARNING: THIS FUNCTION IS A TEMPORARY HACK AND WILL BE REMOVED SHORTLY
  193. **    (LIKE ALL FUNCTIONS IN THE PRIVATE AREA).  DO NOT USE THIS FUNCTION AT
  194. **    ALL WITHOUT CONTACTING mbelshe@netscape.com.
  195. */
  196. PR_EXTERN(void) PR_NT_UseNonblock();
  197.  
  198. #endif /* WIN32 */
  199.  
  200. PR_END_EXTERN_C
  201.  
  202. #endif /* pprio_h___ */
  203.