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_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_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

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.

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

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.

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 147 of file SOCK_IO.cpp.

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

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.

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

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.

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.

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

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.

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

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.

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 107 of file SOCK_IO.cpp.

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

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.

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

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.

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

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.

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

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:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Sun Nov 22 23:16:24 2009 for ACE by  doxygen 1.6.1