FiberIO
Fiber-based C++ network library
Public Member Functions | List of all members
fiberio::server_socket Class Reference

Server socket for listening for incoming connections. More...

#include <server_socket.hpp>

Public Member Functions

 server_socket ()
 Creates an unbound listening socket. More...
 
 server_socket (server_socket &&other)
 Creates a listening socket based on another, which is invalid after. More...
 
 ~server_socket ()
 Destructor. Closes the server_socket if it's open. More...
 
void bind (const std::string &host, uint16_t port)
 Binds the server_socket to an address and port. More...
 
std::string get_host ()
 Return the host that the server_socket is bound to. More...
 
uint16_t get_port ()
 Return the port that the server_socket is bound to. More...
 
void listen (int backlog)
 Start listening for connections with a certain backlog size. More...
 
socket accept ()
 Accept an incoming connection and get a socket representing it. More...
 
void close ()
 Close the listening socket and stop listening for connections. More...
 

Detailed Description

Server socket for listening for incoming connections.

Definition at line 14 of file server_socket.hpp.

Constructor & Destructor Documentation

◆ server_socket() [1/2]

fiberio::server_socket::server_socket ( )

Creates an unbound listening socket.

◆ server_socket() [2/2]

fiberio::server_socket::server_socket ( server_socket &&  other)

Creates a listening socket based on another, which is invalid after.

◆ ~server_socket()

fiberio::server_socket::~server_socket ( )

Destructor. Closes the server_socket if it's open.

Member Function Documentation

◆ accept()

socket fiberio::server_socket::accept ( )

Accept an incoming connection and get a socket representing it.

This is typically done repeatedly.

It's often useful to launch a new fiber for each connection with boost::fibers::async() (don't forget to std::move() the socket).

◆ bind()

void fiberio::server_socket::bind ( const std::string &  host,
uint16_t  port 
)

Binds the server_socket to an address and port.

This should be called befor listen(). Use get_host() and get_port() to check what it's actually bound to after.

A port of 0 will bind to any available port.

◆ close()

void fiberio::server_socket::close ( )

Close the listening socket and stop listening for connections.

◆ get_host()

std::string fiberio::server_socket::get_host ( )

Return the host that the server_socket is bound to.

◆ get_port()

uint16_t fiberio::server_socket::get_port ( )

Return the port that the server_socket is bound to.

◆ listen()

void fiberio::server_socket::listen ( int  backlog)

Start listening for connections with a certain backlog size.

This returns quickly and only tells the OS to start listening.

Use accept() to accept connections after.


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