ACE_SOCK_IO Class Reference

Defines the methods for the ACE socket wrapper I/O routines (e.g., send/recv). More...

#include <SOCK_IO.h>

Inheritance diagram for ACE_SOCK_IO:

Inheritance graph
[legend]
Collaboration diagram for ACE_SOCK_IO:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_SOCK_IO (void)
 Constructor.
 ~ACE_SOCK_IO (void)
 Destructor.
ssize_t recv (void *buf, size_t n, int flags, const ACE_Time_Value *timeout=0) const
 Recv an n byte buffer from the connected socket.
ssize_t recv (void *buf, size_t n, const ACE_Time_Value *timeout=0) const
 Recv an n byte buffer from the connected socket.
ssize_t recvv (iovec iov[], int n, const ACE_Time_Value *timeout=0) const
 Recv an <iovec> of size n from the connected socket.
ssize_t recvv (iovec *io_vec, const ACE_Time_Value *timeout=0) const
ssize_t recv (size_t n,...) const
 Recv n varargs messages to the connected socket.
ssize_t recv (void *buf, size_t n, ACE_OVERLAPPED *overlapped) const
 Recv n bytes via Win32 ReadFile using overlapped I/O.
ssize_t send (const void *buf, size_t n, int flags, const ACE_Time_Value *timeout=0) const
 Send an n byte buffer to the connected socket.
ssize_t send (const void *buf, size_t n, const ACE_Time_Value *timeout=0) const
 Send an n byte buffer to the connected socket.
ssize_t sendv (const iovec iov[], int n, const ACE_Time_Value *timeout=0) const
 Send an iovec of size n to the connected socket.
ssize_t send (size_t n,...) const
 Send n varargs messages to the connected socket.
ssize_t send (const void *buf, size_t n, ACE_OVERLAPPED *overlapped) const
 Send n bytes via Win32 <WriteFile> using overlapped I/O.
void dump (void) const
 Dump the state of an object.

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.

Detailed Description

Defines the methods for the ACE socket wrapper I/O routines (e.g., send/recv).

If timeout == 0, then the call behaves as a normal send/recv call, i.e., for blocking sockets, the call will block until action is possible; for non-blocking sockets, -1 will be returned with errno == EWOULDBLOCK if no action is immediately possible. If timeout != 0, the call will wait until the relative time specified in *timeout elapses. Errors are reported by -1 and 0 return values. If the operation times out, -1 is returned with errno == ETIME. If it succeeds the number of bytes transferred is returned. Methods with the extra flags argument will always result in send getting called. Methods without the extra flags argument will result in send getting called on Win32 platforms, and write getting called on non-Win32 platforms.

Definition at line 49 of file SOCK_IO.h.


Constructor & Destructor Documentation

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE ACE_SOCK_IO::ACE_SOCK_IO ( void   ) 

Constructor.

Definition at line 12 of file SOCK_IO.inl.

00013 {
00014   // ACE_TRACE ("ACE_SOCK_IO::ACE_SOCK_IO");
00015 }

ACE_INLINE ACE_SOCK_IO::~ACE_SOCK_IO ( void   ) 

Destructor.

Definition at line 18 of file SOCK_IO.inl.

00019 {
00020   // ACE_TRACE ("ACE_SOCK_IO::~ACE_SOCK_IO");
00021 }


Member Function Documentation

ACE_BEGIN_VERSIONED_NAMESPACE_DECL void ACE_SOCK_IO::dump ( void   )  const

Dump the state of an object.

Reimplemented from ACE_SOCK.

Reimplemented in ACE_LSOCK_CODgram, ACE_LSOCK_Stream, ACE_SOCK_CODgram, ACE_SOCK_SEQPACK_Association, and ACE_SOCK_Stream.

Definition at line 22 of file SOCK_IO.cpp.

References ACE_TRACE.

00023 {
00024 #if defined (ACE_HAS_DUMP)
00025   ACE_TRACE ("ACE_SOCK_IO::dump");
00026 #endif /* ACE_HAS_DUMP */
00027 }

ACE_INLINE ssize_t ACE_SOCK_IO::recv ( void *  buf,
size_t  n,
ACE_OVERLAPPED overlapped 
) const

Recv n bytes via Win32 ReadFile using overlapped I/O.

Definition at line 62 of file SOCK_IO.inl.

References ACE_TRACE, and ACE_OS::read().

00065 {
00066   ACE_TRACE ("ACE_SOCK_IO::recv");
00067   return ACE_OS::read (this->get_handle (),
00068                        (char *) buf,
00069                        n,
00070                        overlapped);
00071 }

ssize_t ACE_SOCK_IO::recv ( size_t  n,
  ... 
) const

Recv n varargs messages to the connected socket.

Definition at line 148 of file SOCK_IO.cpp.

References ACE_NEW_RETURN, ACE_TRACE, and ACE_OS::recvv().

00149 {
00150   ACE_TRACE ("ACE_SOCK_IO::recv");
00151 
00152   va_list argp;
00153   int total_tuples = ACE_Utils::truncate_cast<int> (n / 2);
00154   iovec *iovp;
00155 #if defined (ACE_HAS_ALLOCA)
00156   iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
00157 #else
00158   ACE_NEW_RETURN (iovp,
00159                   iovec[total_tuples],
00160                   -1);
00161 #endif /* !defined (ACE_HAS_ALLOCA) */
00162 
00163   va_start (argp, n);
00164 
00165   for (int i = 0; i < total_tuples; i++)
00166     {
00167       iovp[i].iov_base = va_arg (argp, char *);
00168       iovp[i].iov_len = va_arg (argp, int);
00169     }
00170 
00171   ssize_t result = ACE_OS::recvv (this->get_handle (),
00172                                   iovp,
00173                                   total_tuples);
00174 #if !defined (ACE_HAS_ALLOCA)
00175   delete [] iovp;
00176 #endif /* !defined (ACE_HAS_ALLOCA) */
00177   va_end (argp);
00178   return result;
00179 }

ACE_INLINE ssize_t ACE_SOCK_IO::recv ( void *  buf,
size_t  n,
const ACE_Time_Value timeout = 0 
) const

Recv an n byte buffer from the connected socket.

Definition at line 38 of file SOCK_IO.inl.

References ACE_TRACE, and ACE::recv().

00041 {
00042   ACE_TRACE ("ACE_SOCK_IO::recv");
00043   return ACE::recv (this->get_handle (),
00044                     buf,
00045                     len,
00046                     timeout);
00047 }

ACE_INLINE ssize_t ACE_SOCK_IO::recv ( void *  buf,
size_t  n,
int  flags,
const ACE_Time_Value timeout = 0 
) const

Recv an n byte buffer from the connected socket.

Definition at line 24 of file SOCK_IO.inl.

References ACE_TRACE, and ACE::recv().

Referenced by ACE_Service_Manager::handle_input(), ACE_Name_Proxy::recv_reply(), and recvv().

00028 {
00029   ACE_TRACE ("ACE_SOCK_IO::recv");
00030   return ACE::recv (this->get_handle (),
00031                     buf,
00032                     len,
00033                     flags,
00034                     timeout);
00035 }

ssize_t ACE_SOCK_IO::recvv ( iovec *  io_vec,
const ACE_Time_Value timeout = 0 
) const

Allows a client to read from a socket without having to provide a buffer to read. This method determines how much data is in the socket, allocates a buffer of this size, reads in the data, and returns the number of bytes read. The caller is responsible for deleting the member in the <iov_base> field of io_vec using delete [] io_vec->iov_base.

Definition at line 35 of file SOCK_IO.cpp.

References ACE_NEW_RETURN, ACE_NOTSUP_RETURN, ACE_TRACE, ACE_OS::ioctl(), recv(), ACE_Handle_Set::reset(), ACE_OS::select(), and ACE_Handle_Set::set_bit().

00037 {
00038   ACE_TRACE ("ACE_SOCK_IO::recvv");
00039 #if defined (FIONREAD)
00040   ACE_Handle_Set handle_set;
00041   handle_set.reset ();
00042   handle_set.set_bit (this->get_handle ());
00043 
00044   io_vec->iov_base = 0;
00045 
00046   // Check the status of the current socket.
00047   int select_width;
00048 #  if defined (ACE_WIN32)
00049   // This arg is ignored on Windows and causes pointer truncation
00050   // warnings on 64-bit compiles.
00051   select_width = 0;
00052 #  else
00053   select_width = int (this->get_handle ()) + 1;
00054 #  endif /* ACE_WIN32 */
00055   switch (ACE_OS::select (select_width,
00056                           handle_set,
00057                           0, 0,
00058                           timeout))
00059     {
00060     case -1:
00061       return -1;
00062       /* NOTREACHED */
00063     case 0:
00064       errno = ETIME;
00065       return -1;
00066       /* NOTREACHED */
00067     default:
00068       // Goes fine, fallthrough to get data
00069       break;
00070     }
00071 
00072   int inlen = 0;
00073 
00074   if (ACE_OS::ioctl (this->get_handle (),
00075                      FIONREAD,
00076                      &inlen) == -1)
00077     return -1;
00078   else if (inlen > 0)
00079     {
00080       ACE_NEW_RETURN (io_vec->iov_base,
00081                       char[inlen],
00082                       -1);
00083       // It's ok to blindly cast this value since 'inlen' is an int and, thus,
00084       // we can't get more than that back. Besides, if the recv() fails, we
00085       // don't want that value cast to unsigned and returned.
00086       ssize_t recv_len = this->recv (io_vec->iov_base, inlen);
00087       if (recv_len > 0)
00088         // u_long is the Windows type; size_t is everyone else's. A u_long
00089         // should go into a size_t anywhere without an issue.
00090         io_vec->iov_len = static_cast<u_long> (recv_len);
00091       return recv_len;
00092     }
00093   else
00094     return 0;
00095 #else
00096   ACE_UNUSED_ARG (io_vec);
00097   ACE_UNUSED_ARG (timeout);
00098   ACE_NOTSUP_RETURN (-1);
00099 #endif /* FIONREAD */
00100 }

ACE_INLINE ssize_t ACE_SOCK_IO::recvv ( iovec  iov[],
int  n,
const ACE_Time_Value timeout = 0 
) const

Recv an <iovec> of size n from the connected socket.

Definition at line 50 of file SOCK_IO.inl.

References ACE_TRACE, and ACE::recvv().

00053 {
00054   ACE_TRACE ("ACE_SOCK_IO::recvv");
00055   return ACE::recvv (this->get_handle (),
00056                      iov,
00057                      n,
00058                      timeout);
00059 }

ACE_INLINE ssize_t ACE_SOCK_IO::send ( const void *  buf,
size_t  n,
ACE_OVERLAPPED overlapped 
) const

Send n bytes via Win32 <WriteFile> using overlapped I/O.

Definition at line 112 of file SOCK_IO.inl.

References ACE_TRACE, and ACE_OS::write().

00115 {
00116   ACE_TRACE ("ACE_SOCK_IO::send");
00117   return ACE_OS::write (this->get_handle (),
00118                         buf,
00119                         n,
00120                         overlapped);
00121 }

ssize_t ACE_SOCK_IO::send ( size_t  n,
  ... 
) const

Send n varargs messages to the connected socket.

Definition at line 108 of file SOCK_IO.cpp.

References ACE_NEW_RETURN, ACE_TRACE, and ACE_OS::sendv().

00109 {
00110   ACE_TRACE ("ACE_SOCK_IO::send");
00111 
00112   va_list argp;
00113   int total_tuples = ACE_Utils::truncate_cast<int> (n / 2);
00114   iovec *iovp = 0;
00115 #if defined (ACE_HAS_ALLOCA)
00116   iovp = (iovec *) alloca (total_tuples * sizeof (iovec));
00117 #else
00118   ACE_NEW_RETURN (iovp,
00119                   iovec[total_tuples],
00120                   -1);
00121 #endif /* !defined (ACE_HAS_ALLOCA) */
00122 
00123   va_start (argp, n);
00124 
00125   for (int i = 0; i < total_tuples; i++)
00126     {
00127       iovp[i].iov_base = va_arg (argp, char *);
00128       iovp[i].iov_len = va_arg (argp, int);
00129     }
00130 
00131   ssize_t result = ACE_OS::sendv (this->get_handle (),
00132                                   iovp,
00133                                   total_tuples);
00134 #if !defined (ACE_HAS_ALLOCA)
00135   delete [] iovp;
00136 #endif /* !defined (ACE_HAS_ALLOCA) */
00137   va_end (argp);
00138   return result;
00139 }

ACE_INLINE ssize_t ACE_SOCK_IO::send ( const void *  buf,
size_t  n,
const ACE_Time_Value timeout = 0 
) const

Send an n byte buffer to the connected socket.

Definition at line 88 of file SOCK_IO.inl.

References ACE_TRACE, and ACE::send().

00091 {
00092   ACE_TRACE ("ACE_SOCK_IO::send");
00093   return ACE::send (this->get_handle (),
00094                     buf,
00095                     len,
00096                     timeout);
00097 }

ACE_INLINE ssize_t ACE_SOCK_IO::send ( const void *  buf,
size_t  n,
int  flags,
const ACE_Time_Value timeout = 0 
) const

Send an n byte buffer to the connected socket.

Definition at line 74 of file SOCK_IO.inl.

References ACE_TRACE, and ACE::send().

00078 {
00079   ACE_TRACE ("ACE_SOCK_IO::send");
00080   return ACE::send (this->get_handle (),
00081                     buf,
00082                     len,
00083                     flags,
00084                     timeout);
00085 }

ACE_INLINE ssize_t ACE_SOCK_IO::sendv ( const iovec  iov[],
int  n,
const ACE_Time_Value timeout = 0 
) const

Send an iovec of size n to the connected socket.

Definition at line 100 of file SOCK_IO.inl.

References ACE_TRACE, and ACE::sendv().

00103 {
00104   ACE_TRACE ("ACE_SOCK_IO::sendv");
00105   return ACE::sendv (this->get_handle (),
00106                      iov,
00107                      n,
00108                      timeout);
00109 }


Member Data Documentation

ACE_SOCK_IO::ACE_ALLOC_HOOK_DECLARE

Declare the dynamic allocation hooks.

Reimplemented from ACE_SOCK.

Reimplemented in ACE_LSOCK_CODgram, ACE_LSOCK_Stream, ACE_SOCK_CODgram, ACE_SOCK_SEQPACK_Association, and ACE_SOCK_Stream.

Definition at line 125 of file SOCK_IO.h.


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:35:38 2010 for ACE by  doxygen 1.4.7