Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

RWSocket



Module

Networking Tools: Network Communication Classes (net library)

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Data Types

Member Functions

Synopsis

#include <rw/toolpro/socket.h>
RWSocket socket;

Required Libraries

net, tls (and possibly std)

Description

RWSocket is a wrapper for the C concept of a socket. Its member functions correspond exactly with the C functions in the Berkeley sockets API. Typically, RWSocket member functions have the same names as the corresponding C API functions, but the arguments and return values may be different to reflect the C++ environment. For example, many member functions have default arguments to handle the most common cases. Some member functions take alternate parameter types that simplify the interface (for example, using the RWSockAddrBase class instead of the sockaddr structure.). Sometimes, multiple overloadings of a member function exist to provide alternate APIs for different occasions.

Almost all of the Berkeley sockets calls that deal with a single socket are encapsulated in this class. There are a few calls left out:

In addition to the functions that match the sockets API, some convenience functions are also provided. These are the functions id(), valid(), socket(), recvAtLeast(), and sendAtLeast().

The socket is not shut down by a destructor. It must be explicitly shut down by calling close(), closesocket(), or shutdown(). Use the RWPortal layer for objects that close the portal automatically using a destructor.

The socket portal provided by RWSocket has no state. All state (whether the socket blocks, etc.) is kept in the communications channel.

In many cases, Tools.h++ Professional provides a C++ wrapper for the native socket API. As a result, return values from socket API calls are returned to the caller unaltered.


NOTE: This can result in different return values, and in some cases different behavior, between calls to the same Tools.h++ Professional member functions on different platforms (BSD platforms vs. Winsock platforms, for instance).

For example, a connect call on a non-blocking socket will return with EINPROGRESS from BSD, but will return with WSAVEWOULDBLOCK from Winsock. As a result, users should consult their implementation-specific users guide to identify expected behavior.

Typedefs

SOCKET

Public Constructors

RWSocket();
RWSocket(const RWSocket&);
RWSocket(const RWSockType& socketType);
RWSocket(SOCKET existingSocket);

Copy Constructors

RWSocket(const RWSocket& x);

Assignment Operators

RWSocket& 
operator=(const RWSocket& s);

Public Member Operators

RWBoolean 
operator==(const RWSocket& s) const;

Public Member Functions

RWSocket 
accept(RWSockAddr *addr =0) const;
void 
bind(const RWSockAddrBase& address);
void 
close();
void 
closesocket();
void 
connect(const RWSockAddrBase& address);
RWSockAddr 
getpeername() const;
RWSockAddr 
getsockname() const;
void 
getsockopt(int level, int option, void *optval, int *optlen) 
           const;
int 
getsockopt(int option) const;
RWSockType
getsocktype() const;
RWCString
id(unsigned level=0);
void 
ioctl(long cmd, void *arg) const;
void 
ioctl(long cmd, int arg) const;
int  
ioctl(long cmd) const;
void 
ioctlsocket(long cmd, void *arg) const;
void 
ioctlsocket(long cmd, int arg) const;
int  
ioctlsocket(long cmd) const;
void 
listen(int backlog=5) const;
void
listen(const RWSockAddrBase& addr, int backlog=5) const;
RWCString 
recv(int flags=0) const;
int
recv(char *buf, int len, int flags=0,RWNetBuf::State* s=0)
     const;
RWCString 
recvAtLeast(int n) const;
int
recvAtLeast(char *buf, int len, int n) const;
RWCString 
recvfrom(RWSockAddr *addr=0, int flags=0) const;
int
recvfrom(char *buf, int len, RWSockAddr *addr=0, 
         int flags=0) const;
int
recvmsg(msghdr *msg, int flags=0) const;
int 
send(const RWCString& buf, int flags=0) const;
int 
send(const char *buf, int len, int flags=0) const;
void 
sendAtLeast(const RWCString& buf) const;
int 
sendAtLeast(const RWCString& buf, int n) const;
void 
sendAtLeast(const char* buf, int len) const;
int 
sendAtLeast(const char* buf, int len, int n) const;
int
sendto(const RWCString& buf, const RWSockAddrBase& to, 
       int flags=0) const;
int 
sendto(const char *buf, int len, const RWSockAddrBase& to, 
       int flags=0) const;
int 
sendmsg(msghdr *msg, int flags=0) const;
void 
setsockopt(int level, int option, void *optval, int optlen) 
           const;
void 
setsockopt(int option, int optval) const;
void 
shutdown(int how=2) const;
void 
shutdownread() const;
void
shutdownwrite() const;
SOCKET 
socket() const;
void 
socket(const RWSockType& type);
RWBoolean 
valid() const;

Protected Data Members

SOCKET 
socket_;

Protected Member Functions

void 
clearError() const;
static void 
doRaise(int err, const char *funcName);
int 
lastError() const;
void 
raise(const char *funcName) const;
void 
raiseUnlessWouldBlock(const char *funcName) const;

Global Operators

ostream&
operator<<(ostream& strm, const RWSocket& x);

Associated Macros

The following macros provide a convenient way to set the blocking mode on an RWSocket.

SET_BLOCKING(RWSocket)
SET_NON_BLOCKING(RWSocket)


Previous fileTop of DocumentContentsIndexNext file

©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.