AnCH Framework 0.1
Another C++ Hack Framework
Loading...
Searching...
No Matches
anch::network::Socket Class Referenceabstract

#include <socket.hpp>

Inheritance diagram for anch::network::Socket:
Collaboration diagram for anch::network::Socket:

Public Member Functions

 Socket (const std::string &ipAddress, uint16_t port, SocketType type=SocketType::UNKNOWN)
virtual ~Socket () noexcept
virtual void bind ()
virtual void connect ()
virtual void listen ()
virtual void accept (Socket &socket)
virtual void send (const std::string &message)=0
virtual void receive (std::string &message)=0
virtual void receive ()
virtual void shutdown (Direction how=Direction::BOTH)
virtual void close () noexcept
virtual int getDomain () const =0
virtual int getType () const =0
const std::string & getIpAddress () const
void setIpAddress (const std::string &ipAddress)
uint16_t getPort () const
void setIpAddress (uint16_t port)
anch::network::SocketType getSocketType () const
void setSocketType (SocketType type)
int getBacklog () const
void setBacklog (int backlog)
Public Member Functions inherited from anch::events::Observable< SocketEvent >
 Observable ()
virtual ~Observable ()
bool addObserver (anch::events::Observer< SocketEvent > &observer)
void removeObserver (anch::events::Observer< SocketEvent > &observer)
void notifyObservers (const SocketEvent &event, const std::map< std::string, std::string > &headers={})

Protected Member Functions

 Socket (SocketType type)

Protected Attributes

SOCKET _sock
int _backlog
addrinfo * _address

Detailed Description

Network socket management class

Author
Vincent Lachenal

Constructor & Destructor Documentation

◆ Socket() [1/2]

anch::network::Socket::Socket ( SocketType type)
protected

Socket constructor.

Parameters
typeThe socket type

◆ Socket() [2/2]

anch::network::Socket::Socket ( const std::string & ipAddress,
uint16_t port,
SocketType type = SocketType::UNKNOWN )

Socket constructor.
Backlog is set to 5 by default. You can change it using the setter before call listen method.

Parameters
ipAddressIP address
portDestination port
typeThe socket type
Exceptions
anch::network::IOExceptionError while creating the socket

◆ ~Socket()

virtual anch::network::Socket::~Socket ( )
virtualnoexcept

Socket destructor

Member Function Documentation

◆ accept()

virtual void anch::network::Socket::accept ( Socket & socket)
virtual

Accept client connection

Parameters
socketThe socket which describes client connection
Exceptions
anch::network::IOExceptionError while accepting client connection

Reimplemented in anch::network::UdpSocket.

Here is the call graph for this function:

◆ bind()

virtual void anch::network::Socket::bind ( )
virtual

Bind socket

Exceptions
anch::network::IOExceptionError while binding the socket
Here is the call graph for this function:

◆ close()

virtual void anch::network::Socket::close ( )
virtualnoexcept

Close the socket

Here is the call graph for this function:

◆ connect()

virtual void anch::network::Socket::connect ( )
virtual

Connect to remote socket

Exceptions
anch::network::IOExceptionError while connectin the client socket to the server socket

Reimplemented in anch::network::UdpSocket.

Here is the call graph for this function:

◆ getBacklog()

int anch::network::Socket::getBacklog ( ) const
inline

Backlog getter

Returns
The backlog

◆ getDomain()

virtual int anch::network::Socket::getDomain ( ) const
pure virtual

Get the socket domain

Returns
The POSIX socket domain

Implemented in anch::network::UdpSocket.

Here is the call graph for this function:

◆ getIpAddress()

const std::string & anch::network::Socket::getIpAddress ( ) const
inline

IP address getter

Returns
The IP address
Here is the call graph for this function:

◆ getPort()

uint16_t anch::network::Socket::getPort ( ) const
inline

Destination port getter

Returns
The destination port

◆ getSocketType()

anch::network::SocketType anch::network::Socket::getSocketType ( ) const
inline

Socket type getter

Returns
The socket type

◆ getType()

virtual int anch::network::Socket::getType ( ) const
pure virtual

Get the socket service type

Returns
The POSIX socket service type

Implemented in anch::network::UdpSocket.

Here is the call graph for this function:

◆ listen()

virtual void anch::network::Socket::listen ( )
virtual

Listen on socket

Exceptions
anch::network::IOExceptionError while listening on the socket

Reimplemented in anch::network::UdpSocket.

Here is the call graph for this function:

◆ receive() [1/2]

virtual void anch::network::Socket::receive ( )
virtual

Receive a message on socket

Exceptions
anch::network::IOExceptionNetwork error while receiving message
Here is the call graph for this function:

◆ receive() [2/2]

virtual void anch::network::Socket::receive ( std::string & message)
pure virtual

Receive a message on socket

Parameters
messageThe messages which has been received
Exceptions
anch::network::IOExceptionNetwork error while receiving message

Implemented in anch::network::TcpSocket, and anch::network::UdpSocket.

Here is the call graph for this function:

◆ send()

virtual void anch::network::Socket::send ( const std::string & message)
pure virtual

Send a message on socket

Parameters
messageThe message to send
Exceptions
anch::network::IOExceptionNetwork error while sending message

Implemented in anch::network::TcpSocket, and anch::network::UdpSocket.

Here is the call graph for this function:

◆ setBacklog()

void anch::network::Socket::setBacklog ( int backlog)
inline

Backlog setter

Parameters
backlogThe backlog to set

◆ setIpAddress() [1/2]

void anch::network::Socket::setIpAddress ( const std::string & ipAddress)
inline

IP address setter

Parameters
ipAddressThe IP address to set

◆ setIpAddress() [2/2]

void anch::network::Socket::setIpAddress ( uint16_t port)
inline

Destination port setter

Parameters
portThe destination port to set

◆ setSocketType()

void anch::network::Socket::setSocketType ( SocketType type)
inline

Socket type setter

Parameters
typeThe socket type to set

◆ shutdown()

virtual void anch::network::Socket::shutdown ( Direction how = Direction::BOTH)
virtual

Shutdown data flow between client and server.
This method has to be called by server.

Parameters
howDirection of the data flow which has to be closed
Exceptions
anch::network::IOExceptionNetwork error while shutting down data transfer
Here is the call graph for this function:

Member Data Documentation

◆ _address

addrinfo* anch::network::Socket::_address
protected

The address informations

◆ _backlog

int anch::network::Socket::_backlog
protected

The number of connection in waiting state

◆ _sock

SOCKET anch::network::Socket::_sock
protected

The socket


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