Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MCSocket Class Reference

Socket base class. More...

#include <mcllib/MCSocket.h>

Inheritance diagram for MCSocket:

MCIOBase MCBase MCCLSocket MCCOSocket MCUDPSocket MCCOUDPSocket MCStreamSocket MCTCPSocket List of all members.

Public Member Functions

void bind (const MCNetAddr &addr)
 Bind a socket to a local address.
bool getNonBlock () const
 Determine if socket is non-blocking.
mcuint32 getRecvBufferSize () const
 Get the size of the receive buffer.
bool getReuseAddr () const
 Determine if the socket address can be reused at bind time.
mcuint32 getSendBufferSize () const
 Get the size of the send buffer.
MCNetAddr getSockName () const
 Get the local address of the socket.
mcuint32 getTos () const
 Get the type of service of the socket.
mcuint32 getTtl () const
 Get the time-to-live of the soket.
MCRecvFromResult recvFrom (void *buf, mcint32 len, mcinterval_t timeout=MCIntervalInfinite)
 Receive data from a peer.
mcint32 sendTo (const MCNetAddr &addr, const void *buf, mcint32 len, mcinterval_t timeout=MCIntervalInfinite)
 Send data to a peer.
void setNonBlock (bool nonBlock)
 Set the blocking state of the socket.
void setRecvBufferSize (mcuint32 sz)
 Set the receive buffer size.
void setReuseAddr (bool reuse)
 Set the socket to allow or disallow resuse of an address during bind.
void setSendBufferSize (mcuint32 sz)
 Set the send buffer size.
void setTos (mcuint32 tos)
 Set the type of service.
void setTtl (mcuint32 ttl)
 Set the time to live.
 ~MCSocket ()
 Close the socket and free resources.

Protected Member Functions

 MCSocket (void *impl)
 Construct from an implementation.
 MCSocket ()
 Default constructor for use by derived classes.

Detailed Description

Socket base class.

Sockets allow intra-system and inter-system IPC. A socket forms one end of a communication path. An address is used to determine what the other end of the communication path is.


Constructor & Destructor Documentation

~MCSocket  ) 
 

Close the socket and free resources.

This does not perform a shutdown() first.

MCSocket void *  impl  )  [protected]
 

Construct from an implementation.

The implementation object must be derived from MCSockBaseImpl


Member Function Documentation

void bind const MCNetAddr addr  ) 
 

Bind a socket to a local address.

If the address cannot be bound an exception is thrown.

Parameters:
addr the address to bind the socket to

bool getNonBlock  )  const
 

Determine if socket is non-blocking.

If the socket is non-blocking, send and receive operations will throw an exception if the operation would block.

Returns:
true if the socket is non-blocking

mcuint32 getRecvBufferSize  )  const
 

Get the size of the receive buffer.

Returns:
the size of the receive buffer

bool getReuseAddr  )  const
 

Determine if the socket address can be reused at bind time.

If the socket address cannot be re-used, a bind() against an address which is already in use will fail. Because sockets may linger in the system after they are closed, or if they were not closed properly, it may be necessary to force re-use of an existing address.

Returns:
true if socket address can be reused at bind time

mcuint32 getSendBufferSize  )  const
 

Get the size of the send buffer.

Returns:
the size of the send buffer

MCNetAddr getSockName  )  const
 

Get the local address of the socket.

The socket must be bound. If the socket name cannot be obtained an exception is thrown.

Returns:
an MCNetAddr representing the local address of the socket

mcuint32 getTos  )  const
 

Get the type of service of the socket.

Returns:
the type of service

mcuint32 getTtl  )  const
 

Get the time-to-live of the soket.

Returns:
the time to live

MCRecvFromResult recvFrom void *  buf,
mcint32  len,
mcinterval_t  timeout = MCIntervalInfinite
 

Receive data from a peer.

If the receive fails an exception is thrown.

Parameters:
buf the buffer into which the data is placed
len the amount of data to receive. Buf must point to a region of memory at least len bytes in size.
timeout the number of milliseconds to wait for the receive to complete. If the receive does not complete within the specified time an MCTimedOut exception is thrown.
Returns:
a MCRecvFromResult which encapsulates both the amount of data received and the address that it was received from.

mcint32 sendTo const MCNetAddr addr,
const void *  buf,
mcint32  len,
mcinterval_t  timeout = MCIntervalInfinite
 

Send data to a peer.

If the send fails an exception is thrown.

Parameters:
addr the address of the peer to send data to. For connection-oriented sockets, the address is ignored because an address was already bound at construction time.
buf the buffer containing the data to send
len the amount of data to send. Buf must point to a region of memory at least len bytes in size.
timeout the number of milliseconds to wait for the send to complete. If the send does not complete within the specified time an MCTimedOut exception is thrown.
Returns:
the number of bytes actually sent.

void setNonBlock bool  nonBlock  ) 
 

Set the blocking state of the socket.

Parameters:
nonBlock if true the socket is non-blocking

void setRecvBufferSize mcuint32  sz  ) 
 

Set the receive buffer size.

Parameters:
sz the new size for the receive buffer

void setReuseAddr bool  reuse  ) 
 

Set the socket to allow or disallow resuse of an address during bind.

Parameters:
reuse if true the bind address will be re-used even if it is already in use

void setSendBufferSize mcuint32  sz  ) 
 

Set the send buffer size.

Parameters:
sz the new size for the send buffer

void setTos mcuint32  tos  ) 
 

Set the type of service.

Parameters:
tos the new type of service

void setTtl mcuint32  ttl  ) 
 

Set the time to live.

Parameters:
ttl the new time-to-live


Generated on Wed Jan 12 19:05:50 2005 for MCLLIB by  doxygen 1.3.9.1