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.

Classes

struct  ADDR
 A generic socket address. More...
class  CLIENT
 Base class for any client that wants to be notified of a socket's state. More...
struct  IPADDR
 An Internet Protocol address. More...

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

 MISOCKET ()
virtual ~MISOCKET ()
MISOCKETAccept (ADDR &address)
ERRVALUE Bind (const ADDR &address)
ERRVALUE Connect (const ADDR &address)
void GetAddress (MISTRING &mistr, bool bDoReverseDNSLookup=false) const
const ADDRGetAddress () const
bool GetSockName (ADDR &addr) const
int GetTimeOut () const
bool IsNonBlocking () const
ERRVALUE Listen ()
ERRVALUE ReadStr (STRUTF8 &string)
void SetNonBlocking (bool bNonBlocking=true)
void SetTimeOut (int seconds)
ERRVALUE Socket (FAMILY family, TYPE type=TYPE_STREAM)
ERRVALUE WriteStr (const char *str)

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.


Member Enumeration Documentation

Enumerator:
FAMILY_NONE 

Equivilant to AF_UNSPEC.

FAMILY_LOCAL 

Equivilant to AF_UNIX.

FAMILY_INET 

Equivilant to AF_INET.

Enumerator:
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.


Constructor & Destructor Documentation

MISOCKET::MISOCKET (  ) 

Default constructor.

virtual MISOCKET::~MISOCKET (  )  [virtual]

Destructor.

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


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)
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.

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::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

bool MISOCKET::GetSockName ( ADDR addr  )  const

Gets the address of local end of a connected socket.

This is useful on a multi-homed server to find out which interface you're connected through.

Returns:
true if the address was filled in, false if not.
int MISOCKET::GetTimeOut (  )  const

Get the timeout interval in seconds.

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::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::SetTimeOut ( int  seconds  ) 

Set the timeout for I/O operations.

To disable timeouts, set it to 0.

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)
ERRVALUE MISOCKET::WriteStr ( const char *  str  ) 

Write a NULL-terminated string.


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

Generated on Sun Oct 7 21:33:39 2012 for TNTsdk 2012 by  doxygen 1.6.1