Fawkes API  Fawkes Development Version
fawkes::StreamSocket Class Reference

TCP stream socket over IP. More...

#include <netcomm/socket/stream.h>

Inheritance diagram for fawkes::StreamSocket:

Public Member Functions

 StreamSocket (float timeout=0.f)
 Constructor. More...
 
 StreamSocket (AddrType addr_type, float timeout=0.f)
 Constructor. More...
 
 StreamSocket (StreamSocket &s)
 Copy constructor. More...
 
virtual Socketclone ()
 Clone socket. More...
 
void set_nodelay (bool no_delay)
 Enable or disable Nagle algorithm. More...
 
bool nodelay ()
 Check if Nalge algorithm is disabled. More...
 
- Public Member Functions inherited from fawkes::Socket
 Socket (AddrType addr_type, SocketType sock_type, float timeout=0.f)
 Constructor similar to syscall. More...
 
 Socket (Socket &socket)
 Copy constructor. More...
 
virtual ~Socket ()
 Destructor. More...
 
virtual void connect (const char *hostname, const unsigned short int port)
 Connect socket. More...
 
virtual void connect (const struct ::sockaddr_storage &addr_port)
 Connect socket. More...
 
virtual void connect (const struct sockaddr *addr_port, socklen_t struct_size)
 Connect socket. More...
 
virtual void bind (const unsigned short int port)
 Bind socket. More...
 
virtual void bind (const unsigned short int port, const char *ipaddr)
 Bind socket to a specific address. More...
 
virtual void listen (int backlog=1)
 Listen on socket. More...
 
virtual Socketaccept ()
 Accept connection. More...
 
virtual void close ()
 Close socket. More...
 
virtual bool available ()
 Check if data is available. More...
 
virtual size_t read (void *buf, size_t count, bool read_all=true)
 Read from socket. More...
 
virtual void write (const void *buf, size_t count)
 Write to the socket. More...
 
virtual void send (void *buf, size_t buf_len)
 Write to the socket. More...
 
virtual void send (void *buf, size_t buf_len, const struct sockaddr *to_addr, socklen_t addr_len)
 Send message. More...
 
virtual size_t recv (void *buf, size_t buf_len)
 Read from socket. More...
 
virtual size_t recv (void *buf, size_t buf_len, struct sockaddr *from_addr, socklen_t *addr_len)
 Receive data. More...
 
virtual short poll (int timeout=-1, short what=POLL_IN|POLL_HUP|POLL_PRI|POLL_RDHUP)
 Wait for some event on socket. More...
 
virtual bool listening ()
 Is socket listening for connections? More...
 
virtual unsigned int mtu ()
 Maximum Transfer Unit (MTU) of socket. More...
 
template<class SocketTypeC >
SocketTypeC * accept ()
 Accept connection. More...
 

Additional Inherited Members

- Public Types inherited from fawkes::Socket
enum  AddrType { UNSPECIFIED, IPv4, IPv6 }
 Address type specification. More...
 
enum  SocketType { TCP, UDP }
 Socket type. More...
 
- Static Public Attributes inherited from fawkes::Socket
static const short POLL_IN = POLLIN
 Data can be read. More...
 
static const short POLL_OUT = POLLOUT
 Writing will not block. More...
 
static const short POLL_PRI = POLLPRI
 There is urgent data to read (e.g., out-of-band data on TCP socket; pseudo-terminal master in packet mode has seen state change in slave). More...
 
static const short POLL_RDHUP = 0
 Stream socket peer closed connection, or shut down writing half of connection. More...
 
static const short POLL_ERR = POLLERR
 Error condition. More...
 
static const short POLL_HUP = POLLHUP
 Hang up. More...
 
static const short POLL_NVAL = POLLNVAL
 Invalid request. More...
 
- Protected Member Functions inherited from fawkes::Socket
 Socket (SocketType sock_type, float timeout=0.f)
 IPv4 Constructor. More...
 
 Socket ()
 Constructor. More...
 
- Protected Attributes inherited from fawkes::Socket
AddrType addr_type
 Address type/family of socket. More...
 
int sock_fd
 Socket file descriptor. More...
 
float timeout
 Timeout in seconds for various operations. More...
 
struct ::sockaddr_storage * client_addr
 Client address, set if connected. More...
 
unsigned int client_addr_len
 length in bytes of client address. More...
 

Detailed Description

TCP stream socket over IP.

Author
Tim Niemueller

Definition at line 31 of file stream.h.

Constructor & Destructor Documentation

◆ StreamSocket() [1/3]

fawkes::StreamSocket::StreamSocket ( float  timeout = 0.f)

Constructor.

This assumes that the socket will later be created using connect().

Parameters
timeouttimeout, if 0 all operationsare blocking, otherwise it is tried for timeout seconds.

Definition at line 47 of file stream.cpp.

Referenced by clone().

◆ StreamSocket() [2/3]

fawkes::StreamSocket::StreamSocket ( AddrType  addr_type,
float  timeout = 0.f 
)

Constructor.

Parameters
addr_typeSpecify IPv4 or IPv6
timeouttimeout, if 0 all operationsare blocking, otherwise it is tried for timeout seconds.

Definition at line 57 of file stream.cpp.

◆ StreamSocket() [3/3]

fawkes::StreamSocket::StreamSocket ( StreamSocket stream_socket)

Copy constructor.

Parameters
stream_socketsocket to copy.

Definition at line 66 of file stream.cpp.

Member Function Documentation

◆ clone()

Socket * fawkes::StreamSocket::clone ( )
virtual

Clone socket.

Returns
a copied instance of StreamSocket.

Implements fawkes::Socket.

Definition at line 76 of file stream.cpp.

References StreamSocket().

◆ nodelay()

bool fawkes::StreamSocket::nodelay ( )

Check if Nalge algorithm is disabled.

This checks the TCP_NODELAY option on the socket. If it is set then the Nagle algorithm is disabled and all data is send out immediately.

Returns
true, if nodelay is enabled and thus the Nagle algorithm disabled, false otherwise

Definition at line 89 of file stream.cpp.

References fawkes::Socket::sock_fd.

◆ set_nodelay()

void fawkes::StreamSocket::set_nodelay ( bool  nodelay)

Enable or disable Nagle algorithm.

Parameters
nodelaytrue to disable Nagle algorithm, false to enable it
See also
nodelay()

Definition at line 109 of file stream.cpp.

References fawkes::Socket::sock_fd.


The documentation for this class was generated from the following files: