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> 77 Socket(
int domain,
int type,
int protocol,
float timeout = 0.f);
81 virtual void connect(
const char *hostname,
const unsigned short int port);
82 virtual void connect(
struct sockaddr *addr_port,
unsigned int struct_size);
84 virtual void bind(
const unsigned short int port);
85 virtual void bind(
const unsigned short int port,
86 const char *hostname);
88 virtual void listen(
int backlog = 1);
91 virtual bool available();
93 virtual size_t read(
void *buf,
size_t count,
bool read_all =
true);
94 virtual void write(
const void *buf,
size_t count);
95 virtual void send(
void *buf,
size_t buf_len);
96 virtual void send(
void *buf,
size_t buf_len,
97 const struct sockaddr *to_addr, socklen_t addr_len);
98 virtual size_t recv(
void *buf,
size_t buf_len);
99 virtual size_t recv(
void *buf,
size_t buf_len,
100 struct sockaddr *from_addr, socklen_t *addr_len);
106 virtual Socket * clone() = 0;
108 virtual short poll(
int timeout = -1,
short what = POLL_IN | POLL_HUP | POLL_PRI | POLL_RDHUP);
110 virtual bool listening();
112 virtual unsigned int mtu();
119 template <
class SocketType>
120 SocketType * accept();
133 template <
class SocketType>
138 if (SocketType *ts = dynamic_cast<SocketType *>(s)) {
static const short POLL_ERR
Error condition.
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.
SocketException(const char *msg, int _errno)
Constructor.
static const short POLL_IN
Data can be read.
struct::sockaddr_in * client_addr
Client address, set if connected.
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.
virtual const char * what() const
Get primary string.
Base class for exceptions in Fawkes.
static const short POLL_RDHUP
Stream socket peer closed connection, or shut down writing half of connection.
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.
static const short POLL_OUT
Writing will not block.