libassa 3.5.0
Public Member Functions | Protected Member Functions
ASSA::UDPSocket Class Reference

#include <UDPSocket.h>

Inheritance diagram for ASSA::UDPSocket:
ASSA::Socket ASSA::ConUDPSocket ASSA::UnConUDPSocket

List of all members.

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.

Detailed Description

Definition at line 28 of file UDPSocket.h.


Constructor & Destructor Documentation

ASSA::UDPSocket::UDPSocket ( ) [inline]

Default constructor.

Definition at line 31 of file UDPSocket.h.

References trace.

    {   
        trace("UDPSocket::UDPSocket()");
    }
ASSA::UDPSocket::UDPSocket ( const handler_t  fd_) [inline]

Constructor.

Parameters:
fd_file descriptor to use

Definition at line 39 of file UDPSocket.h.

References ASSA::Socket::m_fd, and trace.

    {
        trace("UDPSocket::UDPSocket(fd)");
        m_fd = fd_;
    }
virtual ASSA::UDPSocket::~UDPSocket ( ) [inline, virtual]

Destructor will close connection.

Definition at line 46 of file UDPSocket.h.

References trace.

    {
        trace("UDPSocket::~UDPSocket");
    }

Member Function Documentation

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.

Parameters:
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.

{
    trace("UDPSocket::bind");

    int ret = ::bind (m_fd, (SA*) my_address_.getAddress(),
              my_address_.getLength());
    if (ret < 0) {
        setstate (Socket::failbit);
        return false;
    }
    return true;
}
bool UDPSocket::close ( void  ) [virtual]

Close socket connection.

Returns:
true if success, fail if call to ::close() failed.

Implements ASSA::Socket.

Definition at line 39 of file UDPSocket.cpp.

References ASSA::Socket::failbit, ASSA::Socket::m_fd, ASSA::Socket::setstate(), and trace.

{
    trace("UDPSocket::close()");
    if ( m_fd >= 0 ) {
		::close(m_fd);
        setstate (Socket::failbit);
        m_fd = -1;
    }
    return true;
}
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().

{ return m_type; }
handler_t ASSA::UDPSocket::getHandler ( ) const [inline, virtual]
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).

Parameters:
domain_domain
Returns:
true if socket is created successfully, false otherwise

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.

{
    trace("UDPSocket::open");

    m_type = domain_;
    m_fd = ::socket (m_type, SOCK_DGRAM, 0);

    if (m_fd < 0) {
        setstate (Socket::failbit);
        return false;
    }
    clear ();
    return true;
}
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.

{ 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.

{ m_fd = fd_; }

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines