Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

Socket Class Reference

Virtual class for socket operations. More...

#include <Socket.h>

Inheritance diagram for Socket:

TCPSocket UDPSocket List of all members.

Public Member Functions

 Socket ()
virtual ~Socket ()
virtual void Open (int fd=0)=0
void Bind (int addr, short port)
 Bind the socket to the specified address and port.
void Connect (int addr, short port)
 TCP: connect to the specified address and port, UDP: accept messages only from the specified source.
virtual void Send (const DCDT_Msg *msg)=0
virtual DCDT_MsgReceive ()=0
void Close ()
void ForcedClose ()
void GetOption (int level, int optname)
void SetOption (int level, int optname)
void UnSetOption (int level, int optname)
void GetName (char *addr, short &port)
void GetCommData (int &addr, short &port)
void SetLostTimer (int usec)
void LostTimerOn ()
void LostTimerOff ()
void SetConnTimer (int usec)
void ConnTimerOn ()
void ConnTimerOff ()
void SetSendTimer (int usec)
void SendTimerOn ()
void SendTimerOff ()
void UnblockSend ()
void SetReceiveTimer (int usec)
void ReceiveTimerOn ()
void ReceiveTimerOff ()
void UnblockReceive ()
int GetFd ()

Protected Attributes

int sockfd
int opened
 = 1 -> socket opened
int bound
 = 1 -> socket bound
int connected
 = 1 -> socket connected
int tconn_flag
 = 1 -> use a timer in accept()
int tlost_flag
 = 1 -> use a timer in communications
int tsend_flag
 = 1 -> use a timer when sending messages
int trecv_flag
 = 1 -> use a timer when receiving messages
int unblock_send_flag
 = 1 -> socket non blocking when sending
int unblock_recv_flag
 = 1 -> socket non blocking when receiving
timeval tconn_value tlost_value
tsend_value 
trecv_value
int my_addr
short my_port

Detailed Description

Virtual class for socket operations.

A socket is always created in blocking mode.
Ports are stored as short like in the socket API, not as int such as in CommData, out of the library the numeric values are always expressed in network format.
Ex: 192.168.26.250:1500 -> 0xf01aa8c0:0xdc05

Definition at line 44 of file Socket.h.


Constructor & Destructor Documentation

Socket::Socket  )  [inline]
 

Definition at line 47 of file Socket.h.

virtual Socket::~Socket  )  [inline, virtual]
 

Definition at line 54 of file Socket.h.


Member Function Documentation

void Socket::Bind int  addr,
short  port
[inline]
 

Bind the socket to the specified address and port.

If port=0 the port to bind to is randomly choose by the kernel, the same for address. Can throw a ChannelError exception if the bind can't be done; on success set bound to 1.

Exceptions:
ChannelError 

Definition at line 116 of file Socket.h.

References bound, DCDT_TRC_COMM, my_addr, my_port, opened, sockfd, and TRC_PRINT.

Referenced by DCDT_Channel_IP::DynamicPrepare(), DCDT_Channel_IP::Open(), DCDT_Channel_IP::Reopen(), and DCDT_Channel_IP::StaticPrepare().

void Socket::Close  )  [inline]
 

Exceptions:
ConnError 

Definition at line 163 of file Socket.h.

References bound, connected, DCDT_TRC_COMM, opened, sockfd, and TRC_PRINT.

Referenced by DCDT_Channel_IP::Close().

void Socket::Connect int  addr,
short  port
[inline]
 

TCP: connect to the specified address and port, UDP: accept messages only from the specified source.

If the socket is a tcp one connect to the specified address and port, if it's an udp one receive messages only from the specified address and port. Can throw ConnError exception in case of problems. When the connection is successfully established set connected to 1.

Exceptions:
ConnError 

Definition at line 144 of file Socket.h.

References connected, DCDT_TRC_COMM, opened, sockfd, and TRC_PRINT.

Referenced by DCDT_Channel_IP::StartConn(), and DCDT_Channel_IP::WaitConn().

void Socket::ConnTimerOff  )  [inline]
 

Definition at line 284 of file Socket.h.

References tconn_flag.

Referenced by DCDT_Channel_IP::ConnTimerOff().

void Socket::ConnTimerOn  )  [inline]
 

Definition at line 279 of file Socket.h.

References tconn_flag.

Referenced by TCPSocket::Accept(), DCDT_Channel_IP::ConnTimerOn(), DCDT_Channel_IP::DynamicPrepare(), DCDT_Channel_IP::SetTimers(), and DCDT_Channel_IP::StaticPrepare().

void Socket::ForcedClose  )  [inline]
 

Definition at line 174 of file Socket.h.

References bound, connected, DCDT_TRC_COMM, opened, sockfd, and TRC_PRINT.

Referenced by DCDT_Channel_IP::Stop().

void Socket::GetCommData int &  addr,
short &  port
[inline]
 

Exceptions:
ChannelError 

Definition at line 242 of file Socket.h.

References sockfd.

Referenced by DCDT_Channel_IP::Open(), and DCDT_Channel_IP::Reopen().

int Socket::GetFd  )  [inline]
 

Definition at line 82 of file Socket.h.

Referenced by DCDT_Channel_IP::StartConn(), and DCDT_Channel_IP::WaitConn().

void Socket::GetName char *  addr,
short &  port
[inline]
 

Exceptions:
ChannelError 

Definition at line 226 of file Socket.h.

References sockfd.

void Socket::GetOption int  level,
int  optname
[inline]
 

Exceptions:
ChannelError 

Definition at line 186 of file Socket.h.

References DCDT_TRC_COMM, sockfd, and TRC_PRINT.

Referenced by TCPSocket::SetBufs(), and TCPSocket::SetSegSize().

void Socket::LostTimerOff  )  [inline]
 

Definition at line 268 of file Socket.h.

References tlost_flag.

Referenced by DCDT_Channel_IP::LostTimerOff().

void Socket::LostTimerOn  )  [inline]
 

Definition at line 263 of file Socket.h.

References tlost_flag.

Referenced by TCPSocket::Accept(), DCDT_Channel_IP::DynamicPrepare(), DCDT_Channel_IP::LostTimerOn(), DCDT_Channel_IP::SetTimers(), and DCDT_Channel_IP::StaticPrepare().

virtual void Socket::Open int  fd = 0  )  [pure virtual]
 

Implemented in TCPSocket, and UDPSocket.

virtual DCDT_Msg* Socket::Receive  )  [pure virtual]
 

Implemented in TCPSocket, and UDPSocket.

void Socket::ReceiveTimerOff  )  [inline]
 

Definition at line 323 of file Socket.h.

References trecv_flag.

Referenced by DCDT_Channel_IP::ReceiveTimerOff().

void Socket::ReceiveTimerOn  )  [inline]
 

Definition at line 317 of file Socket.h.

References trecv_flag, and unblock_recv_flag.

Referenced by TCPSocket::Accept(), DCDT_Channel_IP::DynamicPrepare(), DCDT_Channel_IP::ReceiveTimerOn(), DCDT_Channel_IP::SetTimers(), and DCDT_Channel_IP::StaticPrepare().

virtual void Socket::Send const DCDT_Msg msg  )  [pure virtual]
 

Implemented in TCPSocket, and UDPSocket.

void Socket::SendTimerOff  )  [inline]
 

Definition at line 301 of file Socket.h.

References tsend_flag.

Referenced by DCDT_Channel_IP::SendTimerOff().

void Socket::SendTimerOn  )  [inline]
 

Definition at line 295 of file Socket.h.

References tsend_flag, and unblock_send_flag.

Referenced by TCPSocket::Accept(), DCDT_Channel_IP::SendTimerOn(), and DCDT_Channel_IP::SetTimers().

void Socket::SetConnTimer int  usec  )  [inline]
 

Definition at line 273 of file Socket.h.

Referenced by TCPSocket::Accept(), DCDT_Channel_IP::DynamicPrepare(), DCDT_Channel_IP::SetConnTimer(), DCDT_Channel_IP::SetTimers(), and DCDT_Channel_IP::StaticPrepare().

void Socket::SetLostTimer int  usec  )  [inline]
 

Definition at line 257 of file Socket.h.

Referenced by TCPSocket::Accept(), DCDT_Channel_IP::DynamicPrepare(), DCDT_Channel_IP::SetLostTimer(), DCDT_Channel_IP::SetTimers(), and DCDT_Channel_IP::StaticPrepare().

void Socket::SetOption int  level,
int  optname
[inline]
 

Exceptions:
ChannelError 

Definition at line 200 of file Socket.h.

References DCDT_TRC_COMM, sockfd, and TRC_PRINT.

void Socket::SetReceiveTimer int  usec  )  [inline]
 

Definition at line 311 of file Socket.h.

References trecv_value.

Referenced by TCPSocket::Accept(), DCDT_Channel_IP::DynamicPrepare(), DCDT_Channel_IP::SetReceiveTimer(), DCDT_Channel_IP::SetTimers(), DCDT_Channel_IP::StaticPrepare(), and DCDT_Channel_IP::WaitConn().

void Socket::SetSendTimer int  usec  )  [inline]
 

Definition at line 289 of file Socket.h.

Referenced by TCPSocket::Accept(), DCDT_Channel_IP::SetSendTimer(), and DCDT_Channel_IP::SetTimers().

void Socket::UnblockReceive  )  [inline]
 

Definition at line 328 of file Socket.h.

References unblock_recv_flag.

Referenced by DCDT_Channel_IP::UnblockReceive().

void Socket::UnblockSend  )  [inline]
 

Definition at line 306 of file Socket.h.

References unblock_send_flag.

Referenced by DCDT_Channel_IP::UnblockSend().

void Socket::UnSetOption int  level,
int  optname
[inline]
 

Exceptions:
ChannelError 

Definition at line 213 of file Socket.h.

References DCDT_TRC_COMM, sockfd, and TRC_PRINT.


Member Data Documentation

int Socket::bound [protected]
 

= 1 -> socket bound

Definition at line 85 of file Socket.h.

Referenced by Bind(), Close(), and ForcedClose().

int Socket::connected [protected]
 

= 1 -> socket connected

Definition at line 85 of file Socket.h.

Referenced by Close(), Connect(), and ForcedClose().

int Socket::my_addr [protected]
 

Definition at line 106 of file Socket.h.

Referenced by Bind().

short Socket::my_port [protected]
 

Definition at line 107 of file Socket.h.

Referenced by Bind().

int Socket::opened [protected]
 

= 1 -> socket opened

Definition at line 85 of file Socket.h.

Referenced by Bind(), Close(), Connect(), and ForcedClose().

int Socket::sockfd [protected]
 

Definition at line 85 of file Socket.h.

Referenced by Bind(), Close(), Connect(), ForcedClose(), GetCommData(), GetName(), GetOption(), SetOption(), and UnSetOption().

int Socket::tconn_flag [protected]
 

= 1 -> use a timer in accept()

Definition at line 85 of file Socket.h.

Referenced by ConnTimerOff(), and ConnTimerOn().

int Socket::tlost_flag [protected]
 

= 1 -> use a timer in communications

Definition at line 85 of file Socket.h.

Referenced by LostTimerOff(), and LostTimerOn().

int Socket::trecv_flag [protected]
 

= 1 -> use a timer when receiving messages

Definition at line 85 of file Socket.h.

Referenced by ReceiveTimerOff(), and ReceiveTimerOn().

struct timeval tconn_value tlost_value tsend_value Socket::trecv_value [protected]
 

Definition at line 105 of file Socket.h.

Referenced by SetReceiveTimer().

int Socket::tsend_flag [protected]
 

= 1 -> use a timer when sending messages

Definition at line 85 of file Socket.h.

Referenced by SendTimerOff(), and SendTimerOn().

int Socket::unblock_recv_flag [protected]
 

= 1 -> socket non blocking when receiving

Definition at line 102 of file Socket.h.

Referenced by ReceiveTimerOn(), and UnblockReceive().

int Socket::unblock_send_flag [protected]
 

= 1 -> socket non blocking when sending

Definition at line 102 of file Socket.h.

Referenced by SendTimerOn(), and UnblockSend().


The documentation for this class was generated from the following file:
Generated on Sun Jun 19 10:35:51 2005 for dcdt by  doxygen 1.3.9.1