Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Pipe Class Reference

Provides a bidirectional "pipe" abstraction that is portable to Windows NT, SVR4 UNIX, and BSD UNIX. More...

#include <Pipe.h>

List of all members.

Public Methods

 ACE_Pipe (void)
 Default constructor (does nothing...). More...

 ACE_Pipe (ACE_HANDLE handles[2])
 Open the pipe and initialize the handles. More...

 ACE_Pipe (ACE_HANDLE read, ACE_HANDLE write)
 Initialize the <ACE_Pipe> from the <read> and <write> handles. More...

 ~ACE_Pipe (void)
 Default dtor. It doesn't close the handles for you. More...

int open (ACE_HANDLE handles[2])
 Open the pipe and initialize the handles. More...

int open (int buffer_size=ACE_DEFAULT_MAX_SOCKET_BUFSIZ)
 Open the pipe, setting the buffer size to the maximum. More...

int close (void)
 Close down the pipe HANDLEs;. More...

ACE_HANDLE read_handle (void) const
ACE_HANDLE write_handle (void) const
void dump (void) const
 Dump the state of the object. More...


Private Attributes

ACE_HANDLE handles_ [2]


Detailed Description

Provides a bidirectional "pipe" abstraction that is portable to Windows NT, SVR4 UNIX, and BSD UNIX.

Uses "name" for lookup in the ACE service repository. Obtains the object and returns it as the appropriate type.

Definition at line 36 of file Pipe.h.


Constructor & Destructor Documentation

ACE_Pipe::ACE_Pipe void   
 

Default constructor (does nothing...).

Definition at line 191 of file Pipe.cpp.

References ACE_TRACE, and handles_.

00192 {
00193   ACE_TRACE ("ACE_Pipe::ACE_Pipe");
00194 
00195   this->handles_[0] = ACE_INVALID_HANDLE;
00196   this->handles_[1] = ACE_INVALID_HANDLE;
00197 }

ACE_Pipe::ACE_Pipe ACE_HANDLE    handles[2]
 

Open the pipe and initialize the handles.

Definition at line 199 of file Pipe.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, and open.

00200 {
00201   ACE_TRACE ("ACE_Pipe::ACE_Pipe");
00202 
00203   if (this->open (handles) == -1)
00204     ACE_ERROR ((LM_ERROR,
00205                 ACE_LIB_TEXT ("ACE_Pipe::ACE_Pipe")));
00206 }

ACE_Pipe::ACE_Pipe ACE_HANDLE    read,
ACE_HANDLE    write
 

Initialize the <ACE_Pipe> from the <read> and <write> handles.

Definition at line 208 of file Pipe.cpp.

References ACE_TRACE, and handles_.

00210 {
00211   ACE_TRACE ("ACE_Pipe::ACE_Pipe");
00212   this->handles_[0] = read;
00213   this->handles_[1] = write;
00214 }

ASYS_INLINE ACE_Pipe::~ACE_Pipe void   
 

Default dtor. It doesn't close the handles for you.

Definition at line 7 of file Pipe.i.

References ACE_TRACE.

00008 {
00009   ACE_TRACE ("ACE_Pipe::~ACE_Pipe");
00010   // Notice that the destructor doesn't close the handles for you.
00011 }


Member Function Documentation

int ACE_Pipe::close void   
 

Close down the pipe HANDLEs;.

Definition at line 217 of file Pipe.cpp.

References ACE_TRACE, ACE_OS::closesocket, and handles_.

Referenced by ACE_Select_Reactor_Notify::close, ACE_Dev_Poll_Reactor_Notify::close, and open.

00218 {
00219   ACE_TRACE ("ACE_Pipe::close");
00220 
00221   int result = 0;
00222 
00223   // Note that the following will work even if we aren't closing down
00224   // sockets because <ACE_OS::closesocket> will just call <::close> in
00225   // that case!
00226 
00227   if (this->handles_[0] != ACE_INVALID_HANDLE)
00228     result = ACE_OS::closesocket (this->handles_[0]);
00229   this->handles_[0] = ACE_INVALID_HANDLE;
00230 
00231   if (this->handles_[1] != ACE_INVALID_HANDLE)
00232     result |= ACE_OS::closesocket (this->handles_[1]);
00233   this->handles_[1] = ACE_INVALID_HANDLE;
00234 
00235   return result;
00236 }

void ACE_Pipe::dump void    const
 

Dump the state of the object.

Definition at line 16 of file Pipe.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, and LM_DEBUG.

Referenced by ACE_Select_Reactor_Notify::dump, and ACE_Dev_Poll_Reactor_Notify::dump.

00017 {
00018   ACE_TRACE ("ACE_Pipe::dump");
00019   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00020   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("handles_[0] = %d"), this->handles_[0]));
00021   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nhandles_[1] = %d"), this->handles_[1]));
00022   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n")));
00023   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00024 }

int ACE_Pipe::open int    buffer_size = ACE_DEFAULT_MAX_SOCKET_BUFSIZ
 

Open the pipe, setting the buffer size to the maximum.

Definition at line 27 of file Pipe.cpp.

References ACE_SOCK_Acceptor::accept, ACE_ERROR_RETURN, ACE_IPPROTO_TCP, ACE_LIB_TEXT, ACE_LOCALHOST, ACE_TRACE, close, ACE_SOCK_Acceptor::close, ACE_SOCK_Stream::close, ACE_SOCK_Connector::connect, ENOTSUP, ACE_IPC_SAP::get_handle, ACE_SOCK::get_local_addr, ACE_INET_Addr::get_port_number, handles_, ACE_OS::ioctl, LM_ERROR, ACE_SOCK_Acceptor::open, ACE_OS::pipe, ACE_Addr::sap_any, ACE_SOCK::set_option, ACE_OS::setsockopt, and ACE_OS::socketpair.

00028 {
00029   ACE_TRACE ("ACE_Pipe::open");
00030 
00031 #if defined (ACE_WIN32) || defined (ACE_LACKS_SOCKETPAIR) || defined (__Lynx__)
00032   ACE_INET_Addr my_addr;
00033   ACE_SOCK_Acceptor acceptor;
00034   ACE_SOCK_Connector connector;
00035   ACE_SOCK_Stream reader;
00036   ACE_SOCK_Stream writer;
00037   int result = 0;
00038 
00039   // Bind listener to any port and then find out what the port was.
00040   if (acceptor.open (ACE_Addr::sap_any) == -1
00041       || acceptor.get_local_addr (my_addr) == -1)
00042     result = -1;
00043   else
00044     {
00045       ACE_INET_Addr sv_addr (my_addr.get_port_number (),
00046                              ACE_LOCALHOST);
00047 
00048       // Establish a connection within the same process.
00049       if (connector.connect (writer, sv_addr) == -1)
00050         result = -1;
00051       else if (acceptor.accept (reader) == -1)
00052         {
00053           writer.close ();
00054           result = -1;
00055         }
00056     }
00057 
00058   // Close down the acceptor endpoint since we don't need it anymore.
00059   acceptor.close ();
00060   if (result == -1)
00061     return -1;
00062 
00063   this->handles_[0] = reader.get_handle ();
00064   this->handles_[1] = writer.get_handle ();
00065 
00066 # if !defined (ACE_LACKS_TCP_NODELAY)
00067   int one = 1;
00068 
00069   // Make sure that the TCP stack doesn't try to buffer small writes.
00070   // Since this communication is purely local to the host it doesn't
00071   // affect network performance.
00072 
00073   if (writer.set_option (ACE_IPPROTO_TCP,
00074                          TCP_NODELAY,
00075                          &one,
00076                          sizeof one) == -1)
00077     {
00078       this->close ();
00079       return -1;
00080     }
00081 # endif /* ! ACE_LACKS_TCP_NODELAY */
00082 
00083 # if defined (ACE_LACKS_SOCKET_BUFSIZ)
00084     ACE_UNUSED_ARG (buffer_size);
00085 # else  /* ! ACE_LACKS_SOCKET_BUFSIZ */
00086   if (reader.set_option (SOL_SOCKET,
00087                          SO_SNDBUF,
00088                          ACE_reinterpret_cast (void *, &buffer_size),
00089                          sizeof (buffer_size)) == -1
00090       && errno != ENOTSUP)
00091     {
00092       this->close ();
00093       return -1;
00094     }
00095   else if (writer.set_option (SOL_SOCKET,
00096                               SO_RCVBUF,
00097                               ACE_reinterpret_cast (void *, &buffer_size),
00098                               sizeof (buffer_size)) == -1
00099            && errno != ENOTSUP)
00100     {
00101       this->close ();
00102       return -1;
00103     }
00104 # endif /* ! ACE_LACKS_SOCKET_BUFSIZ */
00105 
00106 #elif defined (ACE_HAS_STREAM_PIPES) || defined (__QNX__)
00107   ACE_UNUSED_ARG (buffer_size);
00108   if (ACE_OS::pipe (this->handles_) == -1)
00109     ACE_ERROR_RETURN ((LM_ERROR,
00110                        ACE_LIB_TEXT ("%p\n"),
00111                        ACE_LIB_TEXT ("pipe")),
00112                       -1);
00113 
00114 #if !defined(__QNX__)
00115   int arg = RMSGN;
00116 
00117   // Enable "msg no discard" mode, which ensures that record
00118   // boundaries are maintained when messages are sent and received.
00119   if (ACE_OS::ioctl (this->handles_[0],
00120                      I_SRDOPT,
00121                      (void *) arg) == -1
00122       || ACE_OS::ioctl (this->handles_[1],
00123                         I_SRDOPT,
00124                         (void *) arg) == -1)
00125     {
00126       this->close ();
00127       ACE_ERROR_RETURN ((LM_ERROR,
00128                          ACE_LIB_TEXT ("%p\n"),
00129                          ACE_LIB_TEXT ("ioctl")), -1);
00130     }
00131 #endif /* __QNX__ */
00132 
00133 #else  /* ! ACE_WIN32 && ! ACE_LACKS_SOCKETPAIR && ! ACE_HAS_STREAM_PIPES */
00134   if (ACE_OS::socketpair (AF_UNIX,
00135                           SOCK_STREAM,
00136                           0,
00137                           this->handles_) == -1)
00138     ACE_ERROR_RETURN ((LM_ERROR,
00139                        ACE_LIB_TEXT ("%p\n"),
00140                        ACE_LIB_TEXT ("socketpair")),
00141                       -1);
00142 # if defined (ACE_LACKS_SOCKET_BUFSIZ)
00143   ACE_UNUSED_ARG (buffer_size);
00144 # else  /* ! ACE_LACKS_SOCKET_BUFSIZ */
00145   if (ACE_OS::setsockopt (this->handles_[0],
00146                           SOL_SOCKET,
00147                           SO_RCVBUF,
00148                           ACE_reinterpret_cast (const char *,
00149                                                 &buffer_size),
00150                           sizeof (buffer_size)) == -1
00151       && errno != ENOTSUP)
00152     {
00153       this->close ();
00154       return -1;
00155     }
00156   if (ACE_OS::setsockopt (this->handles_[1],
00157                           SOL_SOCKET,
00158                           SO_SNDBUF,
00159                           ACE_reinterpret_cast (const char *, &buffer_size),
00160                           sizeof (buffer_size)) == -1
00161       && errno != ENOTSUP)
00162     {
00163       this->close ();
00164       return -1;
00165     }
00166 # endif /* ! ACE_LACKS_SOCKET_BUFSIZ */
00167 #endif  /* ! ACE_WIN32 && ! ACE_LACKS_SOCKETPAIR && ! ACE_HAS_STREAM_PIPES */
00168   // Point both the read and write HANDLES to the appropriate socket
00169   // HANDLEs.
00170 
00171   return 0;
00172 }

int ACE_Pipe::open ACE_HANDLE    handles[2]
 

Open the pipe and initialize the handles.

Definition at line 175 of file Pipe.cpp.

References ACE_TRACE, and handles_.

Referenced by ACE_AIOCB_Notify_Pipe_Manager::ACE_AIOCB_Notify_Pipe_Manager, ACE_Pipe, ACE_Select_Reactor_Notify::open, and ACE_Dev_Poll_Reactor_Notify::open.

00176 {
00177   ACE_TRACE ("ACE_Pipe::open");
00178 
00179   if (this->open () == -1)
00180     return -1;
00181   else
00182     {
00183       handles[0] = this->handles_[0];
00184       handles[1] = this->handles_[1];
00185       return 0;
00186     }
00187 }

ASYS_INLINE ACE_HANDLE ACE_Pipe::read_handle void    const
 

This is the "read" side of the pipe. Note, however, that processes can also write to this handle as well since pipes are bi-directional.

Definition at line 14 of file Pipe.i.

References ACE_TRACE, and handles_.

Referenced by ACE_Select_Reactor_Notify::dispatch_notifications, ACE_Dev_Poll_Reactor_Notify::dispatch_notifications, ACE_Select_Reactor_Notify::notify_handle, ACE_Dev_Poll_Reactor_Notify::notify_handle, ACE_Select_Reactor_Notify::open, and ACE_AIOCB_Notify_Pipe_Manager::~ACE_AIOCB_Notify_Pipe_Manager.

00015 {
00016   ACE_TRACE ("ACE_Pipe::read_handle");
00017   return this->handles_[0];
00018 }

ASYS_INLINE ACE_HANDLE ACE_Pipe::write_handle void    const
 

This is the "write" side of the pipe. Note, however, that processes can also read to this handle as well since pipes are bi-directional.

Definition at line 21 of file Pipe.i.

References ACE_TRACE, and handles_.

Referenced by ACE_AIOCB_Notify_Pipe_Manager::~ACE_AIOCB_Notify_Pipe_Manager.

00022 {
00023   ACE_TRACE ("ACE_Pipe::write_handle");
00024   return this->handles_[1];
00025 }


Member Data Documentation

ACE_HANDLE ACE_Pipe::handles_[2] [private]
 

Definition at line 81 of file Pipe.h.

Referenced by ACE_Pipe, close, open, read_handle, and write_handle.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:52:02 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002