#include <mi32/socket.h>
Inheritance diagram for MISOCKET:

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 * | Accept (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 |
| MISOCKET * | GetSocket () 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 () |
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.
|
|
|
|
|
|
|
|
|
|
|
Destructor. If this socket has a CLIENT bound to it, the client will be reset to a NULL socket. |
|
|
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. |
|
|
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.
|
|
||||||||||||
|
Construct for an IP address.
|
|
|
Empty constructor.
|
|
|
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.
|
|
||||||||||||
|
|
|
|
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. |
|
|
Will be called when a Connect call completes if the socket was non blocking.
|
|
|
Will be called when there is data available if a previous read couldn't be filled and the socket was non-blocking.
|
|
|
Will be called if a timeout interval has been set and a previous call has timed out.
|
|
|
Will be called when the socket is ready to be written to.
|
|
||||||||||||
|
Constructor.
|
|
|
|
|
|
Connect to a remote server.
|
|
|
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. |
|
|
Destroy the client. For use from within virtual methods. |
|
||||||||||||
|
The the address in a humanly-readable format.
|
|
||||||||||||
|
Returns the address of the socket in a humanly-readable form.
|
|
|
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 |
|
|
|
|
|
|
|
|
Get the socket family.
|
|
|
Get the IP Address (FAMILY_INET only).
|
|
|
Get the socket name (FAMILY_LOCAL only).
|
|
|
Get the port (FAMILY_INET only).
|
|
|
Get the current socket for this client.
|
|
||||||||||||
|
|
|
|
Get the timeout interval in seconds.
|
|
|
|
|
|
|
|
|
Initialize with a known address. Address must be in network byte order (hi-lo) XXX ?maybe? |
|
|
Empty constructor.
|
|
|
Determine if this client is connected to anything.
|
|
|
Determine if the socket is nonblocking.
|
|
|
Put the socket into listening mode. Must be previously Bound |
|
|
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
|
|
||||||||||||
|
Construct for an IP address.
|
|
|
Set the address by looking up a host name.
|
|
|
Set the socket family.
|
|
|
Set the socket name (FAMILY_LOCAL only).
|
|
|
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. |
|
||||||||||||
|
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.
|
|
|
Set the timeout for I/O operations. To disable timeouts, set it to 0. |
|
||||||||||||
|
|
|
||||||||||||
|
|
|
||||||||||||
|
Allocates a new socket of a given family and type.
|
|
||||||||||||
|
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. |
|
|
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. |
|
|
Will be called when a Connect call completes if the socket was non blocking.
|
|
|
Will be called when there is data available if a previous read couldn't be filled and the socket was non-blocking.
|
|
|
Will be called if a timeout interval has been set and a previous call has timed out.
|
|
|
Will be called when the socket is ready to be written to.
|
|
|
Write a NULL-terminated string.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1.3.8-20040913