#include <UDPSocket.h>
Inheritance diagram for ASSA::UDPSocket:
Public Member Functions | |
UDPSocket () | |
Default constructor. | |
UDPSocket (const handler_t fd_) | |
Constructor. | |
virtual | ~UDPSocket () |
Destructor will close connection. | |
bool | open (const int domain_) |
Create socket. | |
bool | close () |
Close socket connection. | |
bool | bind (const Address &my_address_) |
Server in UDP client-server scenario has to bind socket to its local well-known port. | |
handler_t | getHandler () const |
Get socket file descriptor. | |
const int | getDomain () const |
Get socket domain type. | |
Protected Member Functions | |
void | setHandler (const int fd_) |
Set file descriptor. | |
void | setDomain (const int type_) |
Set socket domain type. |
Definition at line 28 of file UDPSocket.h.
ASSA::UDPSocket::UDPSocket | ( | ) | [inline] |
Default constructor.
Definition at line 31 of file UDPSocket.h.
References trace.
00032 { 00033 trace("UDPSocket::UDPSocket()"); 00034 }
ASSA::UDPSocket::UDPSocket | ( | const handler_t | fd_ | ) | [inline] |
Constructor.
fd_ | file descriptor to use |
Definition at line 39 of file UDPSocket.h.
References ASSA::Socket::m_fd, and trace.
virtual ASSA::UDPSocket::~UDPSocket | ( | ) | [inline, virtual] |
Destructor will close connection.
Definition at line 46 of file UDPSocket.h.
References trace.
00047 { 00048 trace("UDPSocket::~UDPSocket"); 00049 }
bool UDPSocket::bind | ( | const Address & | my_address_ | ) | [virtual] |
Server in UDP client-server scenario has to bind socket to its local well-known port.
This is the same bind call as in IPv4 - maybe it should be generalized in parent class.
my_address_ | address to bind to |
Implements ASSA::Socket.
Definition at line 52 of file UDPSocket.cpp.
References ASSA::Socket::failbit, ASSA::Address::getAddress(), ASSA::Address::getLength(), ASSA::Socket::m_fd, ASSA::Socket::setstate(), and trace.
00053 { 00054 trace("UDPSocket::bind"); 00055 00056 int ret = ::bind (m_fd, (SA*) my_address_.getAddress(), 00057 my_address_.getLength()); 00058 if (ret < 0) { 00059 setstate (Socket::failbit); 00060 return false; 00061 } 00062 return true; 00063 }
bool UDPSocket::close | ( | ) | [virtual] |
Close socket connection.
Implements ASSA::Socket.
Definition at line 39 of file UDPSocket.cpp.
References ASSA::Socket::failbit, ASSA::Socket::m_fd, ASSA::Socket::setstate(), and trace.
00040 { 00041 trace("UDPSocket::close()"); 00042 if ( m_fd >= 0 ) { 00043 ::close(m_fd); 00044 setstate (Socket::failbit); 00045 m_fd = -1; 00046 } 00047 return true; 00048 }
const int ASSA::UDPSocket::getDomain | ( | ) | const [inline, virtual] |
Get socket domain type.
Implements ASSA::Socket.
Definition at line 77 of file UDPSocket.h.
References ASSA::Socket::m_type.
Referenced by ASSA::ConUDPSocket::unconnect().
00077 { return m_type; }
handler_t ASSA::UDPSocket::getHandler | ( | ) | const [inline, virtual] |
Get socket file descriptor.
Implements ASSA::Socket.
Definition at line 74 of file UDPSocket.h.
References ASSA::Socket::m_fd.
Referenced by ASSA::ConUDPSocket::connect(), ASSA::ConUDPSocket::read(), ASSA::UnConUDPSocket::recvfrom(), ASSA::UnConUDPSocket::sendto(), and ASSA::ConUDPSocket::write().
00074 { return m_fd; }
bool UDPSocket::open | ( | const int | domain_ | ) | [virtual] |
Create socket.
Socket domain type is specified as AF_INET for internet socket and AF_UNIX for UNIX domain socket (full duplex pipe).
domain_ | domain |
Implements ASSA::Socket.
Definition at line 22 of file UDPSocket.cpp.
References ASSA::Socket::clear(), ASSA::Socket::failbit, ASSA::Socket::m_fd, ASSA::Socket::m_type, ASSA::Socket::setstate(), and trace.
00023 { 00024 trace("UDPSocket::open"); 00025 00026 m_type = domain_; 00027 m_fd = ::socket (m_type, SOCK_DGRAM, 0); 00028 00029 if (m_fd < 0) { 00030 setstate (Socket::failbit); 00031 return false; 00032 } 00033 clear (); 00034 return true; 00035 }
void ASSA::UDPSocket::setDomain | ( | const int | type_ | ) | [inline, protected] |
Set socket domain type.
Definition at line 84 of file UDPSocket.h.
References ASSA::Socket::m_type.
00084 { m_type = type_; }
void ASSA::UDPSocket::setHandler | ( | const int | fd_ | ) | [inline, protected] |
Set file descriptor.
Definition at line 81 of file UDPSocket.h.
References ASSA::Socket::m_fd.
00081 { m_fd = fd_; }