AnCH Framework  0.1
Another C++ Hack Framework
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
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, anch::network::SocketType type=anch::network::SocketType::UNKNOWN) throw (anch::network::IOException)
 
virtual ~Socket () noexcept
 
virtual void bind () throw (anch::network::IOException)
 
virtual void connect () throw (anch::network::IOException)
 
virtual void listen () throw (anch::network::IOException)
 
virtual void accept (Socket &socket) throw (anch::network::IOException)
 
virtual void send (const std::string &message)=0 throw (anch::network::IOException)
 
virtual void receive (std::string &message)=0 throw (anch::network::IOException)
 
virtual void receive () throw (anch::network::IOException)
 
virtual void shutdown (anch::network::Direction how=anch::network::Direction::BOTH) throw (anch::network::IOException)
 
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< anch::network::SocketEvent >
 Observable ()
 
virtual ~Observable ()
 
bool addObserver (anch::events::Observer< anch::network::SocketEvent > &observer)
 
void removeObserver (anch::events::Observer< anch::network::SocketEvent > &observer)
 
void notifyObservers (const anch::network::SocketEvent &event)
 

Protected Member Functions

 Socket (anch::network::SocketType type)
 

Protected Attributes

SOCKET _sock
 
int _backlog
 
addrinfo * _address
 

Detailed Description

Network socket management class

Author
Vincent Lachenal

Constructor & Destructor Documentation

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

Socket constructor.

Parameters
typeThe socket type
Socket::Socket ( const std::string &  ipAddress,
uint16_t  port,
anch::network::SocketType  type = anch::network::SocketType::UNKNOWN 
)
throw (anch::network::IOException
)

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::~Socket ( )
virtualnoexcept

Socket destructor

Member Function Documentation

void Socket::accept ( Socket socket)
throw (anch::network::IOException
)
virtual

Accept client connection

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

Accept client connection

Exceptions
anch::network::IOExceptionError while accepting client connection

Reimplemented in anch::network::UdpSocket.

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

Bind socket

Exceptions
anch::network::IOExceptionError while binding the socket
void Socket::close ( )
virtualnoexcept

Close the socket

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

Connect to remote socket

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

Reimplemented in anch::network::UdpSocket.

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

Backlog getter

Returns
The backlog
virtual int anch::network::Socket::getDomain ( ) const
pure virtual

Get the socket domain

Returns
The POSIX socket domain

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

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

IP address getter

Returns
The IP address
uint16_t anch::network::Socket::getPort ( ) const
inline

Destination port getter

Returns
The destination port
anch::network::SocketType anch::network::Socket::getSocketType ( ) const
inline

Socket type getter

Returns
The socket type
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, and anch::network::TcpSocket.

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

Listen on socket

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

Reimplemented in anch::network::UdpSocket.

virtual void anch::network::Socket::receive ( std::string &  message)
throw (anch::network::IOException
)
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::UdpSocket, and anch::network::TcpSocket.

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

Receive a message on socket

Exceptions
anch::network::IOExceptionNetwork error while receiving message
virtual void anch::network::Socket::send ( const std::string &  message)
throw (anch::network::IOException
)
pure virtual

Send a message on socket

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

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

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

Backlog setter

Parameters
backlogThe backlog to set
void anch::network::Socket::setIpAddress ( const std::string &  ipAddress)
inline

IP address setter

Parameters
ipAddressThe IP address to set
void anch::network::Socket::setIpAddress ( uint16_t  port)
inline

Destination port setter

Parameters
portThe destination port to set
void anch::network::Socket::setSocketType ( SocketType  type)
inline

Socket type setter

Parameters
typeThe socket type to set
void Socket::shutdown ( anch::network::Direction  how = anch::network::Direction::BOTH)
throw (anch::network::IOException
)
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

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

Member Data Documentation

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

The address informations

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

The number of connection in waiting state

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

The socket


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