libsocket
Public Member Functions | Protected Attributes | List of all members
libsocket::inet_stream_server Class Reference

TCP server socket (passive TCP socket) More...

#include <inetserverstream.hpp>

Inheritance diagram for libsocket::inet_stream_server:
Inheritance graph
[legend]

Public Member Functions

 inet_stream_server (void)
 Void constructor; don't forget to setup() the socket before use! More...
 
 inet_stream_server (const char *bindhost, const char *bindport, int proto_osi3, int flags=0)
 Set up a server socket. More...
 
 inet_stream_server (const string &bindhost, const string &bindport, int proto_osi3, int flags=0)
 Set up a server socket. More...
 
void setup (const char *bindhost, const char *bindport, int proto_osi3, int flags=0)
 Set up a server socket. More...
 
void setup (const string &bindhost, const string &bindport, int proto_osi3, int flags=0)
 Set up a server socket. More...
 
inet_streamaccept (int numeric=0, int accept_flags=0)
 Accept a connection and return a socket connected to the client. More...
 
unique_ptr< inet_streamaccept2 (int numeric=0, int accept_flags=0)
 Accept a connection and return a socket connected to the client. More...
 
const string & getbindhost (void)
 
const string & getbindport (void)
 
const string & gethost (void) const
 
const string & getport (void) const
 
virtual int destroy (void)
 Destroys a socket. More...
 
int getfd (void) const
 Returns the socket file descriptor. More...
 
int set_sock_opt (int level, int optname, const char *optval, socklen_t optlen) const
 Set socket options on the underlying socket. More...
 
void set_close_on_destructor (bool cod)
 

Protected Attributes

string host
 The address we're bound or connected to. More...
 
string port
 The port we're bound or connected to. More...
 
int proto
 Which internet protocol version we're using. More...
 
int sfd
 sfd is the sockets API file descriptor More...
 
bool is_nonblocking
 
bool close_on_destructor
 

Detailed Description

TCP server socket (passive TCP socket)

This class acts as TCP server. Once set up you may call accept() on it. When a client wants to connect, a pointer to an inet_stream class is returned. It may be used to communicate with the client.

See also
inet_stream

Definition at line 56 of file inetserverstream.hpp.

Constructor & Destructor Documentation

◆ inet_stream_server() [1/3]

libsocket::inet_stream_server::inet_stream_server ( void  )

Void constructor; don't forget to setup() the socket before use!

Definition at line 60 of file inetserverstream.cpp.

◆ inet_stream_server() [2/3]

libsocket::inet_stream_server::inet_stream_server ( const char *  bindhost,
const char *  bindport,
int  proto_osi3,
int  flags = 0 
)

Set up a server socket.

This constructor initializes a server socket for TCP/IP communication.

Parameters
bindhostThe address the server should listen on
bindportThe port the server should listen on
proto_osi3The protocol: LIBSOCKET_IPv4/LIBSOCKET_IPv6
flagsFlags for socket(2)

Definition at line 72 of file inetserverstream.cpp.

Here is the call graph for this function:

◆ inet_stream_server() [3/3]

libsocket::inet_stream_server::inet_stream_server ( const string &  bindhost,
const string &  bindport,
int  proto_osi3,
int  flags = 0 
)

Set up a server socket.

This constructor initializes a server socket for TCP/IP communication.

Parameters
bindhostThe address the server should listen on
bindportThe port the server should listen on
proto_osi3The protocol: LIBSOCKET_IPv4/LIBSOCKET_IPv6
flagsFlags for socket(2)

Definition at line 88 of file inetserverstream.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ setup() [1/2]

void libsocket::inet_stream_server::setup ( const char *  bindhost,
const char *  bindport,
int  proto_osi3,
int  flags = 0 
)

Set up a server socket.

If the zero-argument constructor was used, this method initializes a server socket for TCP/IP communication.

Parameters
bindhostThe address the server should listen on
bindportThe port the server should listen on
proto_osi3The protocol: LIBSOCKET_IPv4/LIBSOCKET_IPv6
flagsFlags for socket(2)

Definition at line 105 of file inetserverstream.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup() [2/2]

void libsocket::inet_stream_server::setup ( const string &  bindhost,
const string &  bindport,
int  proto_osi3,
int  flags = 0 
)

Set up a server socket.

If the zero-argument constructor was used, this method initializes a server socket for TCP/IP communication.

Parameters
bindhostThe address the server should listen on
bindportThe port the server should listen on
proto_osi3The protocol: LIBSOCKET_IPv4/LIBSOCKET_IPv6
flagsFlags for socket(2)

Definition at line 140 of file inetserverstream.cpp.

Here is the call graph for this function:

◆ accept()

inet_stream * libsocket::inet_stream_server::accept ( int  numeric = 0,
int  accept_flags = 0 
)

Accept a connection and return a socket connected to the client.

Waits for a client to connect and returns a pointer to a inet_stream object which can be used to communicate with the client.

Parameters
numericSpecifies if the client's parameter (IP address, port) should be delivered numerically in the src_host/src_port parameters.
accept_flagsFlags specified in accept(2)
Returns
A pointer to a connected TCP/IP client socket object.

Definition at line 177 of file inetserverstream.cpp.

Here is the call graph for this function:

◆ accept2()

unique_ptr< inet_stream > libsocket::inet_stream_server::accept2 ( int  numeric = 0,
int  accept_flags = 0 
)

Accept a connection and return a socket connected to the client.

The caller owns the client socket.

Parameters
numericSpecifies if the client's parameter (IP address, port) should be delivered numerically in the src_host/src_port parameters.
accept_flagsFlags specified in accept(2)
Returns
An owned pointer to a connected TCP/IP client socket object.

Definition at line 192 of file inetserverstream.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gethost()

const string & libsocket::inet_socket::gethost ( void  ) const
inherited

For sockets behaving as client: Returns the remote host. For sockets behaving as server: Returns the address bound to.

Definition at line 59 of file inetbase.cpp.

◆ getport()

const string & libsocket::inet_socket::getport ( void  ) const
inherited

For sockets behaving as client: Returns the remote port. For sockets behaving as server: Returns the port bound to.

Definition at line 65 of file inetbase.cpp.

◆ destroy()

int libsocket::socket::destroy ( void  )
virtualinherited

Destroys a socket.

Return values
0Fine!
<0Most likely the socket was already closed before.

Definition at line 72 of file socket.cpp.

Here is the caller graph for this function:

◆ getfd()

int libsocket::socket::getfd ( void  ) const
inherited

Returns the socket file descriptor.

Returns
The socket file descriptor of the class.

getfd() is a getter you may use to obtain the file descriptor for raw operations on it. It's relatively uncritical as libsocket just wraps other syscalls and doesn't manipulate it using unusual ways.

Definition at line 91 of file socket.cpp.

◆ set_sock_opt()

int libsocket::socket::set_sock_opt ( int  level,
int  optname,
const char *  optval,
socklen_t  optlen 
) const
inherited

Set socket options on the underlying socket.

Returns
The return value of setsockopt(2).

Sets socket options using setsockopt(2). See setsockopt(2), tcp(7), udp(7), unix(7) for documentation on how to use this function.

Definition at line 101 of file socket.cpp.

◆ set_close_on_destructor()

void libsocket::socket::set_close_on_destructor ( bool  cod)
inlineinherited

close_on_destructor is true by default. If set to false, do not call close(2) on the underlying socket in the destructor.

Definition at line 95 of file socket.hpp.

Member Data Documentation

◆ host

string libsocket::inet_socket::host
protectedinherited

The address we're bound or connected to.

Definition at line 55 of file inetbase.hpp.

◆ port

string libsocket::inet_socket::port
protectedinherited

The port we're bound or connected to.

Definition at line 57 of file inetbase.hpp.

◆ proto

int libsocket::inet_socket::proto
protectedinherited

Which internet protocol version we're using.

Definition at line 59 of file inetbase.hpp.

◆ sfd

int libsocket::socket::sfd
protectedinherited

sfd is the sockets API file descriptor

Definition at line 74 of file socket.hpp.

◆ close_on_destructor

bool libsocket::socket::close_on_destructor
protectedinherited

Default is true; if set to false, the file descriptor is not closed when the destructor is called.

Definition at line 78 of file socket.hpp.


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