cxxtools::net::Socket Class Reference

Wrapper for BSD sockets. More...

#include <cxxtools/net/net.h>

Inheritance diagram for cxxtools::net::Socket:
cxxtools::NonCopyable cxxtools::net::UdpReceiver cxxtools::net::UdpSender

Public Member Functions

 Socket (int domain, int type, int protocol)
 A socket is created. On error a net::Exception is thrown.
 Socket (int fd=-1)
 A socket is initialized with a existing socket descriptor.
virtual ~Socket ()
 The socket is released.
bool good () const
 Returns true, if a socket is held.
bool bad () const
 Returns true, if no socket is held.
 operator bool () const
 Returns true, if a socket is held.
void create (int domain, int type, int protocol)
 Creates a new socket.
void close ()
 Closes the socket, if a socket is held.
int getFd () const
 Returns the socket handle.
std::string getSockAddr () const
 wrapper around getsockname(2)
void setTimeout (int t)
 Set timeout in milliseconds.
int getTimeout () const
 Returns timeout in milliseconds.
short poll (short events) const
 execute poll(2) - throws Timeout-exception, when no data available after timeout

Protected Member Functions

void setFd (int sockFd)

Additional Inherited Members

- Private Member Functions inherited from cxxtools::NonCopyable
 NonCopyable ()

Detailed Description

Wrapper for BSD sockets.

Constructor & Destructor Documentation

cxxtools::net::Socket::Socket ( int  domain,
int  type,
int  protocol 
)

A socket is created. On error a net::Exception is thrown.

cxxtools::net::Socket::Socket ( int  fd = -1)
inlineexplicit

A socket is initialized with a existing socket descriptor.

Ownership is transfered to this class.

virtual cxxtools::net::Socket::~Socket ( )
virtual

The socket is released.

Errors are printed on stderr.

Member Function Documentation

bool cxxtools::net::Socket::bad ( ) const
inline

Returns true, if no socket is held.

void cxxtools::net::Socket::close ( )

Closes the socket, if a socket is held.

void cxxtools::net::Socket::create ( int  domain,
int  type,
int  protocol 
)

Creates a new socket.

If a socket is already associated with this class, it is closed.

int cxxtools::net::Socket::getFd ( ) const
inline

Returns the socket handle.

std::string cxxtools::net::Socket::getSockAddr ( ) const

wrapper around getsockname(2)

int cxxtools::net::Socket::getTimeout ( ) const
inline

Returns timeout in milliseconds.

bool cxxtools::net::Socket::good ( ) const
inline

Returns true, if a socket is held.

cxxtools::net::Socket::operator bool ( ) const
inline

Returns true, if a socket is held.

short cxxtools::net::Socket::poll ( short  events) const

execute poll(2) - throws Timeout-exception, when no data available after timeout

void cxxtools::net::Socket::setFd ( int  sockFd)
protected
void cxxtools::net::Socket::setTimeout ( int  t)

Set timeout in milliseconds.


The documentation for this class was generated from the following file:
  • include/cxxtools/net/net.h