|
0 A.D. | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Contains the basic socket I/O abstraction and event callback methods. A CSocketBase can only be instantiated as a subclass, none of the functions are meant to exist as anything other than helper functions for socket classes Any CSocket subclass that can be Accept:ed by a CServerSocket should provide a constructor that takes a CSocketInternal pointer, and hands it to the base class constructor.
Inner Classes, Typedefs, and Enums | |
enum |
CSocketBase::Ops
These values are bitwise or-ed to produce op masks |
Field Summary | |
private PS_RESULT |
m_Error
|
private bool |
m_NonBlocking
|
private CSocketInternal* |
m_pInternal
|
private ESocketProtocol |
m_Proto
|
private ESocketState |
m_State
|
Constructor Summary | |
protected |
CSocketBase( CSocketInternal* pInt )
Initialize a CSocketBase from a CSocketInternal pointer. |
|
CSocketBase()
Constructs a CSocketBase. |
protected |
virtual ~CSocketBase()
|
Method Summary | |
private static void |
AbortWaitLoop()
Abort the call to RunWaitLoop(), if one is currently running. |
CSocketInternal* |
Accept()
Accept the next incoming connection. |
PS_RESULT |
Bind( const CSocketAddress& address )
Bind the socket to the specified address and start listening for incoming connections. |
void |
Close()
Close the socket. |
PS_RESULT |
Connect( const CSocketAddress& addr )
Connect the socket to the specified address. |
private bool |
ConnectError( CSocketBase* pSocket )
|
void |
Destroy()
Destroy the OS socket. |
inline PS_RESULT |
GetErrorState() const
Return the error state of the socket. |
protected uint |
GetOpMask()
Get the op mask for the socket. |
inline ESocketProtocol |
GetProtocol() const
Returns the protocol set by Initialize. |
const CSocketAddress& |
GetRemoteAddress()
Get the address of the remote end to which the socket is connected. |
inline ESocketState |
GetState() const
Return the connection state of the socket. |
PS_RESULT |
Initialize( ESocketProtocol proto = IPv4 )
Create the OS socket for the specified protocol type. |
inline bool |
IsNonBlocking() const
Return the current non-blocking state of the socket. |
virtual void |
OnClose( PS_RESULT errorCode )= 0
The socket has been closed. |
virtual void |
OnRead()= 0
Called by the Network Thread when data is available for reading. |
virtual void |
OnWrite()= 0
Called by the Network Thread when data can be written to the socket. |
PS_RESULT |
PreAccept( CSocketAddress& addr )
Store the address of the next incoming connection in the SocketAddress pointed to by addr. |
PS_RESULT |
Read( void* buf, uint len, uint* bytesRead )
Attempt to read data from the socket. |
void |
Reject()
Reject the next incoming connection. |
private static void |
RunWaitLoop()
Loop forever, waiting for events and calling the callbacks on sockets, according to their Op mask. |
private static void |
SendWaitLoopAbort()
Tell the running wait loop to abort. |
private void |
SendWaitLoopUpdate()
|
void |
SetNonBlocking( bool nonBlocking = true )
Set or reset non-blocking operation. |
protected void |
SetOpMask( uint ops )
Set the op mask for the socket, specifying which callbacks should be called by the WaitLoop. |
void |
SetTcpNoDelay( bool tcpNoDelay = true )
Disable Nagle's algorithm (enable no-delay working mode) |
static void |
Shutdown()
Forcibly shuts down the network wait loop. |
private static void |
SocketReadable( CSocketBase* )
|
private static void |
SocketWritable( CSocketBase* )
|
PS_RESULT |
Write( void* buf, uint len, uint* bytesWritten )
Attempt to write data to the socket. |
Field Detail |
private PS_RESULT m_Error;
private bool m_NonBlocking;
private CSocketInternal* m_pInternal;
private ESocketProtocol m_Proto;
private ESocketState m_State;
Constructor Detail |
protected CSocketBase( CSocketInternal* pInt );
public CSocketBase();
Connect
, Bind
protected virtual ~CSocketBase();
Method Detail |
private static void AbortWaitLoop();
public CSocketInternal* Accept();
public PS_RESULT Bind( const CSocketAddress& address );
addr
- The address to bind toSocketAddress::SocketAddress(int,SocketProtocol)
public void Close();
public PS_RESULT Connect( const CSocketAddress& addr );
addr
- The address to connect toSocketAddress::Resolve
private bool ConnectError( CSocketBase* pSocket );
public void Destroy();
public inline PS_RESULT GetErrorState() const;
GetState()
protected uint GetOpMask();
public inline ESocketProtocol GetProtocol() const;
public const CSocketAddress& GetRemoteAddress();
public inline ESocketState GetState() const;
SocketState
, GetError()
public PS_RESULT Initialize( ESocketProtocol proto = IPv4 );
public inline bool IsNonBlocking() const;
SetNonBlocking(bool)
public virtual void OnClose( PS_RESULT errorCode )= 0;
errorCode
- A result code describing the reason why the socket was
closedpublic virtual void OnRead()= 0;
public virtual void OnWrite()= 0;
public PS_RESULT PreAccept( CSocketAddress& addr );
addr
- A pointer to a SocketAddressAccept(SocketAddress&)
, Reject()
public PS_RESULT Read( void* buf, uint len, uint* bytesRead );
buf
- A pointer to the buffer where the data should be written
len
- The amount of data that should be read.
bytesRead
- The number of bytes read will be stored in the variable
pointed to by bytesReadpublic void Reject();
private static void RunWaitLoop();
private static void SendWaitLoopAbort();
private void SendWaitLoopUpdate();
public void SetNonBlocking( bool nonBlocking = true );
CSocketBase::Read
, CSocketBase::Write
, CSocketBase::Connect
protected void SetOpMask( uint ops );
public void SetTcpNoDelay( bool tcpNoDelay = true );
public static void Shutdown();
private static void SocketReadable( CSocketBase* );
private static void SocketWritable( CSocketBase* );
public PS_RESULT Write( void* buf, uint len, uint* bytesWritten );
buf
- A pointer to the data that should be written
len
- The length of the buffer.
bytesWritten
- The number of bytes written will be stored in the
variable pointed to by bytesWritten
|
0 A.D.
Generated on September 04, 2007 at 18:13 CppDoc v2.4.0 |
|||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |