Nilorea Library
C utilities for networking, threading, graphics
|
Data Structures | |
struct | N_SOCKET |
Structure of a N_SOCKET. More... | |
struct | NETWORK |
Structure of a NETWORK. More... | |
struct | NETWORK_POOL |
structure of a network pool More... | |
Macros | |
#define | HEAD_CODE 3 |
Code of a HEAD message. More... | |
#define | HEAD_SIZE 10 |
Size of a HEAD message. More... | |
#define | N_ENUM_netw_code_type(_) |
Network codes definition. More... | |
#define | NETWORK_CONSECUTIVE_SEND_TIMEOUT 8192 |
Flag to set consecutive send waiting timeout More... | |
#define | NETWORK_DEPLETE_TIMEOUT 4096 |
Flag to set send buffer depletion timeout More... | |
#define | NETWORK_IPALL 0 |
Flag for auto detection by OS of ip version to use. More... | |
#define | NETWORK_IPV4 1 |
Flag to force IPV4 More... | |
#define | NETWORK_IPV6 2 |
Flag to force IPV6 More... | |
#define | SOCKET SOCKET_TYPE |
socket macro shortcut More... | |
Typedefs | |
typedef int(* | netw_func) (SOCKET, char *, NSTRBYTE) |
send/recv func ptr type More... | |
typedef int | SOCKET_TYPE |
default socket declaration More... | |
Functions | |
N_ENUM_DECLARE (N_ENUM_netw_code_type, __netw_code_type) | |
Network codes declaration. | |
NETWORK * | netw_accept_from (NETWORK *from) |
make a normal blocking 'accept' . More... | |
NETWORK * | netw_accept_from_ex (NETWORK *from, int send_list_limit, int recv_list_limit, int non_blocking, int *retval) |
make a normal 'accept' . More... | |
NETWORK * | netw_accept_nonblock_from (NETWORK *from, int blocking) |
make a normal blocking 'accept' . More... | |
int | netw_add_msg (NETWORK *netw, N_STR *msg) |
Add a message to send in aimed NETWORK. More... | |
int | netw_add_msg_ex (NETWORK *netw, char *str, unsigned int length) |
Add a message to send in aimed NETWORK. More... | |
int | netw_close (NETWORK **netw) |
Closing a specified Network, destroy queues, free the structure. More... | |
int | netw_connect (NETWORK **netw, char *host, char *port, int ip_version) |
Use this to connect a NETWORK to any listening one, unrestricted send/recv lists. More... | |
int | netw_connect_ex (NETWORK **netw, char *host, char *port, int send_list_limit, int recv_list_limit, int ip_version) |
Use this to connect a NETWORK to any listening one. More... | |
int | netw_destroy_pool (NETWORK_POOL **netw_pool) |
free a NETWORK_POOL *pool More... | |
N_STR * | netw_get_msg (NETWORK *netw) |
Get a message from aimed NETWORK. More... | |
int | netw_get_queue_status (NETWORK *netw, int *nb_to_send, int *nb_to_read) |
retrieve network send queue status More... | |
int | netw_get_state (NETWORK *netw, int *state, int *thr_engine_status) |
Get the state of a network. More... | |
int | netw_init_wsa (int mode, int v1, int v2) |
Do not directly use, internal api. More... | |
int | netw_make_listening (NETWORK **netw, char *addr, char *port, int nbpending, int ip_version) |
Make a NETWORK be a Listening network. More... | |
NETWORK_POOL * | netw_new_pool (int nb_min_element) |
return a new network pool of nb_min_element More... | |
int | netw_pool_add (NETWORK_POOL *netw_pool, NETWORK *netw) |
add a NETWORK *netw to a NETWORK_POOL *pool More... | |
int | netw_pool_broadcast (NETWORK_POOL *netw_pool, NETWORK *from, N_STR *net_msg) |
add net_msg to all network in netork pool More... | |
int | netw_pool_nbclients (NETWORK_POOL *netw_pool) |
return the number of networks in netw_pool More... | |
void | netw_pool_netw_close (void *netw_ptr) |
close a network from a network pool More... | |
int | netw_pool_remove (NETWORK_POOL *netw_pool, NETWORK *netw) |
remove a NETWORK *netw to a NETWORK_POOL *pool More... | |
void * | netw_recv_func (void *NET) |
To Thread Receiving function. More... | |
void * | netw_send_func (void *NET) |
Thread send function. More... | |
int | netw_send_ident (NETWORK *netw, int type, int id, N_STR *name, N_STR *passwd) |
Add a formatted NETWMSG_IDENT message to the specified network. More... | |
int | netw_send_ping (NETWORK *netw, int type, int id_from, int id_to, int time) |
Add a ping reply to the network. More... | |
int | netw_send_position (NETWORK *netw, int id, double X, double Y, double vx, double vy, double acc_x, double acc_y, int time_stamp) |
Add a formatted NETWMSG_IDENT message to the specified network. More... | |
int | netw_send_quit (NETWORK *netw) |
Add a formatted NETMSG_QUIT message to the specified network. More... | |
int | netw_send_string_to (NETWORK *netw, int id_to, N_STR *name, N_STR *chan, N_STR *txt, int color) |
Add a string to the network, aiming a specific user. More... | |
int | netw_send_string_to_all (NETWORK *netw, N_STR *name, N_STR *chan, N_STR *txt, int color) |
Add a string to the network, aiming all server-side users. More... | |
int | netw_set (NETWORK *netw, int flag) |
Restart or reset the specified network ability. More... | |
int | netw_set_blocking (NETWORK *netw, unsigned long int is_blocking) |
Modify blocking socket mode. More... | |
int | netw_set_user_id (NETWORK *netw, int id) |
associate an id and a network More... | |
int | netw_setsockopt (NETWORK *netw, int optname, int value) |
Modify common socket options on the given netw. More... | |
int | netw_start_thr_engine (NETWORK *netw) |
Start the NETWORK netw Threaded Engine. More... | |
int | netw_stop_thr_engine (NETWORK *netw) |
Stop a NETWORK connection sending and receing thread. More... | |
int | netw_wait_close (NETWORK **netw) |
Wait for peer closing a specified Network, destroy queues, free the structure. More... | |
int | netw_wait_close_timed (NETWORK **netw, size_t timeout) |
Wait for peer closing a specified Network, destroy queues, free the structure. More... | |
N_STR * | netw_wait_msg (NETWORK *netw, size_t refresh, size_t timeout) |
Wait a message from aimed NETWORK. More... | |
int | recv_data (SOCKET s, char *buf, NSTRBYTE n) |
recv data from the socket More... | |
int | recv_php (SOCKET s, int *_code, char **buf) |
recv data from the socket More... | |
int | send_data (SOCKET s, char *buf, NSTRBYTE n) |
send data onto the socket More... | |
int | send_php (SOCKET s, int _code, char *buf, int n) |
send data onto the socket More... | |
struct N_SOCKET |
Structure of a N_SOCKET.
Definition at line 230 of file n_network.h.
Data Fields | ||
---|---|---|
struct addrinfo | hints | address of local machine |
char * | ip | ip of the connected socket |
unsigned long int | is_blocking | flag to quickly check socket mode |
char * | port | port of socket |
struct sockaddr_storage | raddr | connected remote addr |
struct addrinfo * | rhost | getaddrinfo results |
SOCKET | sock | a normal socket |
struct NETWORK |
Data Fields | ||
---|---|---|
int | addr_infos_loaded | Internal flag to know if we have to free addr infos. |
int | crypto_algo | if encryption is on, which one (flags NETW_ENCRYPT_*) |
int | crypto_mode | tell if the socket have to be encrypted (flags NETW_CRYPTO_*) |
size_t | deplete_timeout | deplete send buffer ( 0 disabled, > 0 wait for timeout and check unset/unack datas) |
pthread_mutex_t | eventbolt | mutex for threaded access of state event |
N_SOCKET | link | networking socket |
int | mode | NETWORK mode , 1 listening, 0 connecting. |
int | nb_pending | Nb pending connection,if listening. |
int | nb_running_threads | nb running threads, if > 0 thread engine is still running |
LIST * | pools | pointers to network pools if members of any |
LIST * | recv_buf | reveicing buffer (for incomming usage) |
netw_func | recv_data | receive func ptr |
pthread_t | recv_thr | receiving thread |
pthread_mutex_t | recvbolt | mutex for threaded access of recv buf |
sem_t | send_blocker | block sending func |
LIST * | send_buf | sending buffer (for outgoing queuing ) |
netw_func | send_data | send func ptr |
int | send_queue_consecutive_wait | send queue consecutive pool interval, used when there are still items to send, in usec |
pthread_t | send_thr | sending thread |
pthread_mutex_t | sendbolt | mutex for threaded access of send_buf |
int | so_linger | close lingering value (-1 disabled, 0 force close, >0 linger ) |
int | so_rcvbuf | size of the socket recv buffer, 0 untouched, else size in bytes |
int | so_rcvtimeo | send timeout value |
int | so_reuseaddr | so reuseaddr state |
int | so_sndbuf | size of the socket send buffer, 0 untouched, else size in bytes |
int | so_sndtimeo | send timeout value |
int | state | state of the connection , NETW_RUN, NETW_QUIT, NETW_STOP , NETW_ERR |
int | tcpnodelay | state of naggle algorythm, 0 untouched, 1 forcibly disabled |
int | threaded_engine_status |
Threaded network engine state for this network. NETW_THR_ENGINE_STARTED or NETW_THR_ENGINE_STOPPED |
int | user_id | if part of a user property, id of the user |
char * | vigenere_key | vigenere key |
struct NETWORK_POOL |
structure of a network pool
Definition at line 340 of file n_network.h.
Data Fields | ||
---|---|---|
HASH_TABLE * | pool | table of clients |
pthread_rwlock_t | rwlock | thread safety |
#define HEAD_CODE 3 |
Code of a HEAD message.
Definition at line 39 of file n_network.h.
#define HEAD_SIZE 10 |
Size of a HEAD message.
Definition at line 37 of file n_network.h.
#define N_ENUM_netw_code_type | ( | _ | ) |
Network codes definition.
Definition at line 202 of file n_network.h.
#define NETWORK_CONSECUTIVE_SEND_TIMEOUT 8192 |
Flag to set consecutive send waiting timeout
Definition at line 35 of file n_network.h.
#define NETWORK_DEPLETE_TIMEOUT 4096 |
Flag to set send buffer depletion timeout
Definition at line 33 of file n_network.h.
#define NETWORK_IPALL 0 |
Flag for auto detection by OS of ip version to use.
Definition at line 27 of file n_network.h.
#define NETWORK_IPV4 1 |
#define NETWORK_IPV6 2 |
#define SOCKET SOCKET_TYPE |
socket macro shortcut
Definition at line 54 of file n_network.h.
send/recv func ptr type
Definition at line 227 of file n_network.h.
typedef int SOCKET_TYPE |
make a normal blocking 'accept' .
Network 'from' must be allocated with netw_make_listening.
from | The network from which to obtaion the connection |
Definition at line 1940 of file n_network.c.
References netw_accept_from_ex().
NETWORK * netw_accept_from_ex | ( | NETWORK * | from, |
int | send_list_limit, | ||
int | recv_list_limit, | ||
int | non_blocking, | ||
int * | retval | ||
) |
make a normal 'accept' .
Network 'from' must be allocated with netw_make_listening.
from | the network from where we accept |
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 |
non_blocking | set to -1 to make it non blocking, to 0 for blocking, else it's the select timeout value in msecs. |
retval | EAGAIN ou EWOULDBLOCK or neterrno (use netstrerr( retval) to obtain a string describing the code ) |
Definition at line 1791 of file n_network.c.
References __n_assert, _str, FreeNoLog, get_in_addr(), LOG_DEBUG, LOG_ERR, LOG_INFO, Malloc, n_log, neterrno, netstrerror, netw_close(), netw_init_wsa(), netw_new(), netw_set(), netw_set_blocking(), and netw_setsockopt().
Referenced by netw_accept_from(), and netw_accept_nonblock_from().
make a normal blocking 'accept' .
Network 'from' must be allocated with netw_make_listening.
from | The network from which to obtaion the connection |
blocking | set to -1 to make it non blocking, to 0 for blocking, else it's the select timeout value in mseconds. |
Definition at line 1953 of file n_network.c.
References netw_accept_from_ex().
Add a message to send in aimed NETWORK.
netw | NETWORK where add the message |
msg | the message to add |
Definition at line 1965 of file n_network.c.
References __n_assert, free_nstr_ptr(), list_push(), LOG_ERR, and n_log.
Referenced by netw_pool_broadcast(), netw_send_ident(), netw_send_ping(), netw_send_position(), netw_send_quit(), netw_send_string_to(), netw_send_string_to_all(), send_net_datas(), userlist_add_msg_to_ex(), userlist_send_waiting_msgs(), and userlist_user_send_waiting_msgs().
int netw_add_msg_ex | ( | NETWORK * | netw, |
char * | str, | ||
unsigned int | length | ||
) |
Add a message to send in aimed NETWORK.
netw | NETWORK where add the message |
str | the message to add |
length | the size of the message to add |
Definition at line 2001 of file n_network.c.
References __n_assert, free_nstr_ptr(), list_push(), LOG_ERR, Malloc, and n_log.
int netw_close | ( | NETWORK ** | netw | ) |
Closing a specified Network, destroy queues, free the structure.
netw | A NETWORK *network to close |
Definition at line 1480 of file n_network.c.
References __n_assert, Free, FreeNoLog, list_destroy(), list_foreach, LOG_DEBUG, n_log, netw_get_state(), netw_pool_remove(), netw_set(), and netw_stop_thr_engine().
Referenced by netw_accept_from_ex(), netw_connect_ex(), netw_make_listening(), netw_new(), netw_set_blocking(), and netw_wait_close_timed().
int netw_connect | ( | NETWORK ** | netw, |
char * | host, | ||
char * | port, | ||
int | ip_version | ||
) |
Use this to connect a NETWORK to any listening one, unrestricted send/recv lists.
netw | a NETWORK *object |
host | Host or IP to connect to |
port | Port to use to connect |
ip_version | NETWORK_IPALL for both ipv4 and ipv6 , NETWORK_IPV4 or NETWORK_IPV6 |
Definition at line 1361 of file n_network.c.
References _str, LOG_INFO, n_log, and netw_connect_ex().
int netw_connect_ex | ( | NETWORK ** | netw, |
char * | host, | ||
char * | port, | ||
int | send_list_limit, | ||
int | recv_list_limit, | ||
int | ip_version | ||
) |
Use this to connect a NETWORK to any listening one.
netw | a NETWORK *object |
host | Host or IP to connect to |
port | Port to use to connect |
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 |
ip_version | NETWORK_IPALL for both ipv4 and ipv6 , NETWORK_IPV4 or NETWORK_IPV6 |
Definition at line 1226 of file n_network.c.
References __n_assert, _str, Free, FreeNoLog, get_in_addr(), LOG_DEBUG, LOG_ERR, LOG_INFO, Malloc, n_log, neterrno, netstrerror, netw_close(), netw_init_wsa(), netw_new(), netw_set(), NETWORK_IPV4, and NETWORK_IPV6.
Referenced by netw_connect().
int netw_destroy_pool | ( | NETWORK_POOL ** | netw_pool | ) |
free a NETWORK_POOL *pool
netw_pool | the address of a NETWORK_POOL *pointer to free |
Definition at line 2869 of file n_network.c.
References __n_assert, destroy_ht(), Free, rw_lock_destroy, unlock, and write_lock.
Get a message from aimed NETWORK.
netw | NETWORK where get the msg |
Definition at line 2044 of file n_network.c.
References __n_assert, and list_shift.
Referenced by manage_client(), and netw_wait_msg().
int netw_get_queue_status | ( | NETWORK * | netw, |
int * | nb_to_send, | ||
int * | nb_to_read | ||
) |
retrieve network send queue status
netw | NETWORK object |
nb_to_send | Number of messages still in send buffer (not yet submitted to kernel) |
nb_to_read | Number of message already read by the kernel, waiting in the local message list |
Definition at line 2825 of file n_network.c.
References __n_assert.
int netw_get_state | ( | NETWORK * | netw, |
int * | state, | ||
int * | thr_engine_status | ||
) |
Get the state of a network.
netw | The NETWORK *connection to query |
state | pointer to network status storage , NETW_RUN , NETW_EXIT_ASKED , NETW_EXITED |
thr_engine_status | pointer to network thread engine status storage ,NETW_THR_ENGINE_STARTED , NETW_THR_ENGINE_STOPPED |
Definition at line 1376 of file n_network.c.
References LOG_ERR, and n_log.
Referenced by manage_client(), netw_close(), netw_recv_func(), netw_send_func(), netw_stop_thr_engine(), netw_wait_close_timed(), and netw_wait_msg().
int netw_init_wsa | ( | int | mode, |
int | v1, | ||
int | v2 | ||
) |
Do not directly use, internal api.
Initialize winsock dll loading on windows if needed.
mode | 1 for opening 0 for close 2 for status |
v1 | First digit of version requested |
v2 | Second digit of version requested |
Definition at line 719 of file n_network.c.
Referenced by netw_accept_from_ex(), netw_connect_ex(), and netw_make_listening().
int netw_make_listening | ( | NETWORK ** | netw, |
char * | addr, | ||
char * | port, | ||
int | nbpending, | ||
int | ip_version | ||
) |
Make a NETWORK be a Listening network.
netw | A NETWORK **network to make listening |
addr | Adress to bind, NULL for automatic address filling |
port | For choosing a PORT to listen to |
nbpending | Number of pending connection when listening |
ip_version | NETWORK_IPALL for both ipv4 and ipv6 , NETWORK_IPV4 or NETWORK_IPV6 |
Definition at line 1665 of file n_network.c.
References __n_assert, _str, FreeNoLog, get_in_addr(), LOG_ERR, Malloc, n_log, neterrno, netstrerror, netw_close(), netw_init_wsa(), netw_new(), netw_set(), netw_setsockopt(), NETWORK_IPV4, and NETWORK_IPV6.
NETWORK_POOL * netw_new_pool | ( | int | nb_min_element | ) |
return a new network pool of nb_min_element
nb_min_element | size of internal hash table for network pool |
Definition at line 2847 of file n_network.c.
References __n_assert, Free, init_lock, Malloc, and new_ht().
int netw_pool_add | ( | NETWORK_POOL * | netw_pool, |
NETWORK * | netw | ||
) |
add a NETWORK *netw to a NETWORK_POOL *pool
netw_pool | targeted network pool |
netw | network to add |
Definition at line 2907 of file n_network.c.
References __n_assert, _nstr, free_nstr, ht_get_ptr(), ht_put_ptr(), list_push(), LOG_DEBUG, LOG_ERR, n_log, netw_pool_netw_close(), nstrprintf, unlock, and write_lock.
int netw_pool_broadcast | ( | NETWORK_POOL * | netw_pool, |
NETWORK * | from, | ||
N_STR * | net_msg | ||
) |
add net_msg to all network in netork pool
netw_pool | targeted network pool |
from | source network |
net_msg | mesage to broadcast |
Definition at line 3001 of file n_network.c.
References __n_assert, hash_val, ht_foreach, netw_add_msg(), nstrdup(), read_lock, and unlock.
int netw_pool_nbclients | ( | NETWORK_POOL * | netw_pool | ) |
return the number of networks in netw_pool
netw_pool | targeted network pool |
Definition at line 3032 of file n_network.c.
References __n_assert, read_lock, and unlock.
void netw_pool_netw_close | ( | void * | netw_ptr | ) |
close a network from a network pool
netw_ptr | NETWORK *network pointer |
Definition at line 2891 of file n_network.c.
References __n_assert, LOG_DEBUG, and n_log.
Referenced by netw_pool_add().
int netw_pool_remove | ( | NETWORK_POOL * | netw_pool, |
NETWORK * | netw | ||
) |
remove a NETWORK *netw to a NETWORK_POOL *pool
netw_pool | targeted network pool |
netw | network to remove |
Definition at line 2960 of file n_network.c.
References __n_assert, _nstr, free_nstr, ht_remove(), list_search(), LOG_DEBUG, LOG_ERR, n_log, nstrprintf, remove_list_node, unlock, and write_lock.
Referenced by netw_close().
void * netw_recv_func | ( | void * | NET | ) |
To Thread Receiving function.
NET | the NETWORK connection to use |
Definition at line 2296 of file n_network.c.
References __n_assert, _str, free_nstr_ptr(), list_push(), LOG_DEBUG, LOG_ERR, Malloc, n_log, netw_get_state(), netw_set(), and NETWORK::recv_data.
Referenced by netw_start_thr_engine().
void * netw_send_func | ( | void * | NET | ) |
Thread send function.
NET | the NETWORK connection to use, casted into (void*) |
Definition at line 2166 of file n_network.c.
References __n_assert, _str, free_nstr, list_shift, LOG_DEBUG, LOG_ERR, n_log, netw_get_state(), netw_set(), NETWORK::send_data, and u_sleep().
Referenced by netw_start_thr_engine().
Add a formatted NETWMSG_IDENT message to the specified network.
netw | The aimed NETWORK where we want to add something to send |
type | type of identification ( NETW_IDENT_REQUEST , NETW_IDENT_NEW ) |
id | The ID of the sending client |
name | Username |
passwd | Password |
Definition at line 3092 of file n_network.c.
References __n_assert, netmsg_make_ident(), and netw_add_msg().
int netw_send_ping | ( | NETWORK * | netw, |
int | type, | ||
int | id_from, | ||
int | id_to, | ||
int | time | ||
) |
Add a ping reply to the network.
netw | The aimed NETWORK where we want to add something to send |
id_from | Identifiant of the sender |
id_to | Identifiant of the destination, -1 if the serveur itslef is targetted |
time | The time it was when the ping was sended |
type | NETW_PING_REQUEST or NETW_PING_REPLY |
Definition at line 3070 of file n_network.c.
References __n_assert, netmsg_make_ping(), and netw_add_msg().
int netw_send_position | ( | NETWORK * | netw, |
int | id, | ||
double | X, | ||
double | Y, | ||
double | vx, | ||
double | vy, | ||
double | acc_x, | ||
double | acc_y, | ||
int | time_stamp | ||
) |
Add a formatted NETWMSG_IDENT message to the specified network.
netw | The aimed NETWORK where we want to add something to send |
id | The ID of the sending client |
X | X position inside a big grid |
Y | Y position inside a big grid |
vx | X speed |
vy | Y speed |
acc_x | Y acceleration |
acc_y | X acceleration |
time_stamp | Current Time when sending (for some delta we would want to compute ) |
Definition at line 3119 of file n_network.c.
References __n_assert, netmsg_make_position_msg(), and netw_add_msg().
int netw_send_quit | ( | NETWORK * | netw | ) |
Add a formatted NETMSG_QUIT message to the specified network.
netw | The aimed NETWORK |
Definition at line 3186 of file n_network.c.
References __n_assert, netmsg_make_quit_msg(), and netw_add_msg().
int netw_send_string_to | ( | NETWORK * | netw, |
int | id_to, | ||
N_STR * | name, | ||
N_STR * | chan, | ||
N_STR * | txt, | ||
int | color | ||
) |
Add a string to the network, aiming a specific user.
netw | The aimed NETWORK where we want to add something to send |
id_to | The ID of the targetted client |
name | Sender Name |
chan | channel to use |
txt | Sender text |
color | Sender text color |
Definition at line 3144 of file n_network.c.
References __n_assert, netmsg_make_string_msg(), and netw_add_msg().
Add a string to the network, aiming all server-side users.
netw | The aimed NETWORK where we want to add something to send |
name | Name of user |
chan | Target Channel, if any. Pass "ALL" to target the default channel |
txt | The text to send |
color | The color of the text |
Definition at line 3167 of file n_network.c.
References __n_assert, netmsg_make_string_msg(), and netw_add_msg().
int netw_set | ( | NETWORK * | netw, |
int | flag | ||
) |
Restart or reset the specified network ability.
netw | The NETWORK *connection to modify |
flag | NETW_EMPTY_SENDBUF, NETW_EMPTY_RECVBUF, NETW_RUN , NETW_EXIT_ASKED , NETW_EXITED |
Definition at line 1403 of file n_network.c.
References list_destroy(), and list_empty().
Referenced by netw_accept_from_ex(), netw_close(), netw_connect_ex(), netw_make_listening(), netw_recv_func(), netw_send_func(), and netw_stop_thr_engine().
int netw_set_blocking | ( | NETWORK * | netw, |
unsigned long int | is_blocking | ||
) |
Modify blocking socket mode.
netw | The network to configure |
is_blocking | 0 NON BLOCk , 1 BLOCK |
Definition at line 773 of file n_network.c.
References __n_assert, _str, FreeNoLog, LOG_DEBUG, LOG_ERR, n_log, neterrno, netstrerror, and netw_close().
Referenced by netw_accept_from_ex().
int netw_set_user_id | ( | NETWORK * | netw, |
int | id | ||
) |
associate an id and a network
netw | targeted network |
id | id we want to associated with |
Definition at line 3052 of file n_network.c.
References __n_assert.
int netw_setsockopt | ( | NETWORK * | netw, |
int | optname, | ||
int | value | ||
) |
Modify common socket options on the given netw.
netw | The socket to configure |
optname | NETWORK_DEPLETE_TIMEOUT,NETWORK_CONSECUTIVE_SEND_TIMEOUT ,SO_REUSEADDR,TCP_NODELAY,SO_SNDBUF,SO_RCVBUF,SO_LINGER,SO_RCVTIMEO,SO_SNDTIMEO. Please refer to man setsockopt for details |
value | The value of the socket parameter |
Definition at line 830 of file n_network.c.
References __n_assert, _str, FreeNoLog, LOG_ERR, n_log, neterrno, netstrerror, NETWORK_CONSECUTIVE_SEND_TIMEOUT, and NETWORK_DEPLETE_TIMEOUT.
Referenced by netw_accept_from_ex(), and netw_make_listening().
int netw_start_thr_engine | ( | NETWORK * | netw | ) |
Start the NETWORK netw Threaded Engine.
Create a sending & receiving thread.
netw | The aimed NETWORK connection to start receiving data |
Definition at line 2125 of file n_network.c.
References __n_assert, _str, LOG_ERR, n_log, netw_recv_func(), and netw_send_func().
Referenced by manage_client().
int netw_stop_thr_engine | ( | NETWORK * | netw | ) |
Stop a NETWORK connection sending and receing thread.
netw | The aimed NETWORK conection to stop |
Definition at line 2446 of file n_network.c.
References __n_assert, LOG_DEBUG, LOG_ERR, n_log, netw_get_state(), and netw_set().
Referenced by netw_close().
int netw_wait_close | ( | NETWORK ** | netw | ) |
Wait for peer closing a specified Network, destroy queues, free the structure.
Default 30 seconds timeout
netw | A NETWORK *network to close |
Definition at line 1574 of file n_network.c.
References netw_wait_close_timed().
Referenced by manage_client().
int netw_wait_close_timed | ( | NETWORK ** | netw, |
size_t | timeout | ||
) |
Wait for peer closing a specified Network, destroy queues, free the structure.
netw | A NETWORK *network to close |
timeout | timeout in seconds before force close engine , 0 to instantly close (not recommanded) |
Definition at line 1589 of file n_network.c.
References __n_assert, _str, deplete_send_buffer(), FreeNoLog, LOG_ERR, N_ENUM_ENTRY, n_log, neterrno, netstrerror, netw_close(), and netw_get_state().
Referenced by netw_wait_close().
Wait a message from aimed NETWORK.
Recheck each usec until a valid
netw | The link on which we wait a message |
refresh | The time in usec between each check until there is a message |
timeout | in usecs , maximum amount of time to wait before return. 0 to disable. |
Definition at line 2068 of file n_network.c.
References __n_assert, LOG_ERR, N_ENUM_ENTRY, n_log, netw_get_msg(), netw_get_state(), and u_sleep().
recv data from the socket
s | connected socket |
buf | pointer to buffer |
n | number of characters we want |
Definition at line 2541 of file n_network.c.
References __n_assert, _str, CALL_RETRY, FreeNoLog, LOG_DEBUG, LOG_ERR, n_log, neterrno, and netstrerror.
Referenced by netw_new().
int recv_php | ( | SOCKET | s, |
int * | _code, | ||
char ** | buf | ||
) |
send data onto the socket
s | connected socket |
buf | pointer to buffer |
n | number of characters we want to send |
Definition at line 2489 of file n_network.c.
References __n_assert, _str, FreeNoLog, LOG_DEBUG, LOG_ERR, n_log, neterrno, and netstrerror.
Referenced by netw_new().
int send_php | ( | SOCKET | s, |
int | _code, | ||
char * | buf, | ||
int | n | ||
) |
send data onto the socket
s | connected socket |
buf | pointer to buffer |
n | number of characters we want to send |
_code | Code for php decoding rule |
Definition at line 2596 of file n_network.c.
References _str, CALL_RETRY, FreeNoLog, HEAD_CODE, HEAD_SIZE, LOG_ERR, n_log, neterrno, and netstrerror.