Free Electron
|
A socket wrapper. More...
#include <Socket.h>
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< Socket > | accept (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 |
![]() | |
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 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 |
Poison * | m_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 | |
![]() | |
int | releaseInternal (void) |
Decrement the reference count. More... | |
void | suppressReport (void) |
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').
fe::ext::Socket::Socket | ( | void | ) |
Constructor.
Wraps bsd accept() call.
References fe::ext::SockAddr::size().
|
virtual |
Close the underlying socket.
|
virtual |
|
virtual |
Return true if the socket is open, otherwise return false.
|
virtual |
Wraps bsd listen() call.
|
virtual |
Wraps bsd socket(AF_INET, SOCK_STREAM, 0) call.
|
virtual |
Wraps bsd recv() call.
|
static |
Shutdown socket networking.
|
virtual |
Wraps bsd socket() call.
|
static |
Startup socket networking.
Only required on Win32, but should always be done for portability.
|
virtual |
|
virtual |
Wraps bsd send() call.