EHS Embedded HTTP Server  1.5.1.0
Socket Class Reference

plain socket implementation of NetworkAbstraction More...

#include <socket.h>

+ Inheritance diagram for Socket:
+ Collaboration diagram for Socket:

Public Member Functions

 Socket ()
 Default constructor.
 
virtual void RegisterBindHelper (PrivilegedBindHelper *helper)
 Registers a PrivilegedBindHelper for use by this instance. More...
 
virtual void Init (int port)
 Initializes a listening socket. More...
 
virtual void SetBindAddress (const char *bindAddress)
 Sets the bind address of the socket. More...
 
virtual ehs_socket_t GetFd () const
 Retrieves the underlying file descriptor. More...
 
virtual int Read (void *buf, int bufsize)
 Performs a read from the underlying socket. More...
 
virtual int Send (const void *buf, size_t buflen, int flags=0)
 Performs a send on the underlying socket. More...
 
virtual void Close ()
 Closes the underlying socket.
 
virtual NetworkAbstractionAccept ()
 Waits for an incoming connection. More...
 
virtual bool IsSecure () const
 Determines, whether the underlying socket is secure. More...
 
virtual void ThreadCleanup ()
 Handles thread specific clean up (used by OpenSSL).
 
- Public Member Functions inherited from NetworkAbstraction
virtual std::string GetAddress () const
 Retrieves the peer address. More...
 
virtual int GetPort () const
 Retrieves the peer's port of a connection. More...
 
virtual ~NetworkAbstraction ()
 Destructor.
 

Protected Member Functions

 Socket (ehs_socket_t fd, sockaddr_in *peer)
 Constructs a new Socket, connected to a client. More...
 
int GetLocalPort () const
 Retrieves the peer's port of a connection. More...
 
int GetRemotePort () const
 Retrieves the peer's port of a connection. More...
 
std::string GetLocalAddress () const
 Retrieves the peer address. More...
 
std::string GetRemoteAddress () const
 Retrieves the peer address. More...
 
std::string GetPeer () const
 Combination of GetRemoteAddress and GetRemotePort. More...
 

Protected Attributes

ehs_socket_t m_fd
 The file descriptor of the socket on which this connection came in.
 
sockaddr_in m_peer
 Stores the peer address of the current connection.
 
sockaddr_in m_bindaddr
 Stores the bind address.
 
PrivilegedBindHelperm_pBindHelper
 Our bind helper.
 

Detailed Description

plain socket implementation of NetworkAbstraction

Definition at line 80 of file socket.h.

Constructor & Destructor Documentation

◆ Socket()

Socket ( ehs_socket_t  fd,
sockaddr_in *  peer 
)
protected

Constructs a new Socket, connected to a client.

Parameters
fdThe socket descriptor of this connection.
peerThe peer address of this socket

Member Function Documentation

◆ Accept()

virtual NetworkAbstraction* Accept ( )
virtual

Waits for an incoming connection.

Returns
A new NetworkAbstraction instance which represents the client connetion.
Exceptions
Astd:runtime_error on failure.

Implements NetworkAbstraction.

Referenced by GetFd().

+ Here is the caller graph for this function:

◆ GetFd()

virtual ehs_socket_t GetFd ( ) const
inlinevirtual

Retrieves the underlying file descriptor.

Returns
The FD/Socket of the listening socket.

Implements NetworkAbstraction.

Definition at line 111 of file socket.h.

References Accept(), Close(), m_fd, Read(), and Send().

+ Here is the call graph for this function:

◆ GetLocalAddress()

std::string GetLocalAddress ( ) const
protectedvirtual

Retrieves the peer address.

Returns
The address of the connected peer in quad-dotted format.

Implements NetworkAbstraction.

Referenced by ThreadCleanup().

+ Here is the caller graph for this function:

◆ GetLocalPort()

int GetLocalPort ( ) const
protectedvirtual

Retrieves the peer's port of a connection.

Returns
The peer port.

Implements NetworkAbstraction.

Referenced by ThreadCleanup().

+ Here is the caller graph for this function:

◆ GetPeer()

std::string GetPeer ( ) const
protectedvirtual

Combination of GetRemoteAddress and GetRemotePort.

Returns
The address of the connected peer in quad-dotted format, followed by the port, separated by a colon.

Implements NetworkAbstraction.

Referenced by ThreadCleanup().

+ Here is the caller graph for this function:

◆ GetRemoteAddress()

std::string GetRemoteAddress ( ) const
protectedvirtual

Retrieves the peer address.

Returns
The address of the connected peer in quad-dotted format.

Implements NetworkAbstraction.

Referenced by ThreadCleanup().

+ Here is the caller graph for this function:

◆ GetRemotePort()

int GetRemotePort ( ) const
protectedvirtual

Retrieves the peer's port of a connection.

Returns
The peer port.

Implements NetworkAbstraction.

Referenced by ThreadCleanup().

+ Here is the caller graph for this function:

◆ Init()

virtual void Init ( int  port)
virtual

Initializes a listening socket.

If listening should be restricted to a specific address, SetBindAddress has to be called in advance.

Parameters
portThe port to listen on.
Exceptions
Astd:runtime_error if initialization fails.

Implements NetworkAbstraction.

◆ IsSecure()

virtual bool IsSecure ( ) const
inlinevirtual

Determines, whether the underlying socket is secure.

Returns
false, because this instance does not use SSL.

Implements NetworkAbstraction.

Definition at line 123 of file socket.h.

◆ Read()

virtual int Read ( void *  buf,
int  bufsize 
)
virtual

Performs a read from the underlying socket.

Parameters
bufPointer to a buffer that receives the incoming data.
bufsizeThe maximum number of bytes to read.
Returns
The actual number of bytes that have been received or -1 if an error occured.

Implements NetworkAbstraction.

Referenced by GetFd().

+ Here is the caller graph for this function:

◆ RegisterBindHelper()

virtual void RegisterBindHelper ( PrivilegedBindHelper helper)
virtual

Registers a PrivilegedBindHelper for use by this instance.

Parameters
helperThe PrivilegedBindHelper to be used by this instance.

Implements NetworkAbstraction.

◆ Send()

virtual int Send ( const void *  buf,
size_t  buflen,
int  flags = 0 
)
virtual

Performs a send on the underlying socket.

Parameters
bufPointer to the data to be sent.
buflenThe number of bytes to send.
flagsAdditional flags for the system call.
Returns
The actual number of byte that have been sent or -1 if an error occured.

Implements NetworkAbstraction.

Referenced by GetFd().

+ Here is the caller graph for this function:

◆ SetBindAddress()

virtual void SetBindAddress ( const char *  bindAddress)
virtual

Sets the bind address of the socket.

Parameters
bindAddressThe address to bind to in quad-dotted format.

Implements NetworkAbstraction.


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