24 #ifndef __NETCOMM_SOCKET_SOCKET_H_ 25 #define __NETCOMM_SOCKET_SOCKET_H_ 27 #include <core/exception.h> 28 #include <core/exceptions/software.h> 30 #include <sys/socket.h> 31 #include <sys/types.h> 32 #include <netinet/in.h> 34 #include <sys/signal.h> 90 Socket(AddrType addr_type, SocketType sock_type,
float timeout = 0.f);
94 virtual void connect(
const char *hostname,
const unsigned short int port);
95 virtual void connect(
const struct ::sockaddr_storage &addr_port);
96 virtual void connect(
const struct sockaddr *addr_port, socklen_t struct_size);
98 virtual void bind(
const unsigned short int port);
99 virtual void bind(
const unsigned short int port,
const char *ipaddr);
101 virtual void listen(
int backlog = 1);
102 virtual Socket * accept();
103 virtual void close();
104 virtual bool available();
106 virtual size_t read(
void *buf,
size_t count,
bool read_all =
true);
107 virtual void write(
const void *buf,
size_t count);
108 virtual void send(
void *buf,
size_t buf_len);
109 virtual void send(
void *buf,
size_t buf_len,
110 const struct sockaddr *to_addr, socklen_t addr_len);
111 virtual size_t recv(
void *buf,
size_t buf_len);
112 virtual size_t recv(
void *buf,
size_t buf_len,
113 struct sockaddr *from_addr, socklen_t *addr_len);
119 virtual Socket * clone() = 0;
121 virtual short poll(
int timeout = -1,
short what = POLL_IN | POLL_HUP | POLL_PRI | POLL_RDHUP);
123 virtual bool listening();
125 virtual unsigned int mtu();
132 template <
class SocketTypeC>
133 SocketTypeC * accept();
136 Socket(SocketType sock_type,
float timeout = 0.f);
147 int socket_addr_family_;
149 int socket_protocol_;
156 template <
class SocketTypeC>
161 if (SocketTypeC *ts = dynamic_cast<SocketTypeC *>(s)) {
static const short POLL_ERR
Error condition.
Yet unknown address type.
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 ...
Fawkes library namespace.
static const short POLL_IN
Data can be read.
struct ::sockaddr_storage * client_addr
Client address, set if connected.
AddrType
Address type specification.
virtual const char * what() const
Get primary string.
int _errno
Error number, should be used if the error was caused by a method that supplies errno.
unsigned int client_addr_len
length in bytes of client address.
virtual Socket * accept()
Accept connection.
Base class for exceptions in Fawkes.
static const short POLL_RDHUP
Stream socket peer closed connection, or shut down writing half of connection.
AddrType addr_type
Address type/family of socket.
int sock_fd
Socket file descriptor.
static const short POLL_HUP
Hang up.
static const short POLL_NVAL
Invalid request.
float timeout
Timeout in seconds for various operations.
SocketException(int _errno, const char *msg)
Constructor.
static const short POLL_OUT
Writing will not block.