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> 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 connect(const char *hostname, const unsigned short int port)
Connect socket.
static const short POLL_ERR
Error condition.
virtual void close()
Close socket.
Yet unknown address type.
virtual void write(const void *buf, size_t count)
Write to the 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 ...
Fawkes library namespace.
virtual size_t recv(void *buf, size_t buf_len)
Read from socket.
static const short POLL_IN
Data can be read.
struct ::sockaddr_storage * client_addr
Client address, set if connected.
AddrType
Address type specification.
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 bool available()
Check if data is available.
virtual Socket * accept()
Accept connection.
virtual Socket * clone()=0
Clone socket.
Base class for exceptions in Fawkes.
virtual size_t read(void *buf, size_t count, bool read_all=true)
Read from socket.
virtual void bind(const unsigned short int port)
Bind socket.
Socket & operator=(Socket &socket)
Copy constructor.
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.
virtual ~Socket()
Destructor.
virtual bool listening()
Is socket listening for connections?
virtual unsigned int mtu()
Maximum Transfer Unit (MTU) of socket.
virtual short poll(int timeout=-1, short what=POLL_IN|POLL_HUP|POLL_PRI|POLL_RDHUP)
Wait for some event on socket.
int sock_fd
Socket file descriptor.
virtual void send(void *buf, size_t buf_len)
Write to the socket.
static const short POLL_HUP
Hang up.
static const short POLL_NVAL
Invalid request.
virtual void listen(int backlog=1)
Listen on socket.
float timeout
Timeout in seconds for various operations.
SocketException(int _errno, const char *msg)
Constructor.
static const short POLL_OUT
Writing will not block.