MISOCKET Class Reference

The base class for MISOCKET_TCP and MISOCKET_LOCAL The base class does not have Open or Close methods. More...

#include <mi32/socket.h>

Inheritance diagram for MISOCKET:

Inheritance graph
[legend]
List of all members.

Public Types

enum  FAMILY { FAMILY_NONE = 0, FAMILY_LOCAL = 1, FAMILY_INET = 2 }
enum  TYPE { TYPE_NONE = 0, TYPE_STREAM = 1, TYPE_DGRAM = 2 }

Public Member Functions

MISOCKETAccept (ADDR &address)
 ADDR (const MISOCKET::IPADDR &ip, int port)
 ADDR ()
ERRVALUE Bind (const ADDR &address)
bool CallOnAccept (MISOCKET *socket, const MISOCKET::ADDR &addr)
void CallOnClose ()
void CallOnConnect ()
void CallOnReadReady ()
void CallOnTimeOut ()
void CallOnWriteReady ()
 CLIENT (MISOCKET *sock, bool bTakeOwnership=true)
 CLIENT ()
ERRVALUE Connect (const MISOCKET::ADDR &address)
ERRVALUE Connect (const ADDR &address)
void GetAddress (MISTRING &mistr, bool bDoReverseDNSLookup) const
void GetAddress (MISTRING &mistr, bool bDoReverseDNSLookup=false) const
const ADDR & GetAddress () const
MISOCKET::FAMILY GetFamily () const
const MISOCKET::IPADDR & GetIPAddress () const
const char * GetLocalName () const
int GetPort () const
MISOCKETGetSocket () const
void GetString (MISTRING &mistr, bool bDoReverseDNSLookup) const
int GetTimeOut () const
 IPADDR (UINT32 addr)
 IPADDR ()
bool IsConnected () const
bool IsNonBlocking () const
ERRVALUE Listen ()
 MISOCKET ()
ERRVALUE ReadStr (STRUTF8 &string)
void Set (const MISOCKET::IPADDR &ip, int port)
bool SetByName (const char *name)
void SetFamily (MISOCKET::FAMILY family)
void SetLocalName (const char *name)
void SetNonBlocking (bool bNonBlocking=true)
void SetSocket (MISOCKET *sock, bool bTakeOwnership=true)
void SetTimeOut (int seconds)
ERRVALUE Socket (FAMILY family, TYPE type=TYPE_STREAM)
ERRVALUE WriteStr (const char *str)
virtual ~CLIENT ()
virtual ~MISOCKET ()

Public Attributes

INT64 __ss_align
char __ss_pad1 [6]
char __ss_pad2 [112]
union {
   UINT32   S_addr
   struct {
      UINT8   s_b1
      UINT8   s_b2
      UINT8   s_b3
      UINT8   s_b4
   }   S_un_b
S_un
unsigned short sa_family

Protected Member Functions

void Destroy ()
char * GetBytePtr (int offset)
const char * GetBytePtr (int offset) const
UINT16 GetUINT16 (int offset) const
UINT32 GetUINT32 (int offset) const
void SetUINT16 (int offset, UINT16 val)
void SetUINT32 (int offset, UINT32 val)

Private Member Functions

virtual bool v_OnAccept (MISOCKET *socket, const MISOCKET::ADDR &addr)
virtual void v_OnClose ()
virtual void v_OnConnect ()
virtual void v_OnReadReady ()
virtual void v_OnTimeOut ()
virtual void v_OnWriteReady ()

Detailed Description

The base class for MISOCKET_TCP and MISOCKET_LOCAL The base class does not have Open or Close methods.

Bind and are implemented in the derived classes, as each implementation may take different parameters. You close a socket by deleting the class instance.

Definition at line 84 of file socket.h.


Member Enumeration Documentation

enum MISOCKET::FAMILY
 

Enumeration values:
FAMILY_NONE  Equivilant to AF_UNSPEC.
FAMILY_LOCAL  Equivilant to AF_UNIX.
FAMILY_INET  Equivilant to AF_INET.

Definition at line 87 of file socket.h.

enum MISOCKET::TYPE
 

Enumeration values:
TYPE_NONE  Invalid value for unitilized structures.
TYPE_STREAM  Equivilant to SOCK_STREAM. Provides sequenced, reliable, two-way connection-based byte streams.
TYPE_DGRAM  Equivilant to SOCK_DGRAM. Connectionless, unreliable buffers of a fixed maximum length.

Definition at line 93 of file socket.h.


Constructor & Destructor Documentation

MISOCKET::MISOCKET  ) 
 

virtual MISOCKET::~MISOCKET  )  [virtual]
 

Destructor.

If this socket has a CLIENT bound to it, the client will be reset to a NULL socket.

virtual MISOCKET::~CLIENT  )  [virtual]
 

Destructor.

If we "own" a socket, it will be deleted as well. Warning: Do NOT destroy client from within one if its virtual methods. The caller of that virtual method may not be done with the "this" yet. Call Destroy() from withing virtual methods.


Member Function Documentation

MISOCKET* MISOCKET::Accept ADDR &  address  ) 
 

Accept an incoming connection.

The socket must be in a listening state. If the socket is non-blocking and has a CLIENT attached to it, then this function will always return 0 and the client's OnAccept() will be called when an incoming connection is available Creates and returns a new socket for the connection. The address returned tells you where the incoming connection is from. It is up to the caller to delete the MISOCKET returned when done.

Parameters:
address  Address of incoming connection (returned)

MISOCKET::ADDR const MISOCKET::IPADDR &  ip,
int  port
 

Construct for an IP address.

MISOCKET::ADDR  ) 
 

Empty constructor.

ERRVALUE MISOCKET::Bind const ADDR &  address  ) 
 

Bind the socket to a given address This is done if you plan to make the socket into a listening socket or if you want all outgoing connections ton this socket to come from as specific address or port.

bool MISOCKET::CallOnAccept MISOCKET socket,
const MISOCKET::ADDR &  addr
 

void MISOCKET::CallOnClose  ) 
 

Will be called when the socket is closed out from under us (dropped connection or some such event).

WARNING: Do NOT destroy "this" from within this method or bad things may happen. Call Destroy() instead.

void MISOCKET::CallOnConnect  ) 
 

Will be called when a Connect call completes if the socket was non blocking.

void MISOCKET::CallOnReadReady  ) 
 

Will be called when there is data available if a previous read couldn't be filled and the socket was non-blocking.

void MISOCKET::CallOnTimeOut  ) 
 

Will be called if a timeout interval has been set and a previous call has timed out.

void MISOCKET::CallOnWriteReady  ) 
 

Will be called when the socket is ready to be written to.

MISOCKET::CLIENT MISOCKET sock,
bool  bTakeOwnership = true
 

Constructor.

Parameters:
sock The socket to watch. Can be NULL to indicate that we're not watching anything.
bTakeOwnership If true (the default) then this CLIENT "owns" the socket and will delete it.

MISOCKET::CLIENT  ) 
 

ERRVALUE MISOCKET::Connect const MISOCKET::ADDR &  address  ) 
 

Connect to a remote server.

ERRVALUE MISOCKET::Connect const ADDR &  address  ) 
 

Connect to a given server If the socket is non-blocking, Connect may return before the connection is actually made.

In this case, a CLIENT attached to the socket will have its OnConnect() called when the connection completes or OnTimeOut if it doesn't complete.

void MISOCKET::Destroy  )  [protected]
 

Destroy the client.

For use from within virtual methods.

void MISOCKET::GetAddress MISTRING mistr,
bool  bDoReverseDNSLookup
const
 

The the address in a humanly-readable format.

Parameters:
mistr The string to place the address in
bDoReverseDNSLookup If true, FAMILY_NET addresses will use reverse DNS to find the hostname of the address. If false, it will just use the numeric IP address. Ignored for other address families.

void MISOCKET::GetAddress MISTRING mistr,
bool  bDoReverseDNSLookup = false
const
 

Returns the address of the socket in a humanly-readable form.

Parameters:
mistr The string to place the address in
bDoReverseDNSLookup If true, IP sockets will use reverse DNS to find the hostname of the address. If false, it will just return the numeric IP address. Ignored for non-IP sockets.

const ADDR& MISOCKET::GetAddress  )  const
 

Returns the MISOCKET::ADDR of the socket.

If not bound to any address, the returned address will be unitialized and will have a family of FAMILY_NONE

char* MISOCKET::GetBytePtr int  offset  )  [protected]
 

const char* MISOCKET::GetBytePtr int  offset  )  const [protected]
 

MISOCKET::FAMILY MISOCKET::GetFamily  )  const
 

Get the socket family.

const MISOCKET::IPADDR& MISOCKET::GetIPAddress  )  const
 

Get the IP Address (FAMILY_INET only).

const char* MISOCKET::GetLocalName  )  const
 

Get the socket name (FAMILY_LOCAL only).

int MISOCKET::GetPort  )  const
 

Get the port (FAMILY_INET only).

MISOCKET* MISOCKET::GetSocket  )  const
 

Get the current socket for this client.

Returns:
a MISOCKET or NULL if no socket being monitored.

void MISOCKET::GetString MISTRING mistr,
bool  bDoReverseDNSLookup
const
 

int MISOCKET::GetTimeOut  )  const
 

Get the timeout interval in seconds.

UINT16 MISOCKET::GetUINT16 int  offset  )  const [protected]
 

UINT32 MISOCKET::GetUINT32 int  offset  )  const [protected]
 

MISOCKET::IPADDR UINT32  addr  ) 
 

Initialize with a known address.

Address must be in network byte order (hi-lo) XXX ?maybe?

MISOCKET::IPADDR  ) 
 

Empty constructor.

bool MISOCKET::IsConnected  )  const
 

Determine if this client is connected to anything.

bool MISOCKET::IsNonBlocking  )  const
 

Determine if the socket is nonblocking.

ERRVALUE MISOCKET::Listen  ) 
 

Put the socket into listening mode.

Must be previously Bound

ERRVALUE MISOCKET::ReadStr STRUTF8 string  ) 
 

Read a single new-line terminated string (stripping out the newline).

If there is no newline in the currently available input buffer this function will either wait for one or return false if the socket is non-blocking. Note: This function assumes that the incoming data is utf-8

Returns:
1 if a string was read, 0 if the socket is non-blocking and no string available yet, < 0 on error.

void MISOCKET::Set const MISOCKET::IPADDR &  ip,
int  port
 

Construct for an IP address.

bool MISOCKET::SetByName const char *  name  ) 
 

Set the address by looking up a host name.

Returns:
true if the name could be resolved, false if not.

void MISOCKET::SetFamily MISOCKET::FAMILY  family  ) 
 

Set the socket family.

void MISOCKET::SetLocalName const char *  name  ) 
 

Set the socket name (FAMILY_LOCAL only).

void MISOCKET::SetNonBlocking bool  bNonBlocking = true  ) 
 

Set the socket to non-blocking mode.

In non-blocking mode, if a read request cannot be fulfilled with what's currently available, it will return 0 and not read anything.

void MISOCKET::SetSocket MISOCKET sock,
bool  bTakeOwnership = true
 

Set the socket to watch.

If we're already watching a socket, that socket is first informed that we're no longer watching it. If we "own" the existing socket, it is deleted. If the socket is deleted out from under us, its destructor will reset our socket back to NULL.

Parameters:
sock The socket to watch. Can be NULL to indicate that we're not watching anything.
bTakeOwnership If true (the default) then this CLIENT "owns" the socket and will delete it.

void MISOCKET::SetTimeOut int  seconds  ) 
 

Set the timeout for I/O operations.

To disable timeouts, set it to 0.

void MISOCKET::SetUINT16 int  offset,
UINT16  val
[protected]
 

void MISOCKET::SetUINT32 int  offset,
UINT32  val
[protected]
 

ERRVALUE MISOCKET::Socket FAMILY  family,
TYPE  type = TYPE_STREAM
 

Allocates a new socket of a given family and type.

Parameters:
family  Socket family
type  Socket type (default is STREAM)

virtual bool MISOCKET::v_OnAccept MISOCKET socket,
const MISOCKET::ADDR &  addr
[private, virtual]
 

Will be called if a previous call to Accept() failed because the socket is non-blocking and the call would have blocked, but would now succeed.

Will be passed a pointer to the already accepted socket. If you wish to reject the connection, return false, and the caller will delete the socket for you. If you wish to accept the connection, return true. You are then responsible for deleting the socket when you're done with it.

virtual void MISOCKET::v_OnClose  )  [private, virtual]
 

Will be called when the socket is closed out from under us (dropped connection or some such event).

WARNING: Do NOT destroy "this" from within this method or bad things may happen. Call Destroy() instead.

virtual void MISOCKET::v_OnConnect  )  [private, virtual]
 

Will be called when a Connect call completes if the socket was non blocking.

virtual void MISOCKET::v_OnReadReady  )  [private, virtual]
 

Will be called when there is data available if a previous read couldn't be filled and the socket was non-blocking.

virtual void MISOCKET::v_OnTimeOut  )  [private, virtual]
 

Will be called if a timeout interval has been set and a previous call has timed out.

virtual void MISOCKET::v_OnWriteReady  )  [private, virtual]
 

Will be called when the socket is ready to be written to.

ERRVALUE MISOCKET::WriteStr const char *  str  ) 
 

Write a NULL-terminated string.


Member Data Documentation

INT64 MISOCKET::__ss_align
 

Definition at line 345 of file socket.h.

char MISOCKET::__ss_pad1[6]
 

Definition at line 344 of file socket.h.

char MISOCKET::__ss_pad2[112]
 

Definition at line 346 of file socket.h.

UINT32 MISOCKET::S_addr
 

Definition at line 305 of file socket.h.

UINT8 MISOCKET::s_b1
 

Definition at line 304 of file socket.h.

UINT8 MISOCKET::s_b2
 

Definition at line 304 of file socket.h.

UINT8 MISOCKET::s_b3
 

Definition at line 304 of file socket.h.

UINT8 MISOCKET::s_b4
 

Definition at line 304 of file socket.h.

union { ... } MISOCKET::S_un
 

struct { ... } MISOCKET::S_un_b
 

unsigned short MISOCKET::sa_family
 

Definition at line 343 of file socket.h.


The documentation for this class was generated from the following file:
Generated on Wed May 31 15:28:53 2006 for TNTsdk by  doxygen 1.3.8-20040913