COSA
An Object-Oriented Platform for Arduino Programming
INET::Server Class Referenceabstract

#include <INET.hh>

Collaboration diagram for INET::Server:
Collaboration graph

Public Member Functions

 Server (IOStream &ios)
 
Socketsocket ()
 
void client (INET::addr_t &addr)
 
virtual bool begin (Socket *sock)
 
virtual int run (uint32_t ms=0L)
 
virtual bool end ()
 
virtual bool on_accept (IOStream &ios)
 
virtual void on_connect (IOStream &ios)
 
virtual void on_request (IOStream &ios)=0
 
virtual void on_disconnect ()
 

Protected Attributes

IOStreamm_ios
 
bool m_connected
 

Detailed Description

Server request handler. Should be sub-classed and the virtual member function on_request() should be implemented to receive client requests and send responses.

Definition at line 184 of file INET.hh.

Constructor & Destructor Documentation

INET::Server::Server ( IOStream ios)
inline

Default server constructor. Must call begin() to initiate with socket. Associate with given io-stream. The socket will be bound as the io-stream device.

Parameters
[in]iosassociated io-stream.

Definition at line 192 of file INET.hh.

Member Function Documentation

bool INET::Server::begin ( Socket sock)
virtual

Start server with given socket. Initiates socket for incoming connection-oriented requests (TCP/listen). Returns true if successful otherwise false.

Parameters
[in]sockserver socket.
Returns
bool.

Definition at line 34 of file INET_Server.cpp.

void INET::Server::client ( INET::addr_t addr)

Get client address, network address and port.

Parameters
[out]addrnetwork address.

Definition at line 26 of file INET_Server.cpp.

bool INET::Server::end ( )
virtual

Stop server and close socket. Returns true if successful otherwise false.

Returns
bool.

Definition at line 92 of file INET_Server.cpp.

virtual bool INET::Server::on_accept ( IOStream ios)
inlinevirtual

Application extension; Called when a client connect has been accepted. Return true if application accepts otherwise false.

Parameters
[in]iosiostream for response.
Returns
bool.

Definition at line 248 of file INET.hh.

virtual void INET::Server::on_connect ( IOStream ios)
inlinevirtual

Application extension; Called when a client connect has been accepted.

Parameters
[in]iosiostream for response.

Definition at line 260 of file INET.hh.

virtual void INET::Server::on_disconnect ( )
inlinevirtual

Application extension; Called when a client disconnects.

Definition at line 277 of file INET.hh.

virtual void INET::Server::on_request ( IOStream ios)
pure virtual

Application extension; Should implement the response to the incoming request. Called with there is available data.

Parameters
[in]iosiostream for request and response.
int INET::Server::run ( uint32_t  ms = 0L)
virtual

Run server; service incoming client connect requests or data. Wait for at most given time period. Zero time period will give blocking behavior. Returns zero if successful or negative error code. The error code ETIME is returned on timeout.

Parameters
[in]mstimeout period (milli-seconds, default BLOCK(0L)).
Returns
zero or negative error code.

Definition at line 47 of file INET_Server.cpp.

Socket* INET::Server::socket ( )
inline

Get server socket.

Returns
socket.

Definition at line 201 of file INET.hh.

Member Data Documentation

bool INET::Server::m_connected
protected

State variable; listening/disconnect(false), connected(true).

Definition at line 284 of file INET.hh.

IOStream& INET::Server::m_ios
protected

Associated io-stream

Definition at line 281 of file INET.hh.


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