Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ex_gui_network.c
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
42#define WIDTH 800
43#define HEIGHT 600
44
45#define ALLEGRO_UNSTABLE 1
46
47#include <getopt.h>
48#include <sys/time.h>
49#include <sys/types.h>
50
51#include "nilorea/n_common.h"
52#include "nilorea/n_log.h"
53#include "nilorea/n_str.h"
54#include "nilorea/n_time.h"
55#include "nilorea/n_network.h"
57#include "nilorea/n_gui.h"
58
59/* custom message type for chat text */
60#define NETMSG_CHAT 100
61
62ALLEGRO_DISPLAY* display = NULL;
63
64static int DONE = 0;
65static int mode = -1; /* 0 = server, 1 = client */
66static char* server_addr = NULL;
67static char* port_str = NULL;
68
69/* networking */
70static NETWORK* netw_server = NULL;
71static NETWORK* netw_client = NULL;
72static NETWORK_POOL* pool = NULL;
73
74/* gui widget ids */
75static int win_chat = -1;
76static int lbl_status = -1;
77static int listbox_log = -1;
78static int textarea_input = -1;
79static int btn_send = -1;
80
81/* server-only gui widget ids */
82static int win_clients = -1;
83static int lbl_clients_header = -1;
84static int listbox_clients = -1;
85
86static N_GUI_CTX* gui = NULL;
87
92void chat_log_add(const char* text) {
93 if (gui && listbox_log >= 0) {
95 }
96}
97
102 if (!gui || listbox_clients < 0 || !pool) return;
103
105
106 HT_FOREACH(node, pool->pool, {
107 NETWORK* cn = (NETWORK*)node->data.ptr;
108 if (cn) {
109 char entry[256] = "";
110 snprintf(entry, sizeof(entry), "%s:%s (sock %d)",
111 cn->link.ip ? cn->link.ip : "?",
112 cn->link.port ? cn->link.port : "?",
113 (int)cn->link.sock);
114 n_gui_listbox_add_item(gui, listbox_clients, entry);
115 }
116 });
117
118 char header[64] = "";
119 snprintf(header, sizeof(header), "Connected clients: %zu", netw_pool_nbclients(pool));
120 if (lbl_clients_header >= 0) {
122 }
123}
124
130N_STR* build_chat_msg(const char* text) {
131 NETW_MSG* msg = NULL;
132 create_msg(&msg);
133 if (!msg) return NULL;
134
136 add_strdup_to_msg(msg, text);
137
138 N_STR* str = make_str_from_msg(msg);
139 delete_msg(&msg);
140 return str;
141}
142
149int decode_chat_msg(N_STR* str, char** out_text) {
150 NETW_MSG* msg = NULL;
151 int type = 0;
152 int ok = FALSE;
153
154 if (out_text) {
155 *out_text = NULL;
156 }
157
158 msg = make_msg_from_str(str);
159 if (!msg) {
160 return FALSE;
161 }
162
163 if (!get_int_from_msg(msg, &type)) {
164 delete_msg(&msg);
165 return FALSE;
166 }
167
168 if (type != NETMSG_CHAT) {
169 delete_msg(&msg);
170 return FALSE;
171 }
172
173 ok = get_str_from_msg(msg, out_text);
174 if (!ok && out_text) {
175 *out_text = NULL;
176 }
177
178 delete_msg(&msg);
179 return ok;
180}
181
187void on_send_click(int widget_id, void* user_data) {
188 (void)widget_id;
189 (void)user_data;
190
191 const char* text = n_gui_textarea_get_text(gui, textarea_input);
192 if (!text || text[0] == '\0') return;
193
194 N_STR* msg_str = build_chat_msg(text);
195 if (!msg_str) return;
196
197 if (mode == 0 && pool) {
198 /* server: broadcast to all clients */
199 netw_pool_broadcast(pool, NULL, msg_str);
200 char logbuf[512] = "";
201 snprintf(logbuf, sizeof(logbuf), "[server] %s", text);
202 chat_log_add(logbuf);
203 } else if (mode == 1 && netw_client) {
204 N_STR* copy = nstrdup(msg_str);
205 if (!netw_add_msg(netw_client, copy)) {
206 /* netw_add_msg did not take ownership of 'copy' on failure */
207 free_nstr(&copy);
208 }
209 char logbuf[512] = "";
210 snprintf(logbuf, sizeof(logbuf), "[me] %s", text);
211 chat_log_add(logbuf);
212 }
213 free_nstr(&msg_str);
215}
216
222void poll_network_msgs(NETWORK* netw, const char* prefix) {
223 if (!netw) return;
224 N_STR* incoming = NULL;
225 while ((incoming = netw_get_msg(netw)) != NULL) {
226 char* text = NULL;
227 if (decode_chat_msg(incoming, &text) == TRUE && text) {
228 char logbuf[512] = "";
229 snprintf(logbuf, sizeof(logbuf), "[%s] %s", prefix, text);
230 chat_log_add(logbuf);
231
232 /* server: relay to all other clients */
233 if (mode == 0 && pool) {
234 N_STR* relay = build_chat_msg(text);
235 if (relay) {
237 free_nstr(&relay);
238 }
239 }
240 Free(text);
241 }
242 free_nstr(&incoming);
243 }
244}
245
246void usage(void) {
247 fprintf(stderr,
248 "Usage:\n"
249 " Server: ex_gui_network -p PORT\n"
250 " Client: ex_gui_network -s ADDRESS -p PORT\n"
251 " Options:\n"
252 " -s addr : server address to connect to (client mode)\n"
253 " -p port : port number\n"
254 " -V level : log level (LOG_DEBUG, LOG_INFO, LOG_ERR)\n"
255 " -h : help\n");
256}
257
258int main(int argc, char** argv) {
259 int log_level = LOG_ERR;
260 int getoptret = 0;
261
262 while ((getoptret = getopt(argc, argv, "hs:p:V:")) != EOF) {
263 switch (getoptret) {
264 case 's':
265 server_addr = strdup(optarg);
266 break;
267 case 'p':
268 port_str = strdup(optarg);
269 break;
270 case 'V':
271 if (!strcmp("LOG_DEBUG", optarg))
273 else if (!strcmp("LOG_INFO", optarg))
275 else if (!strcmp("LOG_NOTICE", optarg))
277 else if (!strcmp("LOG_ERR", optarg))
279 break;
280 default:
281 case 'h':
282 usage();
283 exit(1);
284 }
285 }
287
288 if (!port_str) {
289 fprintf(stderr, "Port is required. Use -p PORT\n");
290 usage();
291 exit(1);
292 }
293
294 mode = server_addr ? 1 : 0;
295
296 /* allegro init */
297 if (!al_init()) {
298 n_log(LOG_ERR, "al_init failed");
299 return 1;
300 }
301 al_install_keyboard();
302 al_install_mouse();
303 al_init_primitives_addon();
304 al_init_font_addon();
305 al_init_ttf_addon();
306 al_init_image_addon();
307
308 al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_WINDOWED);
309 display = al_create_display(WIDTH, HEIGHT);
310 if (!display) {
311 n_log(LOG_ERR, "Failed to create display");
312 return 1;
313 }
314 al_set_window_title(display, mode == 0 ? "GUI Network - Server" : "GUI Network - Client");
315
316 ALLEGRO_FONT* font = al_create_builtin_font();
317 ALLEGRO_EVENT_QUEUE* event_queue = al_create_event_queue();
318 ALLEGRO_TIMER* timer = al_create_timer(1.0 / 30.0);
319
320 al_register_event_source(event_queue, al_get_display_event_source(display));
321 al_register_event_source(event_queue, al_get_keyboard_event_source());
322 al_register_event_source(event_queue, al_get_mouse_event_source());
323 al_register_event_source(event_queue, al_get_timer_event_source(timer));
324
325 /* create GUI */
326 gui = n_gui_new_ctx(font);
327 n_gui_set_display_size(gui, (float)WIDTH, (float)HEIGHT);
328
329 /* main chat window */
330 win_chat = n_gui_add_window(gui, mode == 0 ? "Chat Server" : "Chat Client", 10, 10, 780, 580);
332
333 /* status label */
334 lbl_status = n_gui_add_label(gui, win_chat, mode == 0 ? "Server: waiting..." : "Client: connecting...",
335 10, 10, 760, 20, N_GUI_ALIGN_LEFT);
336
337 /* chat log listbox */
338 listbox_log = n_gui_add_listbox(gui, win_chat, 10, 40, 760, 420, N_GUI_SELECT_NONE, NULL, NULL);
339
340 /* input textarea */
341 textarea_input = n_gui_add_textarea(gui, win_chat, 10, 470, 660, 30, 0, 256, NULL, NULL);
342
343 /* send button bound to Enter key (works even while typing in the single-line text input) */
344 btn_send = n_gui_add_button(gui, win_chat, "Send", 680, 470, 90, 30, N_GUI_SHAPE_ROUNDED, on_send_click, NULL);
345 n_gui_button_set_keycode(gui, btn_send, ALLEGRO_KEY_ENTER, 0);
346
347 /* server: connected clients window */
348 if (mode == 0) {
349 win_clients = n_gui_add_window(gui, "Connected Clients", 800, 10, 290, 580);
351
352 lbl_clients_header = n_gui_add_label(gui, win_clients, "Connected clients: 0",
353 10, 10, 270, 20, N_GUI_ALIGN_LEFT);
354
355 listbox_clients = n_gui_add_listbox(gui, win_clients, 10, 40, 270, 500, N_GUI_SELECT_NONE, NULL, NULL);
356 }
357
358 /* network setup */
359 int net_ok = FALSE;
360 if (mode == 0) {
361 /* server */
362 pool = netw_new_pool(128);
363 if (!pool) {
364 n_gui_label_set_text(gui, lbl_status, "Server: memory allocation failed");
365 chat_log_add("Failed to allocate server connection pool");
366 } else if (netw_make_listening(&netw_server, NULL, port_str, 10, NETWORK_IPALL) == TRUE) {
368 net_ok = TRUE;
369 char buf[128] = "";
370 snprintf(buf, sizeof(buf), "Server listening on port %s", port_str);
372 chat_log_add(buf);
373 } else {
374 n_gui_label_set_text(gui, lbl_status, "Server: bind failed");
375 chat_log_add("Failed to bind server socket");
376 }
377 } else {
378 /* client */
381 net_ok = TRUE;
382 char buf[128] = "";
383 snprintf(buf, sizeof(buf), "Connected to %s:%s", server_addr, port_str);
385 chat_log_add(buf);
386 } else {
387 n_gui_label_set_text(gui, lbl_status, "Client: connection failed");
388 chat_log_add("Failed to connect to server");
389 }
390 }
391
392 al_start_timer(timer);
393 int redraw = 1;
394
395 while (!DONE) {
396 ALLEGRO_EVENT ev;
397 al_wait_for_event(event_queue, &ev);
398
399 if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
400 DONE = 1;
401 continue;
402 }
403 if (ev.type == ALLEGRO_EVENT_KEY_DOWN && ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
404 DONE = 1;
405 continue;
406 }
407 if (ev.type == ALLEGRO_EVENT_TIMER) {
408 redraw = 1;
409
410 /* server: accept new connections */
411 if (mode == 0 && net_ok && netw_server) {
412 int retval = 0;
413 NETWORK* new_client = netw_accept_from_ex(netw_server, 0, 0, -1, &retval);
414 if (new_client) {
415 netw_start_thr_engine(new_client);
416 if (netw_pool_add(pool, new_client) != TRUE) {
417 /* Failed to track this client in the pool: close it to avoid leaks */
418 chat_log_add("Failed to add new client to pool, closing connection");
419 netw_close(&new_client);
420 } else {
421 char buf[128] = "";
422 snprintf(buf, sizeof(buf), "Client connected from %s (total: %zu)",
423 new_client->link.ip ? new_client->link.ip : "?",
425 chat_log_add(buf);
428 }
429 }
430 }
431
432 /* poll messages */
433 if (mode == 0 && pool) {
434 /* server: poll each client in pool */
435 LIST* dead_clients = new_generic_list(MAX_LIST_ITEMS);
436 if (!dead_clients) {
437 n_log(LOG_ERR, "Could not allocate dead_clients list");
438 } else {
439 HT_FOREACH(node, pool->pool, {
440 NETWORK* cn = (NETWORK*)node->data.ptr;
441 if (cn) {
442 uint32_t state = 0;
443 int thr_state = 0;
444 netw_get_state(cn, &state, &thr_state);
445 if (state & NETW_EXITED || state & NETW_ERROR || state & NETW_EXIT_ASKED) {
446 list_push(dead_clients, cn, NULL);
447 } else {
448 poll_network_msgs(cn, cn->link.ip ? cn->link.ip : "client");
449 }
450 }
451 });
452 /* remove and close dead connections outside of the iteration */
453 int had_dead = 0;
454 list_foreach(dead_node, dead_clients) {
455 NETWORK* cn = (NETWORK*)dead_node->ptr;
456 char disc_buf[128] = "";
457 snprintf(disc_buf, sizeof(disc_buf), "Client %s:%s disconnected",
458 cn->link.ip ? cn->link.ip : "?",
459 cn->link.port ? cn->link.port : "?");
460 chat_log_add(disc_buf);
462 netw_close(&cn);
463 had_dead = 1;
464 }
465 if (had_dead) {
467 char sbuf[64] = "";
468 snprintf(sbuf, sizeof(sbuf), "Connected clients: %zu", netw_pool_nbclients(pool));
470 }
471 list_destroy(&dead_clients);
472 }
473 } else if (mode == 1 && netw_client) {
475 /* check connection status */
476 uint32_t state = 0;
477 int thr_state = 0;
478 netw_get_state(netw_client, &state, &thr_state);
479 if (state & NETW_EXITED || state & NETW_ERROR) {
480 n_gui_label_set_text(gui, lbl_status, "Disconnected from server");
481 chat_log_add("Disconnected from server");
483 }
484 }
485 }
486
488
489 if (redraw && al_is_event_queue_empty(event_queue)) {
490 redraw = 0;
491 al_clear_to_color(al_map_rgb(40, 40, 50));
493 al_flip_display();
494 }
495 }
496
497 /* cleanup */
498 if (netw_client) {
500 }
501 if (pool) {
502 /* netw_destroy_pool() does not close NETWORK objects; its internal
503 * destroy callback only logs. Collect all pool clients first, then
504 * close each one (netw_close also removes the client from the pool
505 * via netw_pool_remove), and finally destroy the now-empty pool. */
506 LIST* clients_to_close = new_generic_list(UNLIMITED_LIST_ITEMS);
507 if (clients_to_close) {
508 HT_FOREACH(node, pool->pool, {
509 NETWORK* cn = (NETWORK*)node->data.ptr;
510 if (cn) {
511 list_push(clients_to_close, cn, NULL);
512 }
513 });
514 list_foreach(cnode, clients_to_close) {
515 NETWORK* cn = (NETWORK*)cnode->ptr;
516 netw_close(&cn);
517 }
518 list_destroy(&clients_to_close);
519 } else {
520 n_log(LOG_ERR, "failed to allocate client list for pool cleanup; pool clients may leak");
521 }
523 }
524 if (netw_server) {
526 }
527 netw_unload();
528
530 al_destroy_font(font);
531 al_destroy_timer(timer);
532 al_destroy_event_queue(event_queue);
533 al_destroy_display(display);
534
537
538 return 0;
539}
static void usage(void)
int main(void)
int getoptret
Definition ex_fluid.c:60
int DONE
Definition ex_fluid.c:59
int log_level
Definition ex_fluid.c:61
ALLEGRO_DISPLAY * display
Definition ex_fluid.c:53
#define WIDTH
Definition ex_gui.c:36
static int lbl_status
Definition ex_gui.c:64
#define HEIGHT
Definition ex_gui.c:37
N_STR * build_chat_msg(const char *text)
build a chat network message
static NETWORK * netw_server
static int mode
static int textarea_input
static N_GUI_CTX * gui
static int win_clients
void poll_network_msgs(NETWORK *netw, const char *prefix)
process incoming messages on a single network connection
void refresh_clients_list(void)
refresh the connected clients listbox (server only)
#define NETMSG_CHAT
static int win_chat
static int listbox_log
static char * server_addr
static int lbl_clients_header
void on_send_click(int widget_id, void *user_data)
send button callback
static NETWORK * netw_client
static char * port_str
void chat_log_add(const char *text)
add a line to the chat log listbox
static int listbox_clients
static int btn_send
static NETWORK_POOL * pool
int decode_chat_msg(N_STR *str, char **out_text)
decode a received chat message
NETWORK * netw
Network for server mode, accepting incomming.
Definition ex_network.c:38
#define FreeNoLog(__ptr)
Free Handler without log.
Definition n_common.h:271
#define Free(__ptr)
Free Handler to get errors.
Definition n_common.h:262
void n_gui_set_display_size(N_GUI_CTX *ctx, float w, float h)
Set the display (viewport) size for global scrollbar computation.
Definition n_gui.c:5176
#define N_GUI_ALIGN_LEFT
left aligned text
Definition n_gui.h:156
void n_gui_textarea_set_text(N_GUI_CTX *ctx, int widget_id, const char *text)
set the text content of a textarea widget
Definition n_gui.c:1752
void n_gui_label_set_text(N_GUI_CTX *ctx, int widget_id, const char *text)
set the text of a label widget
Definition n_gui.c:2178
int n_gui_add_listbox(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, int selection_mode, void(*on_select)(int, int, int, void *), void *user_data)
Add a listbox widget.
Definition n_gui.c:1336
int n_gui_process_event(N_GUI_CTX *ctx, ALLEGRO_EVENT event)
Process an allegro event through the GUI system.
Definition n_gui.c:5767
int n_gui_add_label(N_GUI_CTX *ctx, int window_id, const char *text, float x, float y, float w, float h, int align)
Add a static text label.
Definition n_gui.c:1497
#define N_GUI_WIN_FIXED_POSITION
disable window dragging (default:enable)
Definition n_gui.h:196
#define N_GUI_SELECT_NONE
no selection allowed (display only)
Definition n_gui.h:140
int n_gui_listbox_add_item(N_GUI_CTX *ctx, int widget_id, const char *text)
add an item to a listbox widget
Definition n_gui.c:1860
void n_gui_draw(N_GUI_CTX *ctx)
Draw all visible windows and their widgets.
Definition n_gui.c:4800
void n_gui_button_set_keycode(N_GUI_CTX *ctx, int widget_id, int keycode, int modifiers)
Bind a keyboard key with optional modifier requirements to a button.
Definition n_gui.c:1129
int n_gui_add_window(N_GUI_CTX *ctx, const char *title, float x, float y, float w, float h)
Add a new pseudo-window to the context.
Definition n_gui.c:581
N_GUI_CTX * n_gui_new_ctx(ALLEGRO_FONT *default_font)
Create a new GUI context.
Definition n_gui.c:466
void n_gui_listbox_clear(N_GUI_CTX *ctx, int widget_id)
remove all items from a listbox widget
Definition n_gui.c:1907
void n_gui_destroy_ctx(N_GUI_CTX **ctx)
Destroy a GUI context and all its windows/widgets.
Definition n_gui.c:523
const char * n_gui_textarea_get_text(N_GUI_CTX *ctx, int widget_id)
get the text content of a textarea widget
Definition n_gui.c:1738
#define N_GUI_SHAPE_ROUNDED
rounded rectangle shape
Definition n_gui.h:116
void n_gui_window_set_flags(N_GUI_CTX *ctx, int window_id, int flags)
Set feature flags on a window.
Definition n_gui.c:843
int n_gui_add_textarea(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, int multiline, size_t char_limit, void(*on_change)(int, const char *, void *), void *user_data)
Add a text area widget.
Definition n_gui.c:1214
int n_gui_add_button(N_GUI_CTX *ctx, int window_id, const char *label, float x, float y, float w, float h, int shape, void(*on_click)(int, void *), void *user_data)
Add a button widget to a window.
Definition n_gui.c:1001
#define N_GUI_WIN_RESIZABLE
enable user-resizable window with a drag handle at bottom-right
Definition n_gui.h:194
The top-level GUI context that holds all windows.
Definition n_gui.h:882
#define HT_FOREACH(__ITEM_, __HASH_,...)
ForEach macro helper.
Definition n_hash.h:215
#define UNLIMITED_LIST_ITEMS
flag to pass to new_generic_list for an unlimited number of item in the list.
Definition n_list.h:72
#define list_foreach(__ITEM_, __LIST_)
ForEach macro helper, safe for node removal during iteration.
Definition n_list.h:88
int list_destroy(LIST **list)
Empty and Free a list container.
Definition n_list.c:547
LIST * new_generic_list(size_t max_items)
Initialiaze a generic list container to max_items pointers.
Definition n_list.c:36
#define MAX_LIST_ITEMS
flag to pass to new_generic_list for the maximum possible number of item in a list
Definition n_list.h:74
Structure of a generic LIST container.
Definition n_list.h:58
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
Definition n_log.h:88
#define LOG_DEBUG
debug-level messages
Definition n_log.h:83
#define LOG_ERR
error conditions
Definition n_log.h:75
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
Definition n_log.c:120
#define LOG_NOTICE
normal but significant condition
Definition n_log.h:79
#define LOG_INFO
informational
Definition n_log.h:81
#define free_nstr(__ptr)
free a N_STR structure and set the pointer to NULL
Definition n_str.h:201
N_STR * nstrdup(N_STR *str)
Duplicate a N_STR.
Definition n_str.c:708
A box including a string and his lenght.
Definition n_str.h:60
int get_str_from_msg(NETW_MSG *msg, char **value)
Get a string from a message string list.
int add_strdup_to_msg(NETW_MSG *msg, const char *str)
Add a copy of char *str to the string list in the message.
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 create_msg(NETW_MSG **msg)
Create a NETW_MSG *object.
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 an int from a message int list.
network message, array of char and int
char * ip
ip of the connected socket
Definition n_network.h:244
N_SOCKET link
networking socket
Definition n_network.h:326
char * port
port of socket
Definition n_network.h:240
HASH_TABLE * pool
table of clients
Definition n_network.h:373
N_STR * netw_get_msg(NETWORK *netw)
Get a message from aimed NETWORK.
Definition n_network.c:2977
int netw_add_msg(NETWORK *netw, N_STR *msg)
Add a message to send in aimed NETWORK.
Definition n_network.c:2914
NETWORK_POOL * netw_new_pool(size_t nb_min_element)
return a new network pool of nb_min_element
Definition n_network.c:3861
int netw_make_listening(NETWORK **netw, char *addr, char *port, int nbpending, int ip_version)
Make a NETWORK be a Listening network.
Definition n_network.c:2240
int netw_start_thr_engine(NETWORK *netw)
Start the NETWORK netw Threaded Engine.
Definition n_network.c:3050
int netw_destroy_pool(NETWORK_POOL **netw_pool)
free a NETWORK_POOL *pool
Definition n_network.c:3880
size_t netw_pool_nbclients(NETWORK_POOL *netw_pool)
return the number of networks in netw_pool
Definition n_network.c:4019
NETWORK * netw_accept_from_ex(NETWORK *from, size_t send_list_limit, size_t recv_list_limit, int blocking, int *retval)
make a normal 'accept' .
Definition n_network.c:2713
#define NETWORK_IPALL
Flag for auto detection by OS of ip version to use.
Definition n_network.h:47
int netw_pool_broadcast(NETWORK_POOL *netw_pool, const NETWORK *from, N_STR *net_msg)
add net_msg to all network in netork pool
Definition n_network.c:3995
int netw_get_state(NETWORK *netw, uint32_t *state, int *thr_engine_status)
Get the state of a network.
Definition n_network.c:1924
int netw_close(NETWORK **netw)
Closing a specified Network, destroy queues, free the structure.
Definition n_network.c:2041
int netw_set_blocking(NETWORK *netw, unsigned long int is_blocking)
Modify blocking socket mode.
Definition n_network.c:871
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.
Definition n_network.c:1814
int netw_pool_add(NETWORK_POOL *netw_pool, NETWORK *netw)
add a NETWORK *netw to a NETWORK_POOL *pool
Definition n_network.c:3912
int netw_pool_remove(NETWORK_POOL *netw_pool, NETWORK *netw)
remove a NETWORK *netw to a NETWORK_POOL *pool
Definition n_network.c:3958
@ NETW_EXITED
Definition n_network.h:232
@ NETW_ERROR
Definition n_network.h:232
Structure of a NETWORK.
Definition n_network.h:258
structure of a network pool
Definition n_network.h:371
Common headers and low-level functions & define.
GUI system: buttons, sliders, text areas, checkboxes, scrollbars, dropdown menus, windows.
Generic log system.
Network Engine.
Network messages , serialization tools.
N_STR and string function declaration.
Timing utilities.