class Socket

Socket class.

Public Methods

Socket(void)
Construct a socket.
virtual ~Socket(void)
Destructor
MsgAddr getAddr(void) const
Get socket IP address.
MsgAddr getPartner(void) const
Get socket IP address.
int getRecvBuf(void) const
Get the receive buffer length..
int getSendBuf(void) const
Get the send buffer length..
bool isConnected(void) const
Test if socket is connected.
bool isOpen(void) const
Test if socket is open.
virtual error_t async(bool enable=true)
Allow asynchronous message handling.
virtual error_t bind(const MsgAddr* addr)
Bind socket to an address.
virtual error_t connect(const MsgAddr& addr)
connect to a partner address.
virtual error_t disconnect(void)
Disconnect from partner.
virtual error_t read(char* data, size_t len)
Receive a message.
virtual error_t receive(Buffer** Data)
Receive a message.
virtual error_t receive(Buffer* Data)
Receive a message.
virtual error_t send(Buffer* b)
Send a message.
virtual error_t send(const MsgAddr& to, Buffer* b)
Send a message.
error_t wait(wtime_t maxtime) const
Wait for a message.
void setPool(BufferPool* pool)
Specify a buffer pool.
void setPool(SocketPool* pool)
Specify asocket pool.
error_t setRecvBuf(int nBytes)
Specify receive buffer length.
error_t setSendBuf(int nBytes)
Specify send buffer length.
void Return(void)
Return Socket to its pool.

Documentation

Class to manipulate sockets. The socket class is a generic socket API.
Socket(void)
Construct an empty socket.
Parameters:
addr - Pointer to the address to which the socket will be bound.

virtual ~Socket(void)
Release the socket and delete all asociated storage.

MsgAddr getAddr(void) const
Get the address to which the socket is bound. If the IP-Node portion of the address is zero, it indicates that the same port is allocated on ALL networks known by the node.
Returns:
The IP address to which the socket is bound socket.

MsgAddr getPartner(void) const
Get the address of the latest communication partner of this socket. If a connection has been made, the partner address will be the address of socket to which it is connected. If no connection has been made, the address specifies the port to which a message was most recently sent or from which a message was most recently received. The IP node portion of the address may be zero if the latest message was sent to or received from the current node.
Returns:
The IP address to which the socket is bound socket.

int getRecvBuf(void) const
Get the system receive buffer length.
Returns:
The number of bytes allocated for the system receive buffer.

int getSendBuf(void) const
Get the system send buffer length.
Returns:
The number of bytes allocated for the system send buffer.

bool isConnected(void) const
Test if the socket is connected to a partner.
Returns:
true if the socket is connected.

bool isOpen(void) const
Test whether the socket is open.
Returns:
true if the socket is open.

virtual error_t async(bool enable=true)
Enable or disable asynchronous operation of the socket. If asynchronous operation is enabled, the socket will generate a SIGIO signal each time a message is received for the socket. Note that a SIGIO signal may be generated at any time after asynchronous operation has been enabled, so that SIGIO handling should be specified to the operating system before asynchronous operation is enabled.
Returns:
Standard lmsg error codes (OK, NotOpen or SystemError).

virtual error_t bind(const MsgAddr* addr)
Bind this socket to a specified address.
Returns:
Standard lmsg error codes (OK, NotOpen or SystemError).
Parameters:
addr - Address of the socket.

virtual error_t connect(const MsgAddr& addr)
Connect this socket to a specified partner socket. If the connection is successful, the socket patner address is updated.
Returns:
Standard lmsg error codes (OK, NotOpen or SystemError).
Parameters:
addr - Address of partner to which a connection is to be made.

virtual error_t disconnect(void)
Disconnect the socket from a ciurrent parner. If no connection has been made, diconnect returns successfully.
Returns:
Standard lmsg error codes (OK, NotOpen or SystemError).

virtual error_t read(char* data, size_t len)
Read data from a socket.
Returns:
Standard lmsg error codes (OK, NotOpen or SystemError).
Parameters:
Data - Address of data buffer.
len - Number of bytes to read.

virtual error_t receive(Buffer** Data)
Receive a message from a partner socket. If the socket is connected, the message will be received from the connected partner. If no connection has been made, the message may be received from any port. The socket partner address is updated with the IP address of the port from which the message was received.
Returns:
Standard lmsg error codes (OK, NotOpen or SystemError).
Parameters:
Data - Address of pointer in which the address of the buffer containing the received message will be stored.

virtual error_t receive(Buffer* Data)
Receive a message from a partner socket. If the socket is connected, the message will be received from the connected partner. If no connection has been made, the message may be received from any port. The socket partner address is updated with the IP address of the port from which the message was received.
Returns:
Standard lmsg error codes (OK, NotOpen or SystemError).
Parameters:
Data - Address of the buffer to receive the message.

virtual error_t send(Buffer* b)
Send a message to a specified partner.
Returns:
Standard lmsg error codes (OK, NotOpen or SystemError).
Parameters:
to - Address of port to which the message will be sent.
b - Buffer containing the message to be sent.

virtual error_t send(const MsgAddr& to, Buffer* b)
Send a message to a specified partner.
Returns:
Standard lmsg error codes (OK, NotOpen or SystemError).
Parameters:
to - Address of port to which the message will be sent.
b - Buffer containing the message to be sent.

error_t wait(wtime_t maxtime) const
Wait a specified maximum time or until a message is received. Wait can be used to test for an available message by specifying a zero wait time or to wait forever until a message is received by specifying a negative wait time;
Returns:
lmsg error codes (OK, NotOpen, SystemError or TimeOut).
Parameters:
maxtime - Maximum time to wait in seconds.

void setPool(BufferPool* pool)
Specify a buffer pool to be used for received messages.
Parameters:
pool - Pointer to the buffer pool

void setPool(SocketPool* pool)
Specify a pool of which this socket is to be a member.
Parameters:
pool - Pointer to the socket pool

error_t setRecvBuf(int nBytes)
Specify a system receive buffer size.
Parameters:
nBytes - Receive buffer length

error_t setSendBuf(int nBytes)
Specify a system send buffer size.
Parameters:
nBytes - Send buffer length

void Return(void)
Return the socket to its pool.


This class has no child classes.
Author:
John Zweizig
Version:
1.2; Modified October 16, 2000

alphabetic index hierarchy of classes


generated by doc++