Nilorea Library

- Main Page
- Modules
- Data Structures
- Files

All Data Structures Files Functions Variables Typedefs Macros Groups
Data Structures | Macros | Typedefs | Functions
NETWORK: connect, accept, send and recv wrappers. Network Queue, thread-safe add/get message

## Data Structures

struct | N_SOCKET
struct | NETWORK

## Macros

#define | NETW_CLIENT 2
#define | NETW_SERVER 4
#define | NETW_RESTART_TIMER 8
#define | NETW_EMPTY_SENDBUF 16
#define | NETW_EMPTY_RECVBUF 32
#define | NETW_RUN -64
#define | NETW_PAUSE -128
#define | NETW_QUIT -256
#define | NETW_STOP -512
#define | NETW_ERROR -1024
#define | NETW_THR_ENGINE_STARTED 2048
#define | NETW_THR_ENGINE_STOPPED 4096

## Typedefs

typedef struct N_SOCKET | N_SOCKET
typedef struct NETWORK | NETWORK

## Functions

int | handle_wsa (int mode, int v1, int v2)
| Do not directly use, internal api. More...
int | netw_set (NETWORK *netw, int flag)
| Restart or reset the specified network ability. More...
int | netw_setsockopt (SOCKET sock, int disable_naggle, int sock_send_buf, int sock_recv_buf)
| Modify common socket options. Enable SO_REUSEADDR. More...
int | netw_tcp_socket (SOCKET *sock)
| Get a new tcp socket. More...
int | netw_connect_ex (NETWORK **netw, char *host, int port, int disable_naggle, int sock_send_buf, int sock_recv_buf, int send_list_limit, int recv_list_limit)
| Use this to connect a NETWORK to any listening one. More...
int | netw_connect (NETWORK **netw, char *host, int port)
| Use this to connect a NETWORK to any listening one, with following defaults: disable_naggle = 0 , untouched sockbufsendsize and sockbufrecvsize and unrestricted sned/recv lists. More...
int | netw_close (NETWORK **netw)
| Closing a specified Network, destroy queues, free the structure. More...
int | netw_stop_thr_engine (NETWORK *netw)
| Stop a NETWORK connection sending and receing thread. More...
int | netw_make_listening (NETWORK **netw, int PORT, int nbpending)
| Make a NETWORK be a Listening network. More...
NETWORK * | netw_accept_from_ex (NETWORK *from, int disable_naggle, int sock_send_buf, int sock_recv_buf, int send_list_limit, int recv_list_limit)
| make a normal 'accept' . Network 'from' must be allocated with netw_make_listening. More...
NETWORK * | netw_accept_from (NETWORK *from)
| make a normal 'accept' . Network 'from' must be allocated with netw_make_listening. More...
int | netw_add_msg (NETWORK *netw, N_STR *msg)
| Add a message to send in aimed NETWORK. More...
N_STR * | netw_get_msg (NETWORK *netw)
| Get a message from aimed NETWORK. More...
N_STR * | netw_wait_msg (NETWORK *netw, int refresh, int timeout)
| Wait a message from aimed NETWORK. Recheck each usec until a valid. More...
int | netw_start_thr_engine (NETWORK *netw)
| Start the NETWORK netw Threaded Engine. Create a sending & receiving thread. More...
void * | netw_send_func (void *NET)
| Thread send function. More...
void * | netw_recv_func (void *NET)
| To Thread Receiving function. More...
int | send_data (SOCKET s, char *buf, NSTRBYTE n)
| send data onto the socket More...
int | recv_data (SOCKET s, char *buf, NSTRBYTE n)
| recv data from the socket More...

## Detailed Description

## Macro Definition Documentation

#define NETW_CLIENT 2

NETWORK -> mode value for a CLIENT (meaning connecting)

Definition at line 62 of file n_network.h.

#define NETW_EMPTY_RECVBUF 32

Flag: empty recv buffer

Definition at line 70 of file n_network.h.

#define NETW_EMPTY_SENDBUF 16

Flag: empty send buffer

Definition at line 68 of file n_network.h.

#define NETW_ERROR -1024

State to signal errors in the network

Definition at line 80 of file n_network.h.

#define NETW_PAUSE -128

State for a NETWORK who want to pause processing of network queues

Definition at line 74 of file n_network.h.

#define NETW_QUIT -256

State for a NETWORK who want to end connection

Definition at line 76 of file n_network.h.

#define NETW_RESTART_TIMER 8

Flag: start or rester intertal network timing

Definition at line 66 of file n_network.h.

#define NETW_RUN -64

State for a running NETWORK

Definition at line 72 of file n_network.h.

#define NETW_SERVER 4

NETWORK -> mode value for a SERVER (meaning listening)

Definition at line 64 of file n_network.h.

#define NETW_STOP -512

State for a NETWORK that was first asked to QUIT, then STOPped

Definition at line 78 of file n_network.h.

#define NETW_THR_ENGINE_STARTED 2048

State for a started threaded network engine

Definition at line 82 of file n_network.h.

#define NETW_THR_ENGINE_STOPPED 4096

State for a stopped threaded network engine

Definition at line 84 of file n_network.h.

## Typedef Documentation

typedef struct N_SOCKET N_SOCKET

Structure of a N_SOCKET

typedef struct NETWORK NETWORK

Structure of a NETWORK

## Function Documentation

int handle_wsa | ( | int | mode,
|  | int | v1,
|  | int | v2
| ) |  |

Do not directly use, internal api.

Parameters

  mode | 1 for opening 0 for close 2 for status
  v1 | First digit of version requested
  v2 | Second digit of version requested

Returns
  TRUE on success FALSE on error

Definition at line 23 of file n_network.c.

Here is the caller graph for this function:

NETWORK * netw_accept_from | ( | NETWORK * | from | ) |

make a normal 'accept' . Network 'from' must be allocated with netw_make_listening.

Parameters

  from | The network from which to obtaion the connection

Returns
  NULL

Definition at line 550 of file n_network.c.

Here is the call graph for this function:

NETWORK * netw_accept_from_ex | ( | NETWORK * | from,
|  | int | disable_naggle,
|  | int | sock_send_buf,
|  | int | sock_recv_buf,
|  | int | send_list_limit,
|  | int | recv_list_limit
| ) |  |

make a normal 'accept' . Network 'from' must be allocated with netw_make_listening.

Parameters

  from | the network from where we accept
  disable_naggle | Disable Naggle Algorithm. Set to 1 do activate, 0 or negative to leave defaults
  sock_send_buf | NETW_SOCKET_SEND_BUF socket parameter , 0 or negative to leave defaults
  sock_recv_buf | NETW_SOCKET_RECV_BUF socket parameter , 0 or negative to leave defaults
  send_list_limit | Internal sending list maximum number of item. 0 or negative for unrestricted
  recv_list_limit | Internal receiving list maximum number of item. 0 or negative for unrestricted

Returns
  NULL on failure, if not a pointer to the connected network

Definition at line 444 of file n_network.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int netw_add_msg | ( | NETWORK * | netw,
|  | N_STR * | msg
| ) |  |

Add a message to send in aimed NETWORK.

Parameters

  netw | NETWORK where add the message
  msg | the message to add

Returns
  TRUE if success FALSE on error

Definition at line 563 of file n_network.c.

Here is the call graph for this function:

Here is the caller graph for this function:

netw_close | ( | NETWORK ** | netw | ) |

Closing a specified Network, destroy queues, free the structure.

Parameters

  netw | A NETWORK *network to close

Returns
  TRUE on success , FALSE on failure

Definition at line 341 of file n_network.c.

Here is the call graph for this function:

int netw_connect | ( | NETWORK ** | netw,
|  | char * | host,
|  | int | port
| ) |  |

Use this to connect a NETWORK to any listening one, with following defaults: disable_naggle = 0 , untouched sockbufsendsize and sockbufrecvsize and unrestricted sned/recv lists.

Parameters

  netw | a NETWORK *object
  host | Host or IP to connect to
  port | Port to use to connect

Returns
  TRUE or FALSE

Definition at line 288 of file n_network.c.

Here is the call graph for this function:

int netw_connect_ex | ( | NETWORK ** | netw,
|  | char * | host,
|  | int | port,
|  | int | disable_naggle,
|  | int | sock_send_buf,
|  | int | sock_recv_buf,
|  | int | send_list_limit,
|  | int | recv_list_limit
| ) |  |

Use this to connect a NETWORK to any listening one.

Parameters

  netw | a NETWORK *object
  host | Host or IP to connect to
  port | Port to use to connect
  disable_naggle | Disable Naggle Algorithm. Set to 1 do activate, 0 or negative to leave defaults
  sock_send_buf | NETW_SOCKET_SEND_BUF socket parameter , 0 or negative to leave defaults
  sock_recv_buf | NETW_SOCKET_RECV_BUF socket parameter , 0 or negative to leave defaults
  send_list_limit | Internal sending list maximum number of item. 0 or negative for unrestricted
  recv_list_limit | Internal receiving list maximum number of item. 0 or negative for unrestricted

Returns
  TRUE or FALSE

Definition at line 154 of file n_network.c.

Here is the call graph for this function:

Here is the caller graph for this function:

N_STR * netw_get_msg | ( | NETWORK * | netw | ) |

Get a message from aimed NETWORK.

Parameters

  netw | NETWORK where get the msg

Returns
  NULL or a filled N_STR

Definition at line 595 of file n_network.c.

Here is the caller graph for this function:

int netw_make_listening | ( | NETWORK ** | netw,
|  | int | PORT,
|  | int | nbpending
| ) |  |

Make a NETWORK be a Listening network.

Parameters

  netw | A NETWORK **network to make listening
  PORT | For choosing a PORT to listen to
  nbpending | Number of pending connection when listening

Returns
  TRUE on success, FALSE on error

Definition at line 376 of file n_network.c.

Here is the call graph for this function:

void * netw_recv_func | ( | void * | NET | ) |

To Thread Receiving function.

Parameters

  NET | the NETWORK connection to use

Definition at line 815 of file n_network.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void * netw_send_func | ( | void * | NET | ) |

Thread send function.

Parameters

  NET | the NETWORK connection to use, casted into (void*)

Definition at line 691 of file n_network.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int netw_set | ( | NETWORK * | netw,
|  | int | flag
| ) |  |

Restart or reset the specified network ability.

Parameters

  netw | The NETWORK *connection to modify
  flag | NETW_EMPTY_SENDBUF, NETW_EMPTY_RECVBUF, NETW_PAUSE , NETW_RUN

Returns
  TRUE or FALSE

Definition at line 301 of file n_network.c.

Here is the call graph for this function:

int netw_setsockopt | ( | SOCKET | sock,
|  | int | disable_naggle,
|  | int | sock_send_buf,
|  | int | sock_recv_buf
| ) |  |

Modify common socket options. Enable SO_REUSEADDR.

Parameters

  sock | The socket to configure
  disable_naggle | Set to positive to enable. Set to zero or negative to leave the default.
  sock_send_buf | If >0, then try to set the socket send buffer size in octet
  sock_recv_buf | If >0, then try to set the socket recv buffer size in octet

Returns
  TRUE or FALSE

Definition at line 78 of file n_network.c.

Here is the caller graph for this function:

netw_start_thr_engine | ( | NETWORK * | netw | ) |

Start the NETWORK netw Threaded Engine. Create a sending & receiving thread.

Parameters

  netw | The aimed NETWORK connection to start receiving data

Returns
  TRUE on success FALSE on failure

Definition at line 653 of file n_network.c.

Here is the call graph for this function:

netw_stop_thr_engine | ( | NETWORK * | netw | ) |

Stop a NETWORK connection sending and receing thread.

Parameters

  netw | The aimed NETWORK conection to stop

Returns
  TRUE on success FALSE on failure

Definition at line 938 of file n_network.c.

int netw_tcp_socket | ( | SOCKET * | sock | ) |

Get a new tcp socket.

Parameters

  sock | Pointer to a valid and empty SOCKET

Returns
  TRUE or FALSE (in that case sock is untouched)

Definition at line 124 of file n_network.c.

Here is the caller graph for this function:

N_STR * netw_wait_msg | ( | NETWORK * | netw,
|  | int | refresh,
|  | int | timeout
| ) |  |

Wait a message from aimed NETWORK. Recheck each usec until a valid.

Parameters

  netw | The link on which we wait a message
  refresh | The time in usec between each check until there is a message
  timeout | Maximum amount of time to wait before returnin. Pass a value <= 0 to disable.

Returns
  NULL or a filled N_STR

Definition at line 619 of file n_network.c.

Here is the call graph for this function:

recv_data | ( | SOCKET | s,
|  | char * | buf,
|  | NSTRBYTE | n
| ) |  |

recv data from the socket

Parameters

  s | connected socket
  buf | pointer to buffer
  n | number of characters we want

Returns
  -1 on error, n on success

Definition at line 1020 of file n_network.c.

Here is the caller graph for this function:

send_data | ( | SOCKET | s,
|  | char * | buf,
|  | NSTRBYTE | n
| ) |  |

send data onto the socket

Parameters

  s | connected socket
  buf | pointer to buffer
  n | number of characters we want to send

Returns
  -1 on error, n on success

Definition at line 980 of file n_network.c.

Here is the caller graph for this function: