EHS Embedded HTTP Server  1.5.0.132
Socket Class Reference

plain socket implementation of NetworkAbstraction More...

#include <socket.h>

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

List of all members.

Public Member Functions

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

Protected Member Functions

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

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


Constructor & Destructor Documentation

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

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.

virtual ehs_socket_t GetFd ( ) const [inline, virtual]

Retrieves the underlying file descriptor.

Returns:
The FD/Socket of the listening socket.

Implements NetworkAbstraction.

Definition at line 111 of file socket.h.

References m_fd.

std::string GetLocalAddress ( ) const [protected, virtual]

Retrieves the peer address.

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

Implements NetworkAbstraction.

int GetLocalPort ( ) const [protected, virtual]

Retrieves the peer's port of a connection.

Returns:
The peer port.

Implements NetworkAbstraction.

std::string GetPeer ( ) const [protected, virtual]

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.

std::string GetRemoteAddress ( ) const [protected, virtual]

Retrieves the peer address.

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

Implements NetworkAbstraction.

int GetRemotePort ( ) const [protected, virtual]

Retrieves the peer's port of a connection.

Returns:
The peer port.

Implements NetworkAbstraction.

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.

virtual bool IsSecure ( ) const [inline, virtual]

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.

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.

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.

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.

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: