net.h File Reference


Defines

#define NET_API

Typedefs

typedef void(*) SocketEventCallback (int socket)
 Signature of the callback functions.

Enumerations

enum  {
  NET_STARTUP_FAILED = 1, NET_CLEANUP_FAILED, NET_BIND_FAILED, NET_CREATE_SOCKET_FAILED,
  NET_GET_HOST_BY_NAME_FAILED, NET_LISTEN_FAILED, NET_ACCEPT_FAILED, NET_CLOSE_SOCKET_FAILED,
  NET_CONNECT_FAILED, NET_WOULD_BLOCK, NET_WRITE_FAILED, NET_READ_FAILED,
  NET_LOOP_FAILED
}
 Possible error codes. More...

Functions

NET_API void netRegisterReadCallback (SocketEventCallback callback)
 Register callback for read events.
NET_API void netRegisterWriteCallback (SocketEventCallback callback)
 Register callback for write events.
NET_API void netRegisterErrorCallback (SocketEventCallback callback)
 Register callback for write events.
NET_API int netStartup ()
 Initialize the network system.
NET_API int netCleanup ()
 Shutdown the network system.
NET_API int netCreateSocket (int *socketHandle)
 Create an outgoing socket.
NET_API int netCreateServerSocket (const char *address, int port, int *socketHandle)
 Create and bind a server socket (if address is NULL, bind to any address).
NET_API int netListen (int serverSocket, int backlog)
 Start listening on a server socket.
NET_API int netConnect (int socket, const char *address, int port)
 Connect to the specified address and port.
NET_API int netAccept (int serverSocket, char **ipAddress, int *socketHandle)
 Can be called on the accept callback to accept an incoming connection.
NET_API int netCloseSocket (int socket)
 Close a socket.
NET_API int netWait (int millisecondsTimeout)
 Wait for an event or timeout.
NET_API int netWrite (int socket, const void *data, int size)
 Write to a socket.
NET_API int netRead (int socket, void *data, int size)
 Read from a socket.
NET_API void netSleep (int milliseconds)
 Sleep for the specified time in milliseconds.
NET_API void netFree (void *pointer)
 Free memory, which was created by this library, e.g. the IP address in netAccept.

Variables

NET_API SocketEventCallback g_readCallback
NET_API SocketEventCallback g_writeCallback
NET_API SocketEventCallback g_errorCallback

Define Documentation

#define NET_API


Typedef Documentation

typedef void(*) SocketEventCallback(int socket)

Signature of the callback functions.


Enumeration Type Documentation

anonymous enum

Possible error codes.

Every function, which returns an int, returns a value >= 0, or a value < 0 for errors (use -NET_CONSTANT for the error value). NET_WOULD_BLOCK is not an error, but an information.

Enumerator:
NET_STARTUP_FAILED  netStartup failed.
NET_CLEANUP_FAILED  netCleanup failed.
NET_BIND_FAILED  bind in netCreateServerSocket failed.
NET_CREATE_SOCKET_FAILED  Socket creation in netCreateSocket or netCreateServerSocket failed.
NET_GET_HOST_BY_NAME_FAILED  Host name lookup failed in netConnect or netCreateServerSocket.
NET_LISTEN_FAILED  netListen failed.
NET_ACCEPT_FAILED  netAccept failed.
NET_CLOSE_SOCKET_FAILED  netCloseSocket failed.
NET_CONNECT_FAILED  netConnect failed.
NET_WOULD_BLOCK  netRead or netWrite result.
NET_WRITE_FAILED  netWrite failed.
NET_READ_FAILED  netRead failed.
NET_LOOP_FAILED  netLoop failed.


Function Documentation

NET_API int netAccept ( int  serverSocket,
char **  ipAddress,
int *  socketHandle 
)

Can be called on the accept callback to accept an incoming connection.

NET_API int netCleanup (  ) 

Shutdown the network system.

NET_API int netCloseSocket ( int  socket  ) 

Close a socket.

NET_API int netConnect ( int  socket,
const char *  address,
int  port 
)

Connect to the specified address and port.

NET_API int netCreateServerSocket ( const char *  address,
int  port,
int *  socketHandle 
)

Create and bind a server socket (if address is NULL, bind to any address).

NET_API int netCreateSocket ( int *  socketHandle  ) 

Create an outgoing socket.

NET_API void netFree ( void *  pointer  ) 

Free memory, which was created by this library, e.g. the IP address in netAccept.

This function is neccessary, because memory allocated by this library could be incompatible with the memory system used by programs which links this library.

NET_API int netListen ( int  serverSocket,
int  backlog 
)

Start listening on a server socket.

NET_API int netRead ( int  socket,
void *  data,
int  size 
)

Read from a socket.

There are four possible cases (result: returned value from this function) :

NET_API void netRegisterErrorCallback ( SocketEventCallback  callback  ) 

Register callback for write events.

The callback is called on error, e.g. netConnect timeout.

NET_API void netRegisterReadCallback ( SocketEventCallback  callback  ) 

Register callback for read events.

The callback is called when data can be read without blocking or when an incoming connection for a server socket can be accepted.

NET_API void netRegisterWriteCallback ( SocketEventCallback  callback  ) 

Register callback for write events.

The callback is called when a socket was connected or when it is possible to write more data with netWrite.

NET_API void netSleep ( int  milliseconds  ) 

Sleep for the specified time in milliseconds.

NET_API int netStartup (  ) 

Initialize the network system.

NET_API int netWait ( int  millisecondsTimeout  ) 

Wait for an event or timeout.

NET_API int netWrite ( int  socket,
const void *  data,
int  size 
)

Write to a socket.

There are three possible cases (result: returned value from this function) :


Variable Documentation

NET_API SocketEventCallback g_errorCallback

NET_API SocketEventCallback g_readCallback

NET_API SocketEventCallback g_writeCallback


Generated on Fri May 18 00:18:44 2007 by  doxygen 1.5.2