00001 /* -*- C++ -*- */ 00002 00003 //============================================================================= 00004 /** 00005 * @file SPIPE_Acceptor.h 00006 * 00007 * $Id: SPIPE_Acceptor.h,v 1.1.1.4 2003/02/21 18:36:32 chad Exp $ 00008 * 00009 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu> 00010 * @author Prashant Jain <pjain@cs.wustl.edu> 00011 */ 00012 //============================================================================= 00013 00014 00015 #ifndef ACE_SPIPE_ACCEPTOR_H 00016 #define ACE_SPIPE_ACCEPTOR_H 00017 #include "ace/pre.h" 00018 00019 #include "ace/SPIPE_Stream.h" 00020 00021 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00022 # pragma once 00023 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00024 00025 #if defined (ACE_WIN32) 00026 #include "ace/Synch.h" 00027 #endif /* ACE_WIN32 */ 00028 00029 /** 00030 * @class ACE_SPIPE_Acceptor 00031 * 00032 * @brief A factory class that produces ACE_SPIPE_Stream objects. 00033 * 00034 * ACE_SPIPE_Acceptor is a factory class that accepts SPIPE connections. 00035 * Each accepted connection produces an ACE_SPIPE_Stream object. 00036 * 00037 * @warning Windows: Works only on Windows NT 4 and higher. To use this 00038 * class with the ACE_Reactor framework, note that the handle to 00039 * demultiplex on is an event handle and should be registered with the 00040 * ACE_Reactor::register_handler (ACE_Event_Handler *, ACE_HANDLE) method. 00041 * 00042 * @warning Works on non-Windows platforms only when @c ACE_HAS_STREAM_PIPES 00043 * is defined. 00044 * 00045 */ 00046 class ACE_Export ACE_SPIPE_Acceptor : public ACE_SPIPE 00047 { 00048 public: 00049 // = Initialization and termination methods. 00050 /// Default constructor. 00051 ACE_SPIPE_Acceptor (void); 00052 00053 /// Initiate a passive-mode STREAM pipe listener. 00054 /** 00055 * @param local_sap The name of the pipe instance to open and listen on. 00056 * @param reuse_addr Optional, and ignored. Needed for API compatibility 00057 * with other acceptor classes. 00058 * @param perms Optional, the protection mask to create the pipe 00059 * with. Ignored on Windows. 00060 * @param sa Optional, ignored on non-Windows. The 00061 * SECURITY_ATTRIBUTES to create the named pipe 00062 * instances with. This pointer is remembered and 00063 * reused on each new named pipe instance, so only 00064 * pass a value that remains valid as long as this 00065 * object does. 00066 * @param pipe_mode Optional, ignored on non-Windows. The NT pipe 00067 * mode used when creating the pipe. 00068 */ 00069 ACE_SPIPE_Acceptor (const ACE_SPIPE_Addr &local_sap, 00070 int reuse_addr = 1, 00071 int perms = ACE_DEFAULT_FILE_PERMS, 00072 LPSECURITY_ATTRIBUTES sa = 0, 00073 int pipe_mode = PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE); 00074 00075 /// Initiate a passive-mode STREAM pipe listener. 00076 /** 00077 * @param local_sap The name of the pipe instance to open and listen on. 00078 * @param reuse_addr Optional, and ignored. Needed for API compatibility 00079 * with other acceptor classes. 00080 * @param perms Optional, the protection mask to create the pipe 00081 * with. Ignored on Windows. 00082 * @param sa Optional, ignored on non-Windows. The 00083 * SECURITY_ATTRIBUTES to create the named pipe 00084 * instances with. This pointer is remembered and 00085 * reused on each new named pipe instance, so only 00086 * pass a value that remains valid as long as this 00087 * object does. 00088 * @param pipe_mode Optional, ignored on non-Windows. The NT pipe 00089 * mode used when creating the pipe. 00090 * 00091 * @retval 0 for success. 00092 * @retval -1 for failure. 00093 */ 00094 int open (const ACE_SPIPE_Addr &local_sap, 00095 int reuse_addr = 1, 00096 int perms = ACE_DEFAULT_FILE_PERMS, 00097 LPSECURITY_ATTRIBUTES sa = 0, 00098 int pipe_mode = PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE); 00099 00100 /// Close down the passive-mode STREAM pipe listener. 00101 int close (void); 00102 00103 /// Remove the underlying mounted pipe from the file system. 00104 int remove (void); 00105 00106 // = Passive connection acceptance method. 00107 /** 00108 * Accept a new data transfer connection. 00109 * 00110 * @param ipc_sap_spipe The ACE_SPIPE_Stream to initialize with the 00111 * newly-accepted pipe. 00112 * @param remote_addr Optional, accepts the address of the peer. 00113 * @param timeout 0 means block forever, {0, 0} means poll. 00114 * @param restart 1 means "restart if interrupted." 00115 * 00116 * @retval 0 for success. 00117 * @retval -1 for failure. 00118 */ 00119 int accept (ACE_SPIPE_Stream &ipc_sap_spipe, 00120 ACE_SPIPE_Addr *remote_addr = 0, 00121 ACE_Time_Value *timeout = 0, 00122 int restart = 1, 00123 int reset_new_handle = 0); 00124 00125 // = Meta-type info 00126 typedef ACE_SPIPE_Addr PEER_ADDR; 00127 typedef ACE_SPIPE_Stream PEER_STREAM; 00128 00129 /// Dump the state of an object. 00130 void dump (void) const; 00131 00132 /// Declare the dynamic allocation hooks. 00133 ACE_ALLOC_HOOK_DECLARE; 00134 00135 private: 00136 /// Create a new instance of an SPIPE. 00137 int create_new_instance (int perms = 0); 00138 00139 #if (defined (ACE_WIN32) && defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) 00140 // On Windows, the SECURITY_ATTRIBUTES specified for the initial accept 00141 // operation is reused on all subsequent pipe instances as well. 00142 LPSECURITY_ATTRIBUTES sa_; 00143 00144 // On Windows, the pipe mode to create the pipe in. This can be in 00145 // either a bytestream-oriented mode or a message-oriented mode. 00146 DWORD pipe_mode_; 00147 00148 // On Windows, the handle maintained in the ACE_IPC_SAP class is the 00149 // event handle from event_. The pipe handle is useless for telling 00150 // when a pipe connect is done/ready, and it changes on each pipe 00151 // acceptance, quite unlike other acceptor-type classes in ACE. 00152 // This allows the get_handle()-obtained handle to be used for 00153 // registering with the reactor (albeit for signal, not input) 00154 // to tell when a pipe accept is done. 00155 ACE_OVERLAPPED overlapped_; 00156 ACE_Manual_Event event_; 00157 ACE_HANDLE pipe_handle_; 00158 int already_connected_; 00159 #endif /* ACE_WIN32 */ 00160 00161 }; 00162 00163 #include "ace/post.h" 00164 #endif /* ACE_SPIPE_ACCEPTOR_H */
1.2.14 written by Dimitri van Heesch,
© 1997-2002