Fawkes API
Fawkes Development Version
|
24 #ifndef _NETCOMM_SOCKET_SOCKET_H_
25 #define _NETCOMM_SOCKET_SOCKET_H_
27 #include <core/exception.h>
28 #include <core/exceptions/software.h>
29 #include <netinet/in.h>
30 #include <sys/socket.h>
31 #include <sys/types.h>
33 #include <sys/signal.h>
56 class SocketException :
public Exception
93 virtual void connect(
const char *hostname,
const unsigned short int port);
94 virtual void connect(
const struct ::sockaddr_storage &addr_port);
95 virtual void connect(
const struct sockaddr *addr_port, socklen_t struct_size);
97 virtual void bind(
const unsigned short int port);
98 virtual void bind(
const unsigned short int port,
const char *ipaddr);
100 virtual void listen(
int backlog = 1);
102 virtual void close();
105 virtual size_t read(
void *buf,
size_t count,
bool read_all =
true);
106 virtual void write(
const void *buf,
size_t count);
107 virtual void send(
void *buf,
size_t buf_len);
108 virtual void send(
void *buf,
size_t buf_len,
const struct sockaddr *to_addr, socklen_t addr_len);
109 virtual size_t recv(
void *buf,
size_t buf_len);
110 virtual size_t recv(
void *buf,
size_t buf_len,
struct sockaddr *from_addr, socklen_t *addr_len);
122 virtual unsigned int mtu();
129 template <
class SocketTypeC>
143 int socket_addr_family_;
145 int socket_protocol_;
150 template <
class SocketTypeC>
155 if (SocketTypeC *ts =
dynamic_cast<SocketTypeC *
>(s)) {
virtual void bind(const unsigned short int port)
Bind socket.
static const short POLL_HUP
Hang up.
virtual ~Socket()
Destructor.
unsigned int client_addr_len
@ UDP
UDP datagram socket.
@ UNSPECIFIED
Yet unknown address type.
static const short POLL_RDHUP
Stream socket peer closed connection, or shut down writing half of connection.
virtual void connect(const char *hostname, const unsigned short int port)
Connect socket.
static const short POLL_ERR
Error condition.
virtual void close()
Close socket.
virtual void write(const void *buf, size_t count)
Write to the socket.
SocketException(int _errno, const char *msg)
Constructor.
virtual short poll(int timeout=-1, short what=POLL_IN|POLL_HUP|POLL_PRI|POLL_RDHUP)
Wait for some event on socket.
virtual size_t recv(void *buf, size_t buf_len)
Read from socket.
Socket & operator=(Socket &socket)
Copy constructor.
virtual bool listening()
Is socket listening for connections?
static const short POLL_NVAL
Invalid request.
virtual unsigned int mtu()
Maximum Transfer Unit (MTU) of socket.
static const short POLL_PRI
There is urgent data to read (e.g., out-of-band data on TCP socket; pseudo-terminal master in packet ...
virtual void send(void *buf, size_t buf_len)
Write to the socket.
virtual void listen(int backlog=1)
Listen on socket.
static const short POLL_IN
Data can be read.
virtual bool available()
Check if data is available.
static const short POLL_OUT
Writing will not block.
virtual Socket * clone()=0
Clone socket.
virtual Socket * accept()
Accept connection.
virtual size_t read(void *buf, size_t count, bool read_all=true)
Read from socket.
struct ::sockaddr_storage * client_addr
AddrType
Address type specification.