26void sigchld_handler(
int sig )
29 int saved_errno = errno;
31 while(waitpid(-1, NULL, WNOHANG) > 0);
51 N_STR *tmpstr = NULL ;
52 N_STR *hostname = NULL ;
58 if( gethostname( hostname -> data, hostname -> length ) != 0 )
60 n_log(
LOG_ERR,
"Coudldn't resolve hostname. Error:%s", strerror( errno ) );
64 hostname -> written = strlen( hostname -> data );
74 for(
int i = 0 ; i < 10 ; i ++ )
76 int val = ( rand()%20 ) - 10 ;
119 for(
int i = 0 ; i < 10 ; i ++ )
142 N_STR *netw_exchange = NULL ;
143 int state = 0, thr_engine_state = 0 ;
145 n_log(
LOG_NOTICE,
"manage_client started for netw %d", netw -> link . sock );
153 N_STR *hostname = NULL, *data = NULL ;
160 if( hostname && hostname -> data && data && data -> data )
162 n_log(
LOG_NOTICE,
"RECV: %s: %s , %s", netw -> link . ip, hostname -> data, data -> data );
187 if( (state&NETW_EXITED) || (state&NETW_ERROR ) || (state&NETW_EXIT_ASKED) )
191 SOCKET sockid = netw -> link . sock ;
void * manage_client(void *ptr)
recv/send datas if any for the client
#define NETMSG_DATA
type of data message
int get_net_datas(N_STR *str, N_STR **hostname, N_STR **data)
decode data we got from network
int send_net_datas(NETWORK *netw, N_STR *data)
send data to specified network
#define __n_assert(__ptr, __ret)
macro to assert things
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
#define LOG_NOTICE
normal but significant condition
#define free_nstr(__ptr)
free a N_STR structure and set the pointer to NULL
N_STR * new_nstr(NSTRBYTE size)
create a new N_STR string
A box including a string and his lenght.
void u_sleep(unsigned int usec)
wrapper around usleep for API consistency
NETW_MSG * make_msg_from_str(N_STR *str)
Make a single message of the string.
N_STR * make_str_from_msg(NETW_MSG *msg)
Make a single string of the message.
int add_nstrptr_to_msg(NETW_MSG *msg, N_STR *str)
Add a string to the string list in the message.
int create_msg(NETW_MSG **msg)
Create a NETW_MSG *object.
int netw_msg_get_type(N_STR *msg)
Get the type of message without killing the first number. Use with netw_get_XXX.
int get_nstr_from_msg(NETW_MSG *msg, N_STR **value)
Get a string from a message string list.
int add_nstrdup_to_msg(NETW_MSG *msg, N_STR *str)
Add a copy of str to the string list in the message.
int add_int_to_msg(NETW_MSG *msg, int value)
Add an int to the int list int the message.
int delete_msg(NETW_MSG **msg)
Delete a NETW_MSG *object.
int get_int_from_msg(NETW_MSG *msg, int *value)
Get a number from a message number list.
network message, array of char and int
N_STR * netw_get_msg(NETWORK *netw)
Get a message from aimed NETWORK.
int netw_add_msg(NETWORK *netw, N_STR *msg)
Add a message to send in aimed NETWORK.
int netw_start_thr_engine(NETWORK *netw)
Start the NETWORK netw Threaded Engine.
int netw_wait_close(NETWORK **netw)
Wait for peer closing a specified Network, destroy queues, free the structure.
int netw_get_state(NETWORK *netw, int *state, int *thr_engine_status)
Get the state of a network.
#define SOCKET
socket macro shortcut
Common headers and low-level hugly functions & define.
Network messages , serialization tools.