home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / include / private / pprio.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.5 KB  |  173 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. NSPR_BEGIN_EXTERN_C
  32.  
  33.  
  34. #define _PR_FILEDESC_OPEN       0xaaaaaaaa    /* 1010101... */
  35. #define _PR_FILEDESC_CLOSED     0x55555555    /* 0101010... */
  36. #define _PR_FILEDESC_FREED      0x11111111
  37.  
  38. /************************************************************************/
  39. /************************************************************************/
  40.  
  41. /* Return the method tables for files, tcp sockets and udp sockets */
  42. PR_EXTERN(PRIOMethods*)    PR_GetFileMethods(void);
  43. PR_EXTERN(PRIOMethods*)    PR_GetTCPMethods(void);
  44. PR_EXTERN(PRIOMethods*)    PR_GetUDPMethods(void);
  45.  
  46. /*
  47. ** Convert a NSPR Socket Handle to a Native Socket handle.
  48. ** This function will be obsoleted with the next release; avoid using it.
  49. */
  50. PR_EXTERN(PRInt32)      PR_FileDesc2NativeHandle(PRFileDesc *);
  51. PR_EXTERN(void)         PR_ChangeFileDescNativeHandle(PRFileDesc *, PRInt32);
  52. PR_EXTERN(PRFileDesc*)  PR_AllocFileDesc(PRInt32 osfd, PRIOMethods *methods);
  53. PR_EXTERN(void)         PR_FreeFileDesc(PRFileDesc *fd);
  54. /*
  55. ** Import an existing OS file to NSPR. 
  56. */
  57. PR_EXTERN(PRFileDesc*)  PR_ImportFile(PRInt32 osfd);
  58. PR_EXTERN(PRFileDesc*)  PR_ImportTCPSocket(PRInt32 osfd);
  59. PR_EXTERN(PRFileDesc*)  PR_ImportUDPSocket(PRInt32 osfd);
  60.  
  61. /*
  62. ** Create a new Socket; this function is obsolete.
  63. */
  64. PR_EXTERN(PRFileDesc*)    PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto);
  65.  
  66. /* FUNCTION: PR_LockFile
  67. ** DESCRIPTION:
  68. **    Lock a file for exclusive access.
  69. ** RETURNS:
  70. **    PR_SUCCESS when the lock is held
  71. **    PR_FAILURE otherwise
  72. */
  73. PR_EXTERN(PRStatus) PR_LockFile(PRFileDesc *fd);
  74.  
  75. /* FUNCTION: PR_TLockFile
  76. ** DESCRIPTION:
  77. **    Test and Lock a file for exclusive access.  Do not block if the
  78. **    file cannot be locked immediately.
  79. ** RETURNS:
  80. **    PR_SUCCESS when the lock is held
  81. **    PR_FAILURE otherwise
  82. */
  83. PR_EXTERN(PRStatus) PR_TLockFile(PRFileDesc *fd);
  84.  
  85. /* FUNCTION: PR_UnlockFile
  86. ** DESCRIPTION:
  87. **    Unlock a file which has been previously locked successfully by this
  88. **    process.
  89. ** RETURNS:
  90. **    PR_SUCCESS when the lock is released
  91. **    PR_FAILURE otherwise
  92. */
  93. PR_EXTERN(PRStatus) PR_UnlockFile(PRFileDesc *fd);
  94.  
  95. #ifdef WIN32
  96. /* FUNCTION: PR_NTFast_AcceptRead
  97. ** DESCRIPTION:
  98. **    NT has the notion of an "accept context", which is only needed in
  99. **    order to make certain calls.  By default, a socket connected via
  100. **    AcceptEx can only do a limited number of things without updating
  101. **    the acceptcontext.  The generic version of PR_AcceptRead always
  102. **    updates the accept context.  This version does not.
  103. **/
  104. PR_EXTERN(PRInt32) PR_NTFast_AcceptRead(PRFileDesc *sd, PRFileDesc **nd,
  105.               PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime t);
  106.  
  107. typedef void (*_PR_AcceptTimeoutCallback)(void *);
  108.  
  109. /* FUNCTION: PR_NTFast_AcceptRead_WithTimeoutCallback
  110. ** DESCRIPTION:
  111. **    The AcceptEx call combines the accept with the read function.  However,
  112. **    our daemon threads need to be able to wakeup and reliably flush their
  113. **    log buffers if the Accept times out.  However, with the current blocking
  114. **    interface to AcceptRead, there is no way for us to timeout the Accept;
  115. **    this is because when we timeout the Read, we can close the newly 
  116. **    socket and continue; but when we timeout the accept itself, there is no
  117. **    new socket to timeout.  So instead, this version of the function is
  118. **    provided.  After the initial timeout period elapses on the accept()
  119. **    portion of the function, it will call the callback routine and then
  120. **    continue the accept.   If the timeout occurs on the read, it will 
  121. **    close the connection and return error.
  122. */
  123. PR_EXTERN(PRInt32) PR_NTFast_AcceptRead_WithTimeoutCallback(
  124.               PRFileDesc *sd, 
  125.               PRFileDesc **nd,
  126.               PRNetAddr **raddr, 
  127.               void *buf, 
  128.               PRInt32 amount, 
  129.               PRIntervalTime t,
  130.               _PR_AcceptTimeoutCallback callback, 
  131.               void *callback_arg);
  132.  
  133. /* FUNCTION: PR_NTFast_Accept
  134. ** DESCRIPTION:
  135. **    NT has the notion of an "accept context", which is only needed in
  136. **    order to make certain calls.  By default, a socket connected via
  137. **    AcceptEx can only do a limited number of things without updating
  138. **    the acceptcontext.  The generic version of PR_Accept always
  139. **    updates the accept context.  This version does not.
  140. **/
  141. PR_EXTERN(PRFileDesc*)    PR_NTFast_Accept(PRFileDesc *fd, PRNetAddr *addr,
  142.                                                 PRIntervalTime timeout);
  143.  
  144. /* FUNCTION: PR_NTFast_Update
  145. ** DESCRIPTION:
  146. **    For sockets accepted with PR_NTFast_Accept or PR_NTFastAcceptRead,
  147. **    this function will update the accept context for those sockets,
  148. **    so that the socket can make general purpose socket calls.
  149. **    Without calling this, the only operations supported on the socket
  150. **    Are PR_Read, PR_Write, PR_Transmitfile, and PR_Close.
  151. */
  152. PR_EXTERN(void) PR_NTFast_UpdateAcceptContext(PRFileDesc *acceptSock, 
  153.                                         PRFileDesc *listenSock);
  154.  
  155.  
  156. /* FUNCTION: PR_NT_UseNonblock
  157. ** DESCRIPTION:
  158. **    This function only works on NT.  It tells nspr to use nonblocking io
  159. **    rather than async IO.  There is no way to use some of each.  This 
  160. **    function should be called immediately after calling PR_Init().
  161. **
  162. **    WARNING: THIS FUNCTION IS A TEMPORARY HACK AND WILL BE REMOVED SHORTLY
  163. **    (LIKE ALL FUNCTIONS IN THE PRIVATE AREA).  DO NOT USE THIS FUNCTION AT
  164. **    ALL WITHOUT CONTACTING mbelshe@netscape.com.
  165. */
  166. PR_EXTERN(void) PR_NT_UseNonblock();
  167.  
  168. #endif /* WIN32 */
  169.  
  170. NSPR_END_EXTERN_C
  171.  
  172. #endif /* pprio_h___ */
  173.