Free Electron
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
fe::ext::Socket Class Reference

A socket wrapper. More...

#include <Socket.h>

Inheritance diagram for fe::ext::Socket:
Inheritance graph
[legend]

Public Types

enum  Transport {
  e_tcp = 0,
  e_udp = 1
}
 
enum  ReadMode {
  e_readNormal = 0,
  e_readPeek = 1,
  e_readNoWait = 2
}
 

Public Member Functions

 Socket (void)
 Constructor. More...
 
 Socket (Poison *pPoison)
 Construct a socket with the given poison. More...
 
virtual void openStream (Transport transport=e_tcp, BWORD server=FALSE)
 Wraps bsd socket(AF_INET, SOCK_STREAM, 0) call. More...
 
virtual SockHandle socket (int domain, int type, int protocol)
 Wraps bsd socket() call. More...
 
virtual void bind (SockAddr &sockaddr)
 Wraps bsd bind() call. More...
 
virtual void listen (int backlog)
 Wraps bsd listen() call. More...
 
virtual sp< Socketaccept (SockAddr &sockaddr)
 Wraps bsd accept() call. More...
 
virtual void connect (SockAddr &sockaddr)
 Wraps bsd connect() call. More...
 
virtual IWORD read (const void *pBuffer, IWORD count, ReadMode readMode=e_readNormal)
 Wraps bsd recv() call. More...
 
virtual IWORD write (const void *pBuffer, IWORD count)
 Wraps bsd send() call. More...
 
virtual void setPoison (Poison *pPoison)
 Set a Poison object. More...
 
virtual void wait (void)
 Wait for the socket to be readable (via select), checking at a regular interval for Poison to be active. More...
 
virtual void close (void)
 Close the underlying socket. More...
 
virtual bool isOpen (void)
 Return true if the socket is open, otherwise return false. More...
 
virtual U32 id (void)
 Return a network identifier unique among Sockets connected to the same accept()ing 'server' Socket. More...
 
SockHandle sockHandle () const
 
Transport transportType () const
 
SockAddr sockAddrOwn () const
 
- Public Member Functions inherited from fe::Counted
virtual void acquire (void)
 Increment the reference count. More...
 
virtual void acquire (int &rCount)
 Increment the reference count (and get the count) More...
 
virtual void release (void)
 Decrement the reference count. More...
 
virtual void abandon (void)
 Decrement the reference count. More...
 
int count (void) const
 Return the count of references. More...
 
void setName (const String &)
 
void trackReference (void *pReference, String what)
 
void untrackReference (void *pReference)
 
void registerRegion (void *pT, U32 bytes)
 

Static Public Member Functions

static void startup (void)
 Startup socket networking. More...
 
static void shutdown (void)
 Shutdown socket networking. More...
 
- Static Public Member Functions inherited from fe::Counted
static String reportTracker (void)
 
static U32 trackerCount (void)
 

Private Member Functions

IWORD udpRead (const void *pBuffer, IWORD count, ReadMode readMode)
 
IWORD udpWrite (const void *pBuffer, IWORD count)
 

Private Attributes

SockHandle m_sock_handle
 
bool m_open
 
bool m_original
 
Poisonm_pPoison
 
U32 m_id
 
U32 m_nextID
 
Transport m_transportType
 
BWORD m_server
 
SockAddr m_udpSockAddrOwn
 

Static Private Attributes

static bool m_wsaStarted = false
 

Additional Inherited Members

- Protected Member Functions inherited from fe::Counted
int releaseInternal (void)
 Decrement the reference count. More...
 
void suppressReport (void)
 

Detailed Description

A socket wrapper.

The premise of this wrapper is to be simple and to the point. Flexibility and extensibility are not explicitly considered. The intent is that all network communication will go through class and does not care about TCP/IP details.

A concept of thread poison is supported by this class due to the blocking calls (accept, read, connect). If Poison is associated with the Socket, then blocking calls will be aborted if the Poison becomes active before the calls can return normally. If this happens then a Poisoned exception is thrown.

A concept of network identifier is also supported by this class to provide a notion of site uniqueness in a networked application. It is implemented in this lower level abstraction to assure simplicity in maintaining uniqueness. A socket's unique id is 0 until it does a connect() in which case it will be given a unique id from the other side of the connection (presumably a 'server').

Constructor & Destructor Documentation

◆ Socket() [1/2]

fe::ext::Socket::Socket ( void  )

Constructor.

◆ Socket() [2/2]

fe::ext::Socket::Socket ( Poison pPoison)

Construct a socket with the given poison.

Member Function Documentation

◆ accept()

sp< Socket > fe::ext::Socket::accept ( SockAddr sockaddr)
virtual

Wraps bsd accept() call.

References fe::ext::SockAddr::size().

◆ bind()

void fe::ext::Socket::bind ( SockAddr sockaddr)
virtual

Wraps bsd bind() call.

◆ close()

void fe::ext::Socket::close ( void  )
virtual

Close the underlying socket.

◆ connect()

void fe::ext::Socket::connect ( SockAddr sockaddr)
virtual

Wraps bsd connect() call.

◆ id()

U32 fe::ext::Socket::id ( void  )
virtual

Return a network identifier unique among Sockets connected to the same accept()ing 'server' Socket.

Note that this has nothing to do with a socket descriptor.

◆ isOpen()

bool fe::ext::Socket::isOpen ( void  )
virtual

Return true if the socket is open, otherwise return false.

◆ listen()

void fe::ext::Socket::listen ( int  backlog)
virtual

Wraps bsd listen() call.

◆ openStream()

void fe::ext::Socket::openStream ( Transport  transport = e_tcp,
BWORD  server = FALSE 
)
virtual

Wraps bsd socket(AF_INET, SOCK_STREAM, 0) call.

◆ read()

IWORD fe::ext::Socket::read ( const void *  pBuffer,
IWORD  count,
ReadMode  readMode = e_readNormal 
)
virtual

Wraps bsd recv() call.

◆ setPoison()

void fe::ext::Socket::setPoison ( Poison pPoison)
virtual

Set a Poison object.

◆ shutdown()

void fe::ext::Socket::shutdown ( void  )
static

Shutdown socket networking.

◆ socket()

SockHandle fe::ext::Socket::socket ( int  domain,
int  type,
int  protocol 
)
virtual

Wraps bsd socket() call.

◆ startup()

void fe::ext::Socket::startup ( void  )
static

Startup socket networking.

Only required on Win32, but should always be done for portability.

◆ wait()

void fe::ext::Socket::wait ( void  )
virtual

Wait for the socket to be readable (via select), checking at a regular interval for Poison to be active.

Mainly for internal use by read(), accept(), and connect()

◆ write()

IWORD fe::ext::Socket::write ( const void *  pBuffer,
IWORD  count 
)
virtual

Wraps bsd send() call.


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