The Open Master Hearing Aid (openMHA)  openMHA
Open community platform for hearing aid algorithm research
MHA_TCP::Server Class Reference

Public Member Functions

 Server (unsigned short port=0, const std::string &iface="0.0.0.0")
 Create a TCP server socket. More...
 
 Server (const std::string &iface, unsigned short port=0)
 Create a TCP server socket. More...
 
 ~Server ()
 Close the TCP server socket. More...
 
std::string get_interface () const
 Get the name given in the constructor for the network interface. More...
 
unsigned short get_port () const
 Get the port that the TCP server socket currently listens to. More...
 
Sockaccept_Eventget_accept_event ()
 Produces an event that can be observed by an Event_Watcher. More...
 
Connectionaccept ()
 Accept an incoming connection. More...
 
Connectiontry_accept ()
 Accept an incoming connection if it can be done without blocking. More...
 

Private Member Functions

void initialize (const std::string &iface, unsigned short port)
 

Private Attributes

sockaddr_in sock_addr
 
SOCKET serversocket
 
std::string iface
 
unsigned short port
 
Sockaccept_Eventaccept_event
 

Constructor & Destructor Documentation

◆ Server() [1/2]

Server::Server ( unsigned short  port = 0,
const std::string &  iface = "0.0.0.0" 
)

Create a TCP server socket.

Parameters
portThe TCP port to listen to.
ifaceThe network interface to bind to.

◆ Server() [2/2]

Server::Server ( const std::string &  iface,
unsigned short  port = 0 
)

Create a TCP server socket.

Parameters
portThe TCP port to listen to.
ifaceThe network interface to bind to.

◆ ~Server()

Server::~Server ( )

Close the TCP server socket.

Member Function Documentation

◆ initialize()

void Server::initialize ( const std::string &  iface,
unsigned short  port 
)
private

◆ get_interface()

std::string Server::get_interface ( ) const

Get the name given in the constructor for the network interface.

◆ get_port()

unsigned short Server::get_port ( ) const

Get the port that the TCP server socket currently listens to.

◆ get_accept_event()

Sockaccept_Event * Server::get_accept_event ( )

Produces an event that can be observed by an Event_Watcher.

This event signals incoming connections that can be accepted.

◆ accept()

Connection * Server::accept ( )

Accept an incoming connection.

blocks if necessary.

Returns
The new TCP connection. The connection has to be deleted by the caller.

◆ try_accept()

Connection * Server::try_accept ( )

Accept an incoming connection if it can be done without blocking.

Returns
The new TCP connection or 0 if there is no immediate connection. The connection has to be deleted by the caller.

Member Data Documentation

◆ sock_addr

sockaddr_in MHA_TCP::Server::sock_addr
private

◆ serversocket

SOCKET MHA_TCP::Server::serversocket
private

◆ iface

std::string MHA_TCP::Server::iface
private

◆ port

unsigned short MHA_TCP::Server::port
private

◆ accept_event

Sockaccept_Event* MHA_TCP::Server::accept_event
private

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