Defines the methods for the ACE socket wrapper I/O routines (e.g., send/recv). More...
#include <SOCK_IO.h>
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. |
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.
ACE_SOCK_IO::ACE_SOCK_IO | ( | void | ) |
Constructor.
Definition at line 12 of file SOCK_IO.inl.
{
// ACE_TRACE ("ACE_SOCK_IO::ACE_SOCK_IO");
}
ACE_SOCK_IO::~ACE_SOCK_IO | ( | void | ) |
Destructor.
Definition at line 18 of file SOCK_IO.inl.
{
// ACE_TRACE ("ACE_SOCK_IO::~ACE_SOCK_IO");
}
void ACE_SOCK_IO::dump | ( | void | ) | const |
Dump the state of an object.
Reimplemented from ACE_SOCK.
Reimplemented in ACE_SOCK_CODgram, ACE_SOCK_SEQPACK_Association, and ACE_SOCK_Stream.
Definition at line 22 of file SOCK_IO.cpp.
{ #if defined (ACE_HAS_DUMP) ACE_TRACE ("ACE_SOCK_IO::dump"); #endif /* ACE_HAS_DUMP */ }
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.
{ ACE_TRACE ("ACE_SOCK_IO::recv"); return ACE::recv (this->get_handle (), buf, len, timeout); }
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.
{ ACE_TRACE ("ACE_SOCK_IO::recv"); va_list argp; int const total_tuples = ACE_Utils::truncate_cast<int> (n / 2); iovec *iovp; #if defined (ACE_HAS_ALLOCA) iovp = (iovec *) alloca (total_tuples * sizeof (iovec)); #else ACE_NEW_RETURN (iovp, iovec[total_tuples], -1); #endif /* !defined (ACE_HAS_ALLOCA) */ va_start (argp, n); for (int i = 0; i < total_tuples; i++) { iovp[i].iov_base = va_arg (argp, char *); iovp[i].iov_len = va_arg (argp, int); } ssize_t const result = ACE_OS::recvv (this->get_handle (), iovp, total_tuples); #if !defined (ACE_HAS_ALLOCA) delete [] iovp; #endif /* !defined (ACE_HAS_ALLOCA) */ va_end (argp); return result; }
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.
{ ACE_TRACE ("ACE_SOCK_IO::recv"); return ACE::recv (this->get_handle (), buf, len, flags, timeout); }
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.
{ ACE_TRACE ("ACE_SOCK_IO::recv"); return ACE_OS::read (this->get_handle (), (char *) buf, n, overlapped); }
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.
{ ACE_TRACE ("ACE_SOCK_IO::recvv"); #if defined (FIONREAD) ACE_Handle_Set handle_set; handle_set.reset (); handle_set.set_bit (this->get_handle ()); io_vec->iov_base = 0; // Check the status of the current socket. # if defined (ACE_WIN32) // This arg is ignored on Windows and causes pointer truncation // warnings on 64-bit compiles. int select_width = 0; # else int select_width = int (this->get_handle ()) + 1; # endif /* ACE_WIN32 */ switch (ACE_OS::select (select_width, handle_set, 0, 0, timeout)) { case -1: return -1; /* NOTREACHED */ case 0: errno = ETIME; return -1; /* NOTREACHED */ default: // Goes fine, fallthrough to get data break; } int inlen = 0; if (ACE_OS::ioctl (this->get_handle (), FIONREAD, &inlen) == -1) return -1; else if (inlen > 0) { ACE_NEW_RETURN (io_vec->iov_base, char[inlen], -1); // It's ok to blindly cast this value since 'inlen' is an int and, thus, // we can't get more than that back. Besides, if the recv() fails, we // don't want that value cast to unsigned and returned. ssize_t recv_len = this->recv (io_vec->iov_base, inlen); if (recv_len > 0) // u_long is the Windows type; size_t is everyone else's. A u_long // should go into a size_t anywhere without an issue. io_vec->iov_len = static_cast<u_long> (recv_len); return recv_len; } else return 0; #else ACE_UNUSED_ARG (io_vec); ACE_UNUSED_ARG (timeout); ACE_NOTSUP_RETURN (-1); #endif /* FIONREAD */ }
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.
{ ACE_TRACE ("ACE_SOCK_IO::recvv"); return ACE::recvv (this->get_handle (), iov, n, timeout); }
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.
{ ACE_TRACE ("ACE_SOCK_IO::send"); return ACE::send (this->get_handle (), buf, len, flags, timeout); }
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.
{ ACE_TRACE ("ACE_SOCK_IO::send"); return ACE::send (this->get_handle (), buf, len, timeout); }
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.
{ ACE_TRACE ("ACE_SOCK_IO::send"); return ACE_OS::write (this->get_handle (), buf, n, overlapped); }
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.
{ ACE_TRACE ("ACE_SOCK_IO::send"); va_list argp; int const total_tuples = ACE_Utils::truncate_cast<int> (n / 2); iovec *iovp = 0; #if defined (ACE_HAS_ALLOCA) iovp = (iovec *) alloca (total_tuples * sizeof (iovec)); #else ACE_NEW_RETURN (iovp, iovec[total_tuples], -1); #endif /* !defined (ACE_HAS_ALLOCA) */ va_start (argp, n); for (int i = 0; i < total_tuples; i++) { iovp[i].iov_base = va_arg (argp, char *); iovp[i].iov_len = va_arg (argp, int); } ssize_t const result = ACE_OS::sendv (this->get_handle (), iovp, total_tuples); #if !defined (ACE_HAS_ALLOCA) delete [] iovp; #endif /* !defined (ACE_HAS_ALLOCA) */ va_end (argp); return result; }
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.
{ ACE_TRACE ("ACE_SOCK_IO::sendv"); return ACE::sendv (this->get_handle (), iov, n, timeout); }
Declare the dynamic allocation hooks.
Reimplemented from ACE_SOCK.
Reimplemented in ACE_SOCK_CODgram, ACE_SOCK_SEQPACK_Association, and ACE_SOCK_Stream.