Nilorea Library n_network api test.
#define NETMSG_DATA 1
#include <getopt.h>
#include <sys/time.h>
#include <sys/types.h>
#ifndef __windows__
#include <sys/wait.h>
#endif
if (gethostname(hostname->
data, hostname->
length) != 0) {
n_log(
LOG_ERR,
"Coudldn't resolve hostname. Error:%s", strerror(errno));
return FALSE;
}
for (int i = 0; i < 10; i++) {
int val = (rand() % 20) - 10;
}
}
int type = 0;
return FALSE;
}
for (int i = 0; i < 10; i++) {
int val = 0;
}
return TRUE;
}
N_STR* netw_exchange = NULL;
uint32_t state = 0;
int thr_engine_state = 0;
N_STR *hostname = NULL, *data = NULL;
switch (type) {
if (hostname && hostname->
data && data && data->data) {
} else {
}
break;
default:
break;
}
if (data)
if (hostname)
if (netw_exchange)
} else {
}
}
return NULL;
}
NETWORK * netw
Network for server mode, accepting incomming.
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
size_t written
size of the written data inside the string
size_t length
length of string (in case we wanna keep information after the 0 end of string value)
#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
char * ip
ip of the connected socket
N_SOCKET link
networking socket
SOCKET sock
a normal socket
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 SOCKET
default socket declaration
int netw_get_state(NETWORK *netw, uint32_t *state, int *thr_engine_status)
Get the state of a network.
int netw_close(NETWORK **netw)
Closing a specified Network, destroy queues, free the structure.
Common headers and low-level functions & define.
Network messages , serialization tools.