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