![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
Data Structures | |
| struct | N_HTTP_REQUEST |
| parsed HTTP request for mock server callback More... | |
| struct | N_HTTP_RESPONSE |
| HTTP response to send from mock server callback. More... | |
| struct | N_MOCK_SERVER |
| mock HTTP server handle More... | |
| struct | N_PROXY_CFG |
| Parsed proxy URL components. More... | |
| struct | N_SOCKET |
| Structure of a N_SOCKET. More... | |
| struct | N_SSE_CONN |
| SSE connection handle. More... | |
| struct | N_SSE_EVENT |
| SSE event received from server. More... | |
| struct | N_URL |
| parsed URL components More... | |
| struct | N_URL_PARAM |
| a single query parameter key=value pair More... | |
| struct | N_WS_CONN |
| WebSocket connection. More... | |
| struct | N_WS_MESSAGE |
| WebSocket message. More... | |
| struct | NETWORK |
| Structure of a NETWORK. More... | |
| struct | NETWORK_HTTP_INFO |
| structure for splitting HTTP requests More... | |
| struct | NETWORK_POOL |
| structure of a network pool More... | |
Macros | |
| #define | _OPEN_SYS_SOCK_IPV6 1 |
| #define | HEAD_CODE 3 |
| Code of a HEAD message. | |
| #define | HEAD_SIZE 10 |
| Size of a HEAD message. | |
| #define | N_ENUM_netw_code_type(_) |
| Network codes definition. | |
| #define | N_URL_MAX_PARAMS 64 |
| maximum number of parsed query parameters | |
| #define | N_WS_OP_BINARY 0x02 |
| #define | N_WS_OP_CLOSE 0x08 |
| #define | N_WS_OP_PING 0x09 |
| #define | N_WS_OP_PONG 0x0A |
| #define | N_WS_OP_TEXT 0x01 |
| WebSocket opcodes per RFC 6455. | |
| #define | netw_atomic_read_state(netw) __atomic_load_n(&(netw)->state, __ATOMIC_ACQUIRE) |
| Lock-free atomic read of the network state field. | |
| #define | netw_atomic_write_state(netw, val) __atomic_store_n(&(netw)->state, (val), __ATOMIC_RELEASE) |
| Lock-free atomic write of the network state field. | |
| #define | NETW_MAX_RETRIES 8 |
| Send or recv max number of retries. | |
| #define | NETW_RETRY_DELAY 1000 |
| Send or recv delay between retries in usec. | |
| #define | NETW_SOCKET_DISCONNECTED -2 |
| Code for a disconnected recv. | |
| #define | NETW_SOCKET_ERROR -1 |
| code for a socket error | |
| #define | NETWORK_CONSECUTIVE_SEND_WAIT 2048 |
| Flag to set consecutive send waiting timeout | |
| #define | NETWORK_DEPLETE_QUEUES_TIMEOUT 1024 |
| Flag to set network queues depletion timeout | |
| #define | NETWORK_DEPLETE_SOCKET_TIMEOUT 512 |
| Flag to set send buffer depletion timeout | |
| #define | NETWORK_DISABLE_ZERO_LENGTH_RECV FALSE |
| Enable/disable recv of length 0. | |
| #define | NETWORK_IPALL 0 |
| Flag for auto detection by OS of ip version to use. | |
| #define | NETWORK_IPV4 1 |
| Flag to force IPV4 | |
| #define | NETWORK_IPV6 2 |
| Flag to force IPV6 | |
| #define | NETWORK_TCP 0 |
| Flag for TCP transport (default) | |
| #define | NETWORK_UDP 1 |
| Flag for UDP transport. | |
| #define | NETWORK_WAIT_CLOSE_TIMEOUT 4096 |
| Flag to set network closing wait timeout. | |
| #define | SOCKET_SIZE_FORMAT "%d" |
| socket associated printf style | |
Typedefs | |
| typedef ssize_t(* | netw_func) (void *, char *, uint32_t) |
| send/recv func ptr type | |
| typedef int | SOCKET |
| default socket declaration | |
Enumerations | |
| enum | __netw_code_type { NETW_CLIENT = 2 , NETW_SERVER = 4 , NETW_RESTART_TIMER = 8 , NETW_EMPTY_SENDBUF = 16 , NETW_EMPTY_RECVBUF = 32 , NETW_RUN = 64 , NETW_EXIT_ASKED = 128 , NETW_EXITED = 256 , NETW_ERROR = 512 , NETW_ENCRYPT_NONE = 1024 , NETW_ENCRYPT_OPENSSL = 2048 , NETW_THR_ENGINE_STARTED = 4096 , NETW_THR_ENGINE_STOPPED = 8192 , NETW_DESTROY_RECVBUF = 16384 , NETW_DESTROY_SENDBUF = 32768 , ____netw_code_type_UNKNOWN_VALUE__ } |
| Network codes declaration. More... | |
Functions | |
| int | deplete_send_buffer (int fd, int timeout) |
| wait for send buffer to be empty | |
| size_t | htonst (size_t value) |
| host to network size_t | |
| void | n_mock_server_free (N_MOCK_SERVER **server) |
| free a mock server and close the listening socket | |
| void | n_mock_server_run (N_MOCK_SERVER *server) |
| run the mock server accept loop (blocks until stop_flag is set) | |
| N_MOCK_SERVER * | n_mock_server_start (int port, void(*on_request)(N_HTTP_REQUEST *, N_HTTP_RESPONSE *, void *), void *user_data) |
| start a mock HTTP server on localhost:port (returns immediately) | |
| void | n_mock_server_stop (N_MOCK_SERVER *server) |
| signal the mock server to stop accepting connections | |
| void | n_netw_clear_connect_errors (void) |
| Clear pre-connection errors on this thread. | |
| void | n_netw_clear_errors (NETWORK *netw) |
| Clear captured errors on a NETWORK handle. | |
| const char * | n_netw_get_connect_error (int index) |
| Get pre-connection error message by index. | |
| int | n_netw_get_connect_error_count (void) |
| Get number of pre-connection errors captured on this thread. | |
| const char * | n_netw_get_error (NETWORK *netw, int index) |
| Get captured error message by index (0 = oldest). | |
| int | n_netw_get_error_count (NETWORK *netw) |
| Get number of captured errors on a NETWORK handle. | |
| void | n_proxy_cfg_free (N_PROXY_CFG **cfg) |
| Free an N_PROXY_CFG created by n_proxy_cfg_parse(). | |
| N_PROXY_CFG * | n_proxy_cfg_parse (const char *url) |
| Parse a proxy URL string into an N_PROXY_CFG struct. | |
| int | n_proxy_connect_socks5 (const N_PROXY_CFG *proxy, const char *target_host, int target_port) |
| Open a TCP connection through a SOCKS5 proxy. | |
| int | n_proxy_connect_tunnel (const N_PROXY_CFG *proxy, const char *target_host, int target_port) |
| Open a TCP connection through an HTTP proxy using CONNECT tunneling. | |
| int | n_proxy_connect_tunnel_ssl (const N_PROXY_CFG *proxy, const char *target_host, int target_port) |
| Open a TCP connection through an HTTPS proxy using CONNECT tunneling. | |
| void | n_sse_conn_free (N_SSE_CONN **conn) |
| free an SSE connection | |
| N_SSE_CONN * | n_sse_connect (const char *host, const char *port, const char *path, int use_ssl, void(*on_event)(N_SSE_EVENT *, N_SSE_CONN *, void *), void *user_data) |
| connect to an SSE endpoint and start reading events (blocks until stopped) | |
| void | n_sse_event_clean (N_SSE_EVENT *event) |
| free an SSE event's contents (does not free the event struct itself) | |
| void | n_sse_stop (N_SSE_CONN *conn) |
| signal the SSE connection to stop reading | |
| N_STR * | n_url_build (const N_URL *u) |
| build a URL string from parsed components | |
| N_STR * | n_url_decode (const char *str) |
| decode a percent-encoded string (returns N_STR) | |
| N_STR * | n_url_encode (const char *str) |
| percent-encode a string for use in URLs (returns N_STR) | |
| void | n_url_free (N_URL **u) |
| free a N_URL and all its members | |
| N_URL * | n_url_parse (const char *url) |
| parse a URL string into components | |
| void | n_ws_close (N_WS_CONN *conn) |
| send close frame and close the connection | |
| void | n_ws_conn_free (N_WS_CONN **conn) |
| free a WebSocket connection structure | |
| N_WS_CONN * | n_ws_connect (const char *host, const char *port, const char *path, int use_ssl) |
| connect to a WebSocket server (ws:// or wss://) and perform the HTTP/1.1 upgrade handshake | |
| int | n_ws_recv (N_WS_CONN *conn, N_WS_MESSAGE *msg_out) |
| receive one WebSocket frame | |
| int | n_ws_send (N_WS_CONN *conn, const char *payload, size_t len, int opcode) |
| send a WebSocket frame (client always masks) | |
| NETWORK * | netw_accept_from (NETWORK *from) |
| Accepting routine. | |
| NETWORK * | netw_accept_from_ex (NETWORK *from, size_t send_list_limit, size_t recv_list_limit, int blocking, int *retval) |
| Accepting routine extended. | |
| NETWORK * | netw_accept_nonblock_from (NETWORK *from, int blocking) |
| Accepting routine. | |
| int | netw_add_msg (NETWORK *netw, N_STR *msg) |
| Add a message to send in aimed NETWORK. | |
| int | netw_add_msg_ex (NETWORK *netw, char *str, unsigned int length) |
| Add a char message to send in the aimed NETWORK. | |
| int | netw_bind_udp (NETWORK **netw, char *addr, char *port, int ip_version) |
| Create a UDP bound socket. | |
| int | netw_build_http_response (N_STR **http_response, int status_code, const char *server_name, const char *content_type, char *additional_headers, N_STR *body) |
| build HTTP response | |
| size_t | netw_calculate_urlencoded_size (const char *str, size_t len) |
| calculate URL-encoded size | |
| int | netw_close (NETWORK **netw) |
| Closing. | |
| int | netw_connect (NETWORK **netw, char *host, char *port, int ip_version) |
| Connecting. | |
| int | netw_connect_ex (NETWORK **netw, char *host, char *port, size_t send_list_limit, size_t recv_list_limit, int ip_version, char *ssl_key_file, char *ssl_cert_file) |
| Connecting, extended. | |
| int | netw_connect_udp (NETWORK **netw, char *host, char *port, int ip_version) |
| Connect a UDP socket to a remote host. | |
| int | netw_destroy_pool (NETWORK_POOL **netw_pool) |
| destroy pool | |
| NETWORK_HTTP_INFO | netw_extract_http_info (char *request) |
| extract HTTP info from request | |
| char * | netw_extract_http_request_type (const char *request) |
| extract HTTP request type | |
| int | netw_get_http_date (char *buffer, size_t buffer_size) |
| get current HTTP date string | |
| const char * | netw_get_http_status_message (int status_code) |
| get HTTP status message string | |
| N_STR * | netw_get_msg (NETWORK *netw) |
| Get a message from aimed NETWORK. | |
| int | netw_get_queue_status (NETWORK *netw, size_t *nb_to_send, size_t *nb_to_read) |
| get queue status | |
| int | netw_get_state (NETWORK *netw, uint32_t *state, int *thr_engine_status) |
| Get flags from network. | |
| int | netw_get_url_from_http_request (const char *request, char *url, size_t size) |
| get URL from HTTP request | |
| const char * | netw_guess_http_content_type (const char *url) |
| guess HTTP content type from URL | |
| int | netw_info_destroy (NETWORK_HTTP_INFO http_request) |
| destroy HTTP info structure | |
| int | netw_init_openssl (void) |
| init ssl helper | |
| int | netw_init_wsa (int mode, int v1, int v2) |
| Used by Init & Close network. | |
| int | netw_make_listening (NETWORK **netw, char *addr, char *port, int nbpending, int ip_version) |
| Listening network. | |
| NETWORK_POOL * | netw_new_pool (size_t nb_min_element) |
| init pools | |
| HASH_TABLE * | netw_parse_post_data (const char *post_data) |
| parse POST data into hash table | |
| int | netw_pool_add (NETWORK_POOL *netw_pool, NETWORK *netw) |
| add network to pool | |
| int | netw_pool_broadcast (NETWORK_POOL *netw_pool, const NETWORK *from, N_STR *net_msg) |
| broadcast message to pool | |
| size_t | netw_pool_nbclients (NETWORK_POOL *netw_pool) |
| get nb clients | |
| void | netw_pool_netw_close (void *netw_ptr) |
| close pool | |
| int | netw_pool_remove (NETWORK_POOL *netw_pool, NETWORK *netw) |
| remove network from pool | |
| void * | netw_recv_func (void *NET) |
| Thread Receiving management function. | |
| void * | netw_send_func (void *NET) |
| Thread Sending management function. | |
| int | netw_send_ident (NETWORK *netw, int type, int id, N_STR *name, N_STR *passwd) |
| send ident message | |
| int | netw_send_ping (NETWORK *netw, int type, int id_from, int id_to, int time) |
| send ping message | |
| 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) |
| send position message | |
| int | netw_send_quit (NETWORK *netw) |
| send quit message | |
| int | netw_send_string_to (NETWORK *netw, int id_to, N_STR *name, N_STR *chan, N_STR *txt, int color) |
| send string to a specific target | |
| int | netw_send_string_to_all (NETWORK *netw, N_STR *name, N_STR *chan, N_STR *txt, int color) |
| send string to all targets | |
| int | netw_set (NETWORK *netw, int flag) |
| Set flags on network. | |
| int | netw_set_blocking (NETWORK *netw, unsigned long int is_blocking) |
| set blocking mode | |
| int | netw_set_crypto (NETWORK *netw, char *key, char *certificate) |
| set SSL | |
| int | netw_set_crypto_chain (NETWORK *netw, char *key, char *certificate, char *ca_file) |
| set SSL certificate chain from PEM file | |
| int | netw_set_crypto_chain_pem (NETWORK *netw, const char *key_pem, const char *cert_pem, const char *ca_pem) |
| set SSL certificate chain from PEM strings in memory | |
| int | netw_set_crypto_pem (NETWORK *netw, const char *key_pem, const char *cert_pem) |
| set SSL from PEM strings in memory | |
| int | netw_set_user_id (NETWORK *netw, int id) |
| set user id on a netw | |
| int | netw_setsockopt (NETWORK *netw, int optname, int value) |
| Set common socket options (disable naggle, send/recv buf, reuse addr) | |
| int | netw_ssl_connect (NETWORK **netw, char *host, char *port, int ip_version, char *ssl_key_file, char *ssl_cert_file) |
| connect ssl helper | |
| int | netw_ssl_connect_client (NETWORK **netw, char *host, char *port, int ip_version) |
| connect as SSL client without client certificate (TCP + SSL_CTX, no handshake yet) | |
| int | netw_ssl_do_handshake (NETWORK *netw, const char *sni_hostname) |
| complete the SSL handshake on a NETWORK whose ctx was already created | |
| int | netw_ssl_set_ca (NETWORK *netw, const char *ca_file, const char *ca_path) |
| set custom CA verify path or file | |
| int | netw_ssl_set_client_cert (NETWORK *netw, const char *cert_file, const char *key_file) |
| load client certificate and private key for mTLS | |
| int | netw_ssl_set_verify (NETWORK *netw, int enable) |
| enable or disable peer certificate verification | |
| int | netw_start_thr_engine (NETWORK *netw) |
| Create the sending and receiving thread of a NETWORK. | |
| int | netw_stop_thr_engine (NETWORK *netw) |
| Stop a NETWORK connection sending and receiving thread. | |
| ssize_t | netw_udp_recvfrom (NETWORK *netw, char *buf, uint32_t n, struct sockaddr *src_addr, socklen_t *src_len) |
| UDP recvfrom with source address capture. | |
| ssize_t | netw_udp_sendto (NETWORK *netw, char *buf, uint32_t n, struct sockaddr *dest_addr, socklen_t dest_len) |
| UDP sendto with explicit destination. | |
| int | netw_unload_openssl (void) |
| unload ssl helper | |
| char * | netw_urldecode (const char *str) |
| URL-decode a string. | |
| char * | netw_urlencode (const char *str, size_t len) |
| URL-encode a string. | |
| int | netw_wait_close (NETWORK **netw) |
| Closing for peer. | |
| int | netw_wait_close_timed (NETWORK **netw, size_t timeout) |
| Closing for peer with timeout. | |
| N_STR * | netw_wait_msg (NETWORK *netw, unsigned int refresh, size_t timeout) |
| Wait a message from aimed NETWORK. | |
| size_t | ntohst (size_t value) |
| network to host size_t | |
| ssize_t | recv_data (void *netw, char *buf, uint32_t n) |
| Reading from a socket. | |
| ssize_t | recv_php (SOCKET s, int *_code, char **buf) |
| receive from php | |
| ssize_t | recv_ssl_data (void *netw, char *buf, uint32_t n) |
| SSL Reading from a socket. | |
| ssize_t | recv_udp_data (void *netw, char *buf, uint32_t n) |
| UDP recv data from socket. | |
| ssize_t | send_data (void *netw, char *buf, uint32_t n) |
| Writing to a socket. | |
| ssize_t | send_php (SOCKET s, int _code, char *buf, int n) |
| sending to php | |
| ssize_t | send_ssl_data (void *netw, char *buf, uint32_t n) |
| SSL Writing to a socket. | |
| ssize_t | send_udp_data (void *netw, char *buf, uint32_t n) |
| UDP send data to connected peer or specified addr. | |
| struct N_HTTP_REQUEST |
parsed HTTP request for mock server callback
Definition at line 745 of file n_network.h.
Collaboration diagram for N_HTTP_REQUEST:| Data Fields | ||
|---|---|---|
| N_STR * | body | request body (or NULL) |
| LIST * | headers | list of char* "Name: Value" strings |
| char | method[16] | HTTP method. |
| char | path[2048] | request path |
| char | query[2048] | query string (or empty) |
| struct N_HTTP_RESPONSE |
HTTP response to send from mock server callback.
Definition at line 754 of file n_network.h.
Collaboration diagram for N_HTTP_RESPONSE:| Data Fields | ||
|---|---|---|
| N_STR * | body | response body |
| char | content_type[128] | Content-Type header value. |
| int | status_code | HTTP status code. |
| struct N_MOCK_SERVER |
Collaboration diagram for N_MOCK_SERVER:Data Fields | |
| NETWORK * | listener |
| listening network | |
| void(* | on_request )(N_HTTP_REQUEST *req, N_HTTP_RESPONSE *resp, void *user_data) |
| request handler | |
| int | port |
| listening port | |
| volatile int | stop_flag |
| atomic stop flag | |
| void * | user_data |
| user data for handler | |
| NETWORK* N_MOCK_SERVER::listener |
listening network
Definition at line 762 of file n_network.h.
| void(* N_MOCK_SERVER::on_request) (N_HTTP_REQUEST *req, N_HTTP_RESPONSE *resp, void *user_data) |
request handler
Definition at line 764 of file n_network.h.
| int N_MOCK_SERVER::port |
listening port
Definition at line 766 of file n_network.h.
| volatile int N_MOCK_SERVER::stop_flag |
atomic stop flag
Definition at line 763 of file n_network.h.
| void* N_MOCK_SERVER::user_data |
user data for handler
Definition at line 765 of file n_network.h.
| struct N_PROXY_CFG |
Parsed proxy URL components.
Definition at line 554 of file n_network.h.
Collaboration diagram for N_PROXY_CFG:| Data Fields | ||
|---|---|---|
| char * | host | proxy hostname |
| char * | password | NULL if no auth. |
| int | port | proxy port |
| char * | scheme | "http", "https", or "socks5" |
| char * | username | NULL if no auth. |
| struct N_SOCKET |
Structure of a N_SOCKET.
Definition at line 238 of file n_network.h.
Collaboration diagram for N_SOCKET:| 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 N_SSE_CONN |
Collaboration diagram for N_SSE_CONN:Data Fields | |
| NETWORK * | netw |
| underlying network connection | |
| void(* | on_event )(N_SSE_EVENT *event, struct N_SSE_CONN *conn, void *user_data) |
| callback | |
| volatile int | stop_flag |
| atomic stop flag | |
| void * | user_data |
| user data for callback | |
| NETWORK* N_SSE_CONN::netw |
underlying network connection
Definition at line 724 of file n_network.h.
Referenced by n_sse_conn_free(), and n_sse_connect().
| void(* N_SSE_CONN::on_event) (N_SSE_EVENT *event, struct N_SSE_CONN *conn, void *user_data) |
| volatile int N_SSE_CONN::stop_flag |
atomic stop flag
Definition at line 725 of file n_network.h.
Referenced by n_sse_connect(), and n_sse_stop().
| void* N_SSE_CONN::user_data |
| struct N_SSE_EVENT |
SSE event received from server.
Definition at line 713 of file n_network.h.
Collaboration diagram for N_SSE_EVENT:| Data Fields | ||
|---|---|---|
| N_STR * | data | event data |
| N_STR * | event | event type (or NULL for default) |
| N_STR * | id | last event ID (or NULL) |
| int | retry | retry interval in ms (0 if not set) |
| struct N_URL |
parsed URL components
Definition at line 652 of file n_network.h.
Collaboration diagram for N_URL:| Data Fields | ||
|---|---|---|
| char * | host | hostname |
| int | nb_params | number of parsed parameters |
| N_URL_PARAM | params[64] | parsed key=value pairs |
| char * | path | path starting with "/", or "/" if empty |
| int | port | port number (0 if not specified) |
| char * | query | raw query string without leading '?', or NULL |
| char * | scheme | "http" or "https" |
| struct N_URL_PARAM |
a single query parameter key=value pair
Definition at line 646 of file n_network.h.
Collaboration diagram for N_URL_PARAM:| Data Fields | ||
|---|---|---|
| char * | key | parameter name |
| char * | value | parameter value |
| struct N_WS_CONN |
Collaboration diagram for N_WS_CONN:| Data Fields | ||
|---|---|---|
| int | connected | 1 if handshake completed |
| char * | host | remote hostname |
| NETWORK * | netw | underlying network connection |
| char * | path | resource path |
| struct N_WS_MESSAGE |
Collaboration diagram for N_WS_MESSAGE:| Data Fields | ||
|---|---|---|
| int | masked | 1 if masked |
| int | opcode | frame opcode |
| N_STR * | payload | message payload |
| struct NETWORK |
Structure of a NETWORK.
Definition at line 258 of file n_network.h.
Collaboration diagram for NETWORK:| Data Fields | ||
|---|---|---|
| int | addr_infos_loaded | Internal flag to know if we have to free addr infos. |
| char * | certificate | openssl certificate file |
| 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_*) |
| SSL_CTX * | ctx | SSL context holder. |
| int | deplete_queues_timeout | deplete network queues timeout ( 0 disabled, > 0 wait for timeout and check unset/unack datas) |
| int | deplete_socket_timeout | deplete socket send buffer timeout ( 0 disabled, > 0 wait for timeout and check unset/unack datas) |
| pthread_mutex_t | eventbolt | mutex for threaded access of state event |
| char * | key | openssl key file |
| N_SOCKET | link | networking socket |
| const SSL_METHOD * | method | SSL method container. |
| 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 |
| int | netw_err_count | number of captured errors |
| int | netw_err_next | next write slot in ring buffer |
| char | netw_errors[8][512] | per-connection error capture ring buffer (max 8 entries, 512 chars each) |
| 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_keepalive | so keepalive state |
| 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 |
| SSL * | ssl | SSL handle. |
| uint32_t | 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 | transport_type | transport type: NETWORK_TCP (0) or NETWORK_UDP (1) |
| int | user_id | if part of a user property, id of the user |
| int | wait_close_timeout | network wait close timeout value ( < 1 disabled, >= 1 timeout sec ) |
| struct NETWORK_HTTP_INFO |
structure for splitting HTTP requests
Definition at line 381 of file n_network.h.
Collaboration diagram for NETWORK_HTTP_INFO:| Data Fields | ||
|---|---|---|
| char * | body | Pointer to the body data. |
| size_t | content_length | Store content length. |
| char | content_type[256] | Store content type. |
| char * | type | Type of request. |
| struct NETWORK_POOL |
Collaboration diagram for NETWORK_POOL:| Data Fields | ||
|---|---|---|
| HASH_TABLE * | pool | table of clients |
| pthread_rwlock_t | rwlock | thread safety |
| #define _OPEN_SYS_SOCK_IPV6 1 |
Definition at line 207 of file n_network.h.
| #define HEAD_CODE 3 |
Code of a HEAD message.
Definition at line 67 of file n_network.h.
| #define HEAD_SIZE 10 |
Size of a HEAD message.
Definition at line 65 of file n_network.h.
| #define N_ENUM_netw_code_type | ( | _ | ) |
Network codes definition.
Definition at line 214 of file n_network.h.
| #define N_URL_MAX_PARAMS 64 |
maximum number of parsed query parameters
Definition at line 643 of file n_network.h.
| #define N_WS_OP_BINARY 0x02 |
Definition at line 675 of file n_network.h.
| #define N_WS_OP_CLOSE 0x08 |
Definition at line 676 of file n_network.h.
| #define N_WS_OP_PING 0x09 |
Definition at line 677 of file n_network.h.
| #define N_WS_OP_PONG 0x0A |
Definition at line 678 of file n_network.h.
| #define N_WS_OP_TEXT 0x01 |
WebSocket opcodes per RFC 6455.
Definition at line 674 of file n_network.h.
Lock-free atomic read of the network state field.
Uses GCC __atomic builtins (supported on Linux gcc, Solaris gcc, Windows mingw gcc). Provides acquire semantics so subsequent reads see up-to-date values. For use in send/recv thread hot loops to avoid mutex overhead.
Definition at line 363 of file n_network.h.
| #define netw_atomic_write_state | ( | netw, | |
| val | |||
| ) | __atomic_store_n(&(netw)->state, (val), __ATOMIC_RELEASE) |
Lock-free atomic write of the network state field.
Uses GCC __atomic builtins with release semantics so prior writes are visible to threads performing an acquire load.
Definition at line 368 of file n_network.h.
| #define NETW_MAX_RETRIES 8 |
Send or recv max number of retries.
Definition at line 73 of file n_network.h.
| #define NETW_RETRY_DELAY 1000 |
Send or recv delay between retries in usec.
Definition at line 75 of file n_network.h.
| #define NETW_SOCKET_DISCONNECTED -2 |
Code for a disconnected recv.
Definition at line 71 of file n_network.h.
| #define NETW_SOCKET_ERROR -1 |
code for a socket error
Definition at line 69 of file n_network.h.
| #define NETWORK_CONSECUTIVE_SEND_WAIT 2048 |
Flag to set consecutive send waiting timeout
Definition at line 61 of file n_network.h.
| #define NETWORK_DEPLETE_QUEUES_TIMEOUT 1024 |
Flag to set network queues depletion timeout
Definition at line 59 of file n_network.h.
| #define NETWORK_DEPLETE_SOCKET_TIMEOUT 512 |
Flag to set send buffer depletion timeout
Definition at line 57 of file n_network.h.
| #define NETWORK_DISABLE_ZERO_LENGTH_RECV FALSE |
Enable/disable recv of length 0.
Warning: only enable if you know what you are doing ! (TRUE or FALSE)
Definition at line 45 of file n_network.h.
| #define NETWORK_IPALL 0 |
Flag for auto detection by OS of ip version to use.
Definition at line 47 of file n_network.h.
| #define NETWORK_IPV4 1 |
Flag to force IPV4
Definition at line 49 of file n_network.h.
| #define NETWORK_IPV6 2 |
Flag to force IPV6
Definition at line 51 of file n_network.h.
| #define NETWORK_TCP 0 |
Flag for TCP transport (default)
Definition at line 53 of file n_network.h.
| #define NETWORK_UDP 1 |
Flag for UDP transport.
Definition at line 55 of file n_network.h.
| #define NETWORK_WAIT_CLOSE_TIMEOUT 4096 |
Flag to set network closing wait timeout.
Definition at line 63 of file n_network.h.
| #define SOCKET_SIZE_FORMAT "%d" |
socket associated printf style
Definition at line 90 of file n_network.h.
| typedef ssize_t(* netw_func) (void *, char *, uint32_t) |
send/recv func ptr type
Definition at line 235 of file n_network.h.
| typedef int SOCKET |
| enum __netw_code_type |
Network codes declaration.
Definition at line 232 of file n_network.h.
| int deplete_send_buffer | ( | int | fd, |
| int | timeout | ||
| ) |
wait for send buffer to be empty
wait for send buffer to be empty
Not as reliable as expected.
| fd | socket descriptor |
| timeout | timeout value in msec , value <= 0 : disabled |
Definition at line 2010 of file n_network.c.
References LOG_ERR, and n_log.
Referenced by netw_close().
Here is the caller graph for this function:| size_t htonst | ( | size_t | value | ) |
host to network size_t
| value | the size_t value to convert to network order |
Definition at line 134 of file n_network.c.
| void n_mock_server_free | ( | N_MOCK_SERVER ** | server | ) |
free a mock server and close the listening socket
free a mock server and close the listening socket
| server | pointer to pointer, set to NULL |
Definition at line 5570 of file n_network.c.
References __n_assert, FreeNoLog, netw_close(), and server.
Referenced by main().
Here is the call graph for this function:
Here is the caller graph for this function:| void n_mock_server_run | ( | N_MOCK_SERVER * | server | ) |
run the mock server accept loop (blocks until stop_flag is set)
run the mock server accept loop (blocks until stop_flag is set)
Blocks until stop_flag is set.
| server | mock server handle |
Definition at line 5476 of file n_network.c.
References __n_assert, _n_mock_parse_request(), _n_mock_request_clean(), N_HTTP_RESPONSE::body, N_HTTP_RESPONSE::content_type, N_STR::data, free_nstr, NETWORK::link, LOG_INFO, n_log, netw_accept_from_ex(), netw_close(), netw_get_http_status_message(), server, N_SOCKET::sock, N_HTTP_RESPONSE::status_code, and N_STR::written.
Referenced by server_thread().
Here is the call graph for this function:
Here is the caller graph for this function:| N_MOCK_SERVER * n_mock_server_start | ( | int | port, |
| void(*)(N_HTTP_REQUEST *, N_HTTP_RESPONSE *, void *) | on_request, | ||
| void * | user_data | ||
| ) |
start a mock HTTP server on localhost:port (returns immediately)
start a mock HTTP server on localhost:port (returns immediately)
| port | port number to listen on |
| on_request | callback for each received HTTP request |
| user_data | arbitrary pointer passed to callback |
Definition at line 5442 of file n_network.c.
References __n_assert, FreeNoLog, LOG_ERR, LOG_INFO, Malloc, n_log, netw_make_listening(), NETWORK_IPALL, on_request(), port, port_str, and server.
Referenced by main().
Here is the call graph for this function:
Here is the caller graph for this function:| void n_mock_server_stop | ( | N_MOCK_SERVER * | server | ) |
signal the mock server to stop accepting connections
signal the mock server to stop accepting connections
| server | mock server handle |
Definition at line 5561 of file n_network.c.
References __n_assert, and server.
Referenced by main().
Here is the caller graph for this function:| void n_netw_clear_connect_errors | ( | void | ) |
Clear pre-connection errors on this thread.
Definition at line 121 of file n_network.c.
References s_connect_err_count, and s_connect_err_next.
| void n_netw_clear_errors | ( | NETWORK * | netw | ) |
Clear captured errors on a NETWORK handle.
Definition at line 105 of file n_network.c.
References netw, NETWORK::netw_err_count, and NETWORK::netw_err_next.
| const char * n_netw_get_connect_error | ( | int | index | ) |
Get pre-connection error message by index.
Returns NULL if out of range
Definition at line 115 of file n_network.c.
References s_connect_err_count, s_connect_err_next, and s_connect_errors.
| int n_netw_get_connect_error_count | ( | void | ) |
Get number of pre-connection errors captured on this thread.
Definition at line 111 of file n_network.c.
References s_connect_err_count.
| const char * n_netw_get_error | ( | NETWORK * | netw, |
| int | index | ||
| ) |
Get captured error message by index (0 = oldest).
Returns NULL if out of range
Definition at line 99 of file n_network.c.
References netw, NETWORK::netw_err_count, NETWORK::netw_err_next, and NETWORK::netw_errors.
| int n_netw_get_error_count | ( | NETWORK * | netw | ) |
Get number of captured errors on a NETWORK handle.
Definition at line 95 of file n_network.c.
References netw, and NETWORK::netw_err_count.
| void n_proxy_cfg_free | ( | N_PROXY_CFG ** | cfg | ) |
Free an N_PROXY_CFG created by n_proxy_cfg_parse().
| cfg | Pointer to pointer; set to NULL on return. |
Definition at line 5840 of file n_network.c.
References FreeNoLog, N_PROXY_CFG::host, N_PROXY_CFG::password, N_PROXY_CFG::scheme, and N_PROXY_CFG::username.
Referenced by main().
Here is the caller graph for this function:| N_PROXY_CFG * n_proxy_cfg_parse | ( | const char * | url | ) |
Parse a proxy URL string into an N_PROXY_CFG struct.
Accepted formats: http://host:port http://user:pass@host:port https://host:port https://user:pass@host:port socks5://host:port socks5://user:pass@host:port
| url | Proxy URL string. Must not be NULL. |
Definition at line 5745 of file n_network.c.
References FreeNoLog, N_PROXY_CFG::host, LOG_ERR, Malloc, n_log, N_PROXY_CFG::password, port, N_PROXY_CFG::port, N_PROXY_CFG::scheme, and N_PROXY_CFG::username.
Referenced by main().
Here is the caller graph for this function:| int n_proxy_connect_socks5 | ( | const N_PROXY_CFG * | proxy, |
| const char * | target_host, | ||
| int | target_port | ||
| ) |
Open a TCP connection through a SOCKS5 proxy.
Performs the SOCKS5 handshake (no-auth or user/pass auth), requests connection to target_host:target_port. Returns the raw socket fd ready for use.
| proxy | Parsed proxy configuration. Must not be NULL. |
| target_host | Destination hostname. |
| target_port | Destination port. |
Definition at line 6050 of file n_network.c.
References _proxy_tcp_connect(), N_PROXY_CFG::host, LOG_DEBUG, LOG_ERR, n_log, N_PROXY_CFG::password, N_PROXY_CFG::port, and N_PROXY_CFG::username.
Here is the call graph for this function:| int n_proxy_connect_tunnel | ( | const N_PROXY_CFG * | proxy, |
| const char * | target_host, | ||
| int | target_port | ||
| ) |
Open a TCP connection through an HTTP proxy using CONNECT tunneling.
Connects to the proxy, issues: CONNECT target_host:target_port HTTP/1.1 Host: target_host:target_port Proxy-Authorization: Basic base64(user:pass) (if credentials present)
Verifies the proxy responds with 200 Connection established. Returns the raw socket file descriptor ready for a TLS handshake or plain HTTP use over the tunnel.
| proxy | Parsed proxy configuration. Must not be NULL. |
| target_host | Destination hostname. |
| target_port | Destination port. |
Definition at line 5851 of file n_network.c.
References _proxy_tcp_connect(), char_to_nstr(), N_STR::data, free_nstr, N_PROXY_CFG::host, LOG_DEBUG, LOG_ERR, n_base64_encode(), n_log, N_PROXY_CFG::password, N_PROXY_CFG::port, and N_PROXY_CFG::username.
Here is the call graph for this function:| int n_proxy_connect_tunnel_ssl | ( | const N_PROXY_CFG * | proxy, |
| const char * | target_host, | ||
| int | target_port | ||
| ) |
Open a TCP connection through an HTTPS proxy using CONNECT tunneling.
Like n_proxy_connect_tunnel(), but connects to the proxy over TLS first. The CONNECT request and response are exchanged over the encrypted channel. After the tunnel is established, the proxy TLS session is torn down and the raw socket fd is returned, ready for a second TLS handshake to the target or plain HTTP use.
| proxy | Parsed proxy configuration (scheme must be "https"). |
| target_host | Destination hostname. |
| target_port | Destination port. |
Definition at line 5924 of file n_network.c.
References _proxy_tcp_connect(), char_to_nstr(), N_STR::data, free_nstr, N_PROXY_CFG::host, LOG_DEBUG, LOG_ERR, n_base64_encode(), n_log, netw_init_openssl(), N_PROXY_CFG::password, N_PROXY_CFG::port, and N_PROXY_CFG::username.
Here is the call graph for this function:| void n_sse_conn_free | ( | N_SSE_CONN ** | conn | ) |
free an SSE connection
free an SSE connection
| conn | pointer to pointer, set to NULL |
Definition at line 5094 of file n_network.c.
References __n_assert, FreeNoLog, N_SSE_CONN::netw, and netw_close().
Referenced by main(), and n_sse_connect().
Here is the call graph for this function:
Here is the caller graph for this function:| N_SSE_CONN * n_sse_connect | ( | const char * | host, |
| const char * | port, | ||
| const char * | path, | ||
| int | use_ssl, | ||
| void(*)(N_SSE_EVENT *, N_SSE_CONN *, void *) | on_event, | ||
| void * | user_data | ||
| ) |
connect to an SSE endpoint and start reading events (blocks until stopped)
connect to an SSE endpoint and start reading events (blocks until stopped)
Blocks until stopped or connection closes. Calls on_event for each complete SSE event received.
| host | hostname |
| port | port string |
| path | resource path |
| use_ssl | 1 for https, 0 for http |
| on_event | callback for each received event |
| user_data | passed to callback |
Definition at line 5179 of file n_network.c.
References __n_assert, _netw_capture_error(), _sse_read_byte(), _sse_write(), char_to_nstr(), N_SSE_EVENT::data, N_SSE_EVENT::event, free_nstr, N_SSE_EVENT::id, LOG_DEBUG, LOG_ERR, LOG_INFO, Malloc, n_log, n_sse_conn_free(), n_sse_event_clean(), N_SSE_CONN::netw, netw_connect(), netw_ssl_connect_client(), netw_ssl_do_handshake(), NETWORK_IPALL, nstrprintf_cat, N_SSE_CONN::on_event, port, N_SSE_EVENT::retry, N_SSE_CONN::stop_flag, and N_SSE_CONN::user_data.
Referenced by main().
Here is the call graph for this function:
Here is the caller graph for this function:| void n_sse_event_clean | ( | N_SSE_EVENT * | event | ) |
free an SSE event's contents (does not free the event struct itself)
free an SSE event's contents (does not free the event struct itself)
| event | the event to clean |
Definition at line 5073 of file n_network.c.
References N_SSE_EVENT::data, N_SSE_EVENT::event, free_nstr, and N_SSE_EVENT::id.
Referenced by n_sse_connect().
Here is the caller graph for this function:| void n_sse_stop | ( | N_SSE_CONN * | conn | ) |
signal the SSE connection to stop reading
signal the SSE connection to stop reading
| conn | SSE connection |
Definition at line 5085 of file n_network.c.
References __n_assert, and N_SSE_CONN::stop_flag.
Referenced by on_sse_event().
Here is the caller graph for this function:build a URL string from parsed components
Definition at line 5640 of file n_network.c.
References N_URL::host, new_nstr(), nstrprintf, nstrprintf_cat, N_URL::path, N_URL::port, N_URL::query, and N_URL::scheme.
Here is the call graph for this function:| N_STR * n_url_decode | ( | const char * | str | ) |
decode a percent-encoded string (returns N_STR)
Definition at line 5669 of file n_network.c.
References new_nstr(), and nstrprintf_cat.
Here is the call graph for this function:| N_STR * n_url_encode | ( | const char * | str | ) |
percent-encode a string for use in URLs (returns N_STR)
Definition at line 5654 of file n_network.c.
References new_nstr(), and nstrprintf_cat.
Here is the call graph for this function:| void n_url_free | ( | N_URL ** | u | ) |
free a N_URL and all its members
Definition at line 5690 of file n_network.c.
References FreeNoLog, N_URL::host, N_URL_PARAM::key, N_URL::nb_params, N_URL::params, N_URL::path, N_URL::query, N_URL::scheme, and N_URL_PARAM::value.
| N_URL * n_url_parse | ( | const char * | url | ) |
parse a URL string into components
Definition at line 5601 of file n_network.c.
References _n_parse_query_params(), N_URL::host, Malloc, N_URL::path, N_URL::port, N_URL::query, and N_URL::scheme.
Here is the call graph for this function:| void n_ws_close | ( | N_WS_CONN * | conn | ) |
send close frame and close the connection
send close frame and close the connection
Sends a close frame (opcode 0x08), attempts to read a close response, then closes the underlying NETWORK.
| conn | WebSocket connection |
Definition at line 5019 of file n_network.c.
References __n_assert, N_WS_CONN::connected, free_nstr, N_WS_OP_CLOSE, n_ws_recv(), n_ws_send(), N_WS_CONN::netw, netw_close(), and N_WS_MESSAGE::payload.
Referenced by n_ws_conn_free().
Here is the call graph for this function:
Here is the caller graph for this function:| void n_ws_conn_free | ( | N_WS_CONN ** | conn | ) |
free a WebSocket connection structure
free a WebSocket connection structure
Closes the connection if still open, then frees all members.
| conn | pointer to pointer, set to NULL |
Definition at line 5049 of file n_network.c.
References __n_assert, N_WS_CONN::connected, FreeNoLog, N_WS_CONN::host, n_ws_close(), N_WS_CONN::netw, netw_close(), and N_WS_CONN::path.
Referenced by main(), and n_ws_connect().
Here is the call graph for this function:
Here is the caller graph for this function:| N_WS_CONN * n_ws_connect | ( | const char * | host, |
| const char * | port, | ||
| const char * | path, | ||
| int | use_ssl | ||
| ) |
connect to a WebSocket server (ws:// or wss://) and perform the HTTP/1.1 upgrade handshake
connect to a WebSocket server (ws:// or wss://) and perform the HTTP/1.1 upgrade handshake
Performs the HTTP/1.1 upgrade handshake per RFC 6455.
| host | hostname to connect to |
| port | port string (e.g. "443") |
| path | resource path (e.g. "/") |
| use_ssl | 1 for wss://, 0 for ws:// |
Definition at line 4676 of file n_network.c.
References __n_assert, _netw_capture_error(), _ws_write(), N_WS_CONN::connected, NETWORK::crypto_algo, N_STR::data, free_nstr, N_WS_CONN::host, NETWORK::link, LOG_DEBUG, LOG_ERR, LOG_INFO, Malloc, n_base64_encode(), n_log, n_ws_conn_free(), N_WS_CONN::netw, netw_connect(), NETW_ENCRYPT_OPENSSL, netw_ssl_connect_client(), netw_ssl_do_handshake(), NETWORK_IPALL, new_nstr(), N_WS_CONN::path, port, N_SOCKET::sock, NETWORK::ssl, and N_STR::written.
Referenced by main().
Here is the call graph for this function:
Here is the caller graph for this function:| int n_ws_recv | ( | N_WS_CONN * | conn, |
| N_WS_MESSAGE * | msg_out | ||
| ) |
receive one WebSocket frame
receive one WebSocket frame
Reads the frame header, extended length, optional mask, and payload.
| conn | WebSocket connection |
| msg_out | output: populated message. Caller must free payload with free_nstr. |
Definition at line 4947 of file n_network.c.
References __n_assert, _ws_read(), N_STR::data, free_nstr, N_WS_MESSAGE::masked, N_WS_CONN::netw, new_nstr(), N_WS_MESSAGE::opcode, N_WS_MESSAGE::payload, and N_STR::written.
Referenced by main(), and n_ws_close().
Here is the call graph for this function:
Here is the caller graph for this function:| int n_ws_send | ( | N_WS_CONN * | conn, |
| const char * | payload, | ||
| size_t | len, | ||
| int | opcode | ||
| ) |
send a WebSocket frame (client always masks)
send a WebSocket frame (client always masks)
Builds a masked WebSocket frame per RFC 6455 and sends it.
| conn | WebSocket connection |
| payload | data to send |
| len | payload length |
| opcode | frame opcode (N_WS_OP_TEXT, etc.) |
Definition at line 4880 of file n_network.c.
References __n_assert, _netw_capture_error(), _ws_write(), FreeNoLog, LOG_ERR, Malloc, n_log, and N_WS_CONN::netw.
Referenced by main(), and n_ws_close().
Here is the call graph for this function:
Here is the caller graph for this function:Accepting routine.
Accepting routine.
Network 'from' must be allocated with netw_make_listening.
| from | The network from which to obtaion the connection |
Definition at line 2894 of file n_network.c.
References MAX_LIST_ITEMS, and netw_accept_from_ex().
Referenced by main().
Here is the call graph for this function:
Here is the caller graph for this function:| NETWORK * netw_accept_from_ex | ( | NETWORK * | from, |
| size_t | send_list_limit, | ||
| size_t | recv_list_limit, | ||
| int | blocking, | ||
| int * | retval | ||
| ) |
Accepting routine extended.
Accepting routine extended.
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 for unrestricted |
| recv_list_limit | Internal receiving list maximum number of item. 0 for unrestricted |
| 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 2713 of file n_network.c.
References __n_assert, _netw_capture_error(), _str, NETWORK::crypto_algo, NETWORK::ctx, endif, FreeNoLog, get_in_addr(), N_SOCKET::ip, N_SOCKET::is_blocking, NETWORK::link, LOG_DEBUG, LOG_ERR, Malloc, n_log, neterrno, netstrerror, netw, netw_close(), NETW_ENCRYPT_OPENSSL, netw_init_wsa(), netw_new(), NETW_RUN, NETW_SERVER, netw_set(), netw_set_blocking(), netw_setsockopt(), netw_ssl_print_errors(), NETW_THR_ENGINE_STOPPED, N_SOCKET::port, N_SOCKET::raddr, NETWORK::recv_data, recv_ssl_data(), NETWORK::send_data, send_ssl_data(), N_SOCKET::sock, SOCKET_SIZE_FORMAT, and NETWORK::ssl.
Referenced by main(), main(), n_mock_server_run(), netw_accept_from(), netw_accept_nonblock_from(), and netw_accept_pool_thread_func().
Here is the call graph for this function:
Here is the caller graph for this function:Accepting routine.
Accepting routine.
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 2904 of file n_network.c.
References MAX_LIST_ITEMS, and netw_accept_from_ex().
Here is the call graph for this function:Add a message to send in aimed NETWORK.
| netw | NETWORK where add the message |
| msg | the message to add |
Definition at line 2914 of file n_network.c.
References __n_assert, _netw_capture_error(), N_STR::data, free_nstr_ptr(), N_STR::length, list_push(), LOG_ERR, n_log, netw, NETWORK::send_blocker, NETWORK::send_buf, and NETWORK::sendbolt.
Referenced by client_worker_echo(), handle_client(), netw_pool_broadcast(), netw_send_ident(), netw_send_ping(), netw_send_position(), netw_send_quit(), netw_send_string_to(), netw_send_string_to_all(), on_send_click(), send_net_datas(), userlist_add_msg_to_ex(), userlist_send_waiting_msgs(), and userlist_user_send_waiting_msgs().
Here is the call graph for this function:
Here is the caller graph for this function:| int netw_add_msg_ex | ( | NETWORK * | netw, |
| char * | str, | ||
| unsigned int | length | ||
| ) |
Add a char message to send in the aimed NETWORK.
Add a char message to send in the aimed NETWORK.
| netw | NETWORK where add the message |
| str | the message to add |
| length | the size of the message to add |
Definition at line 2946 of file n_network.c.
References __n_assert, N_STR::data, free_nstr_ptr(), N_STR::length, list_push(), Malloc, netw, NETWORK::send_blocker, NETWORK::send_buf, NETWORK::sendbolt, and N_STR::written.
Here is the call graph for this function:| int netw_bind_udp | ( | NETWORK ** | netw, |
| char * | addr, | ||
| char * | port, | ||
| int | ip_version | ||
| ) |
Create a UDP bound socket.
Create a UDP bound socket.
| netw | A NETWORK **network to bind |
| addr | Address to bind, NULL for wildcard |
| port | Port to bind to |
| ip_version | NETWORK_IPALL for both ipv4 and ipv6 , NETWORK_IPV4 or NETWORK_IPV6 |
Definition at line 2360 of file n_network.c.
References __n_assert, _netw_capture_error(), _str, addr, FreeNoLog, get_in_addr(), ip_version, LOG_DEBUG, LOG_ERR, Malloc, MAX_LIST_ITEMS, n_log, neterrno, netstrerror, netw, netw_close(), netw_init_wsa(), netw_new(), NETW_RUN, NETW_SERVER, netw_set(), netw_setsockopt(), NETW_THR_ENGINE_STOPPED, NETWORK_IPV4, NETWORK_IPV6, NETWORK_UDP, port, recv_udp_data(), and send_udp_data().
Referenced by main(), and run_server().
Here is the call graph for this function:
Here is the caller graph for this function:| int netw_build_http_response | ( | N_STR ** | http_response, |
| int | status_code, | ||
| const char * | server_name, | ||
| const char * | content_type, | ||
| char * | additional_headers, | ||
| N_STR * | body | ||
| ) |
build HTTP response
build HTTP response
| http_response | pointer to a N_STR *response. Will be set to the response, or NULL |
| status_code | response http status code |
| server_name | response 'Server' in headers |
| content_type | response 'Content-Type' in headers |
| additional_headers | additional response headers, can be "" if no additional headers, else 'backslash r backslash n' separated key: values |
| body | response 'Server' in headers |
Definition at line 4578 of file n_network.c.
References __n_assert, LOG_DEBUG, n_log, netw_get_http_date(), netw_get_http_status_message(), nstrcat, nstrprintf, and N_STR::written.
Referenced by build_secure_response(), and handle_request().
Here is the call graph for this function:
Here is the caller graph for this function:| size_t netw_calculate_urlencoded_size | ( | const char * | str, |
| size_t | len | ||
| ) |
calculate URL-encoded size
calculate URL-encoded size
| str | clear string from which we want to know the urlencoded size |
| len | length of the input string |
Definition at line 4169 of file n_network.c.
References __n_assert.
Referenced by netw_urlencode().
Here is the caller graph for this function:| int netw_close | ( | NETWORK ** | netw | ) |
Closing.
Closing.
| netw | A NETWORK *network to close |
Definition at line 2041 of file n_network.c.
References __n_assert, _str, deplete_send_buffer(), endif, Free, FreeNoLog, list_destroy(), list_foreach, LOG_DEBUG, LOG_ERR, LOG_WARNING, N_ENUM_ENTRY, n_log, neterrno, netstrerror, netw, NETW_DESTROY_RECVBUF, NETW_DESTROY_SENDBUF, NETW_ENCRYPT_OPENSSL, netw_get_state(), netw_pool_remove(), NETW_SERVER, netw_set(), netw_stop_thr_engine(), NETW_THR_ENGINE_STARTED, and pool.
Referenced by client_worker_echo(), client_worker_fast(), dispatch_to_pool(), handle_client(), handle_inline_and_count(), handle_request(), main(), main(), manage_client(), n_mock_server_free(), n_mock_server_run(), n_sse_conn_free(), n_ws_close(), n_ws_conn_free(), netw_accept_from_ex(), netw_accept_pool_thread_func(), netw_bind_udp(), netw_connect_ex(), netw_connect_udp(), netw_make_listening(), netw_new(), netw_set_blocking(), netw_ssl_connect_client(), on_accept_pooled(), run_client(), run_server(), and ssl_network_thread().
Here is the call graph for this function:
Here is the caller graph for this function:| int netw_connect | ( | NETWORK ** | netw, |
| char * | host, | ||
| char * | port, | ||
| int | ip_version | ||
| ) |
Connecting.
Connecting.
| 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 1814 of file n_network.c.
References _str, ip_version, LOG_INFO, MAX_LIST_ITEMS, n_log, netw, netw_connect_ex(), and port.
Referenced by client_worker_echo(), client_worker_fast(), main(), n_sse_connect(), and n_ws_connect().
Here is the call graph for this function:
Here is the caller graph for this function:| int netw_connect_ex | ( | NETWORK ** | netw, |
| char * | host, | ||
| char * | port, | ||
| size_t | send_list_limit, | ||
| size_t | recv_list_limit, | ||
| int | ip_version, | ||
| char * | ssl_key_file, | ||
| char * | ssl_cert_file | ||
| ) |
Connecting, extended.
Connecting, extended.
| 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. From UNLIMITED_LIST_ITEMS (0) to MAX_LIST_ITEMS (SIZE_MAX). |
| recv_list_limit | Internal receiving list maximum number of item. From UNLIMITED_LIST_ITEMS (0) to MAX_LIST_ITEMS (SIZE_MAX). |
| ip_version | NETWORK_IPALL for both ipv4 and ipv6 , NETWORK_IPV4 or NETWORK_IPV6 |
| ssl_key_file | NULL or the path to the SSL key file to use. If set, a ssl_cert_file must also be provided |
| ssl_cert_file | NULL or the path to the SSL certificate file to use. If set, a ssl_key_file must also be provided |
Definition at line 1670 of file n_network.c.
References __n_assert, _netw_capture_connect_error(), _netw_capture_error(), _str, FreeNoLog, get_in_addr(), N_SOCKET::ip, ip_version, NETWORK::link, LOG_DEBUG, LOG_ERR, LOG_INFO, Malloc, n_log, neterrno, netstrerror, netw, NETW_CLIENT, netw_close(), netw_init_wsa(), netw_new(), NETW_RUN, netw_set(), netw_set_crypto(), NETW_THR_ENGINE_STOPPED, NETWORK_IPV4, NETWORK_IPV6, and port.
Referenced by netw_connect(), netw_ssl_connect(), and netw_ssl_connect_client().
Here is the call graph for this function:
Here is the caller graph for this function:| int netw_connect_udp | ( | NETWORK ** | netw, |
| char * | host, | ||
| char * | port, | ||
| int | ip_version | ||
| ) |
Connect a UDP socket to a remote host.
| netw | A NETWORK **network to connect |
| host | Host or IP to connect to |
| port | Port to connect to |
| ip_version | NETWORK_IPALL, NETWORK_IPV4 or NETWORK_IPV6 |
Definition at line 2468 of file n_network.c.
References __n_assert, _netw_capture_error(), _str, FreeNoLog, get_in_addr(), ip_version, LOG_DEBUG, LOG_ERR, LOG_INFO, Malloc, MAX_LIST_ITEMS, n_log, neterrno, netstrerror, netw, NETW_CLIENT, netw_close(), netw_init_wsa(), netw_new(), NETW_RUN, netw_set(), NETW_THR_ENGINE_STOPPED, NETWORK_IPV4, NETWORK_IPV6, NETWORK_UDP, port, recv_udp_data(), and send_udp_data().
Referenced by main(), and run_client().
Here is the call graph for this function:
Here is the caller graph for this function:| int netw_destroy_pool | ( | NETWORK_POOL ** | netw_pool | ) |
destroy pool
destroy pool
| netw_pool | the address of a NETWORK_POOL *pointer to free |
Definition at line 3880 of file n_network.c.
References __n_assert, destroy_ht(), Free, rw_lock_destroy, unlock, and write_lock.
Here is the call graph for this function:| NETWORK_HTTP_INFO netw_extract_http_info | ( | char * | request | ) |
extract HTTP info from request
extract HTTP info from request
| request | the raw http request string |
Definition at line 4258 of file n_network.c.
References __n_assert, NETWORK_HTTP_INFO::body, NETWORK_HTTP_INFO::content_length, NETWORK_HTTP_INFO::content_type, LOG_ERR, n_log, netw_extract_http_request_type(), and NETWORK_HTTP_INFO::type.
Referenced by handle_request().
Here is the call graph for this function:
Here is the caller graph for this function:| char * netw_extract_http_request_type | ( | const char * | request | ) |
extract HTTP request type
extract HTTP request type
| request | the raw http request |
Definition at line 4225 of file n_network.c.
References __n_assert.
Referenced by netw_extract_http_info().
Here is the caller graph for this function:| int netw_get_http_date | ( | char * | buffer, |
| size_t | buffer_size | ||
| ) |
get current HTTP date string
get current HTTP date string
| buffer | the target buffer, must be big enough to hold the date |
| buffer_size | the size of the target buffer |
Definition at line 4546 of file n_network.c.
References __n_assert, LOG_ERR, and n_log.
Referenced by netw_build_http_response().
Here is the caller graph for this function:| const char * netw_get_http_status_message | ( | int | status_code | ) |
get HTTP status message string
get HTTP status message string
| status_code | the code to convert into a human-readable message |
Definition at line 4522 of file n_network.c.
Referenced by n_mock_server_run(), and netw_build_http_response().
Here is the caller graph for this function:Get a message from aimed NETWORK.
Instant return to NULL if no MSG
| netw | NETWORK where get the msg |
Definition at line 2977 of file n_network.c.
References __n_assert, list_shift, netw, NETWORK::recv_buf, and NETWORK::recvbolt.
Referenced by manage_client(), netw_wait_msg(), and poll_network_msgs().
Here is the caller graph for this function:| int netw_get_queue_status | ( | NETWORK * | netw, |
| size_t * | nb_to_send, | ||
| size_t * | nb_to_read | ||
| ) |
get queue status
get 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 3842 of file n_network.c.
References __n_assert, LIST::nb_items, netw, NETWORK::recv_buf, NETWORK::recvbolt, NETWORK::send_buf, and NETWORK::sendbolt.
| int netw_get_state | ( | NETWORK * | netw, |
| uint32_t * | state, | ||
| int * | thr_engine_status | ||
| ) |
Get flags from network.
Get flags from 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 1924 of file n_network.c.
References NETWORK::eventbolt, LOG_ERR, n_log, netw, netw_atomic_read_state, and NETWORK::threaded_engine_status.
Referenced by main(), manage_client(), netw_close(), netw_stop_thr_engine(), and netw_wait_msg().
Here is the caller graph for this function:| int netw_get_url_from_http_request | ( | const char * | request, |
| char * | url, | ||
| size_t | size | ||
| ) |
get URL from HTTP request
get URL from HTTP request
| request | raw http request to decode |
| url | pointer to an allocated char *holder |
| size | the size of the url holder |
Definition at line 4338 of file n_network.c.
References __n_assert.
Referenced by handle_request().
Here is the caller graph for this function:| const char * netw_guess_http_content_type | ( | const char * | url | ) |
guess HTTP content type from URL
guess HTTP content type from URL
| url | the url from which we want to guess the content type |
Definition at line 4458 of file n_network.c.
References __n_assert.
Referenced by handle_request().
Here is the caller graph for this function:| int netw_info_destroy | ( | NETWORK_HTTP_INFO | http_request | ) |
destroy HTTP info structure
destroy HTTP info structure
| http_request | the parsed NETWORK_HTTP_INFO request |
Definition at line 4325 of file n_network.c.
References NETWORK_HTTP_INFO::body, FreeNoLog, and NETWORK_HTTP_INFO::type.
Referenced by handle_request().
Here is the caller graph for this function:| int netw_init_openssl | ( | void | ) |
init ssl helper
init ssl helper
Initialize openssl
Definition at line 1280 of file n_network.c.
References netw_init_locks(), and OPENSSL_IS_INITIALIZED.
Referenced by n_proxy_connect_tunnel_ssl(), netw_set_crypto(), netw_set_crypto_pem(), and netw_ssl_connect_client().
Here is the call graph for this function:
Here is the caller graph for this function:| int netw_init_wsa | ( | int | mode, |
| int | v1, | ||
| int | v2 | ||
| ) |
Used by Init & Close network.
Used by Init & Close network.
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 824 of file n_network.c.
References mode.
Referenced by netw_accept_from_ex(), netw_bind_udp(), netw_connect_ex(), netw_connect_udp(), and netw_make_listening().
Here is the caller graph for this function:| int netw_make_listening | ( | NETWORK ** | netw, |
| char * | addr, | ||
| char * | port, | ||
| int | nbpending, | ||
| int | ip_version | ||
| ) |
Listening network.
Listening network.
| netw | A NETWORK **network to make listening |
| addr | Address 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 2240 of file n_network.c.
References __n_assert, _netw_capture_error(), _str, addr, FreeNoLog, get_in_addr(), ip_version, LOG_ERR, Malloc, MAX_LIST_ITEMS, n_log, neterrno, netstrerror, netw, netw_close(), netw_init_wsa(), netw_new(), NETW_RUN, NETW_SERVER, netw_set(), netw_setsockopt(), NETW_THR_ENGINE_STOPPED, NETWORK_IPV4, NETWORK_IPV6, and port.
Referenced by main(), main(), and n_mock_server_start().
Here is the call graph for this function:
Here is the caller graph for this function:| NETWORK_POOL * netw_new_pool | ( | size_t | nb_min_element | ) |
init pools
init pools
| nb_min_element | size of internal hash table for network pool |
Definition at line 3861 of file n_network.c.
References __n_assert, Free, init_lock, Malloc, new_ht(), NETWORK_POOL::pool, and NETWORK_POOL::rwlock.
Referenced by main().
Here is the call graph for this function:
Here is the caller graph for this function:| HASH_TABLE * netw_parse_post_data | ( | const char * | post_data | ) |
parse POST data into hash table
parse POST data into hash table
| post_data | the post data to parse |
Definition at line 4412 of file n_network.c.
References __n_assert, ht_put_string(), key, netw_urldecode(), and new_ht().
Referenced by handle_request().
Here is the call graph for this function:
Here is the caller graph for this function:| int netw_pool_add | ( | NETWORK_POOL * | netw_pool, |
| NETWORK * | netw | ||
| ) |
add network to pool
add network to pool
| netw_pool | targeted network pool |
| netw | network to add |
Definition at line 3912 of file n_network.c.
References __n_assert, _netw_capture_error(), _nstr, free_nstr, ht_get_ptr(), ht_put_ptr(), key, NETWORK::link, list_push(), LOG_DEBUG, LOG_ERR, n_log, netw, netw_pool_netw_close(), nstrprintf, NETWORK_POOL::pool, NETWORK::pools, NETWORK_POOL::rwlock, N_SOCKET::sock, unlock, and write_lock.
Referenced by main().
Here is the call graph for this function:
Here is the caller graph for this function:| int netw_pool_broadcast | ( | NETWORK_POOL * | netw_pool, |
| const NETWORK * | from, | ||
| N_STR * | net_msg | ||
| ) |
broadcast message to pool
broadcast message to pool
| netw_pool | targeted network pool |
| from | source network |
| net_msg | mesage to broadcast |
Definition at line 3995 of file n_network.c.
References __n_assert, hash_val, ht_foreach, NETWORK::link, netw, netw_add_msg(), nstrdup(), NETWORK_POOL::pool, read_lock, NETWORK_POOL::rwlock, N_SOCKET::sock, and unlock.
Referenced by on_send_click(), and poll_network_msgs().
Here is the call graph for this function:
Here is the caller graph for this function:| size_t netw_pool_nbclients | ( | NETWORK_POOL * | netw_pool | ) |
get nb clients
get nb clients
| netw_pool | targeted network pool |
Definition at line 4019 of file n_network.c.
References __n_assert, HASH_TABLE::nb_keys, NETWORK_POOL::pool, read_lock, NETWORK_POOL::rwlock, and unlock.
Referenced by main().
Here is the caller graph for this function:| void netw_pool_netw_close | ( | void * | netw_ptr | ) |
close pool
close pool
| netw_ptr | NETWORK *network pointer |
Definition at line 3899 of file n_network.c.
References __n_assert, NETWORK::link, LOG_DEBUG, n_log, netw, and N_SOCKET::sock.
Referenced by netw_pool_add().
Here is the caller graph for this function:| int netw_pool_remove | ( | NETWORK_POOL * | netw_pool, |
| NETWORK * | netw | ||
| ) |
remove network from pool
remove network from pool
| netw_pool | targeted network pool |
| netw | network to remove |
Definition at line 3958 of file n_network.c.
References __n_assert, _netw_capture_error(), _nstr, free_nstr, ht_remove(), key, NETWORK::link, list_search(), LOG_DEBUG, LOG_ERR, n_log, netw, nstrprintf, NETWORK_POOL::pool, NETWORK::pools, remove_list_node, NETWORK_POOL::rwlock, N_SOCKET::sock, unlock, and write_lock.
Referenced by main(), and netw_close().
Here is the call graph for this function:
Here is the caller graph for this function:| void * netw_recv_func | ( | void * | NET | ) |
Thread Receiving management function.
Thread Receiving management function.
| NET | the NETWORK connection to use |
Definition at line 3219 of file n_network.c.
References __n_assert, _netw_capture_error(), _str, N_STR::data, DONE, NETWORK::eventbolt, free_nstr, free_nstr_ptr(), N_SOCKET::ip, N_STR::length, NETWORK::link, list_push(), LOG_DEBUG, LOG_ERR, Malloc, n_log, NETWORK::nb_running_threads, netw, netw_atomic_read_state, NETW_ERROR, NETW_EXIT_ASKED, NETW_EXITED, netw_set(), NETW_SOCKET_DISCONNECTED, NETWORK::recv_buf, NETWORK::recv_data, NETWORK::recvbolt, N_SOCKET::sock, and N_STR::written.
Referenced by netw_start_thr_engine().
Here is the call graph for this function:
Here is the caller graph for this function:| void * netw_send_func | ( | void * | NET | ) |
Thread Sending management function.
Thread Sending management function.
| NET | the NETWORK connection to use, casted into (void*) |
Definition at line 3091 of file n_network.c.
References __n_assert, _netw_capture_error(), _str, N_STR::data, DONE, NETWORK::eventbolt, free_nstr, N_SOCKET::ip, N_STR::length, NETWORK::link, list_shift, LOG_DEBUG, LOG_ERR, n_log, NETWORK::nb_running_threads, netw, netw_atomic_read_state, NETW_ERROR, NETW_EXIT_ASKED, NETW_EXITED, netw_set(), NETW_SOCKET_DISCONNECTED, NETWORK::send_blocker, NETWORK::send_buf, NETWORK::send_data, NETWORK::send_queue_consecutive_wait, NETWORK::sendbolt, N_SOCKET::sock, u_sleep(), and N_STR::written.
Referenced by netw_start_thr_engine().
Here is the call graph for this function:
Here is the caller graph for this function:send ident message
send ident message
| 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 4070 of file n_network.c.
References __n_assert, netmsg_make_ident(), netw, and netw_add_msg().
Here is the call graph for this function:| int netw_send_ping | ( | NETWORK * | netw, |
| int | type, | ||
| int | id_from, | ||
| int | id_to, | ||
| int | time | ||
| ) |
send ping message
send ping message
| 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 4051 of file n_network.c.
References __n_assert, netmsg_make_ping(), netw, and netw_add_msg().
Here is the call graph for this function:| 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 | ||
| ) |
send position message
send position message
| 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 4094 of file n_network.c.
References __n_assert, netmsg_make_position_msg(), netw, and netw_add_msg().
Here is the call graph for this function:| int netw_send_quit | ( | NETWORK * | netw | ) |
send quit message
send quit message
| netw | The aimed NETWORK |
Definition at line 4152 of file n_network.c.
References __n_assert, netmsg_make_quit_msg(), netw, and netw_add_msg().
Here is the call graph for this function:| int netw_send_string_to | ( | NETWORK * | netw, |
| int | id_to, | ||
| N_STR * | name, | ||
| N_STR * | chan, | ||
| N_STR * | txt, | ||
| int | color | ||
| ) |
send string to a specific target
send string to a specific target
| 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 4116 of file n_network.c.
References __n_assert, netmsg_make_string_msg(), netw, netw_add_msg(), and NETWORK::user_id.
Here is the call graph for this function:send string to all targets
send string to all targets
| 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 4136 of file n_network.c.
References __n_assert, netmsg_make_string_msg(), netw, netw_add_msg(), and NETWORK::user_id.
Here is the call graph for this function:| int netw_set | ( | NETWORK * | netw, |
| int | flag | ||
| ) |
Set flags on network.
Set flags on network.
| netw | The NETWORK *connection to modify |
| flag | NETW_EMPTY_SENDBUF, NETW_EMPTY_RECVBUF, NETW_RUN , NETW_EXIT_ASKED , NETW_EXITED |
Definition at line 1946 of file n_network.c.
References __n_assert, NETWORK::eventbolt, list_destroy(), list_empty(), NETWORK::mode, netw, netw_atomic_write_state, NETW_CLIENT, NETW_DESTROY_RECVBUF, NETW_DESTROY_SENDBUF, NETW_EMPTY_RECVBUF, NETW_EMPTY_SENDBUF, NETW_ERROR, NETW_EXIT_ASKED, NETW_EXITED, NETW_RUN, NETW_SERVER, NETW_THR_ENGINE_STARTED, NETW_THR_ENGINE_STOPPED, NETWORK::recv_buf, NETWORK::recvbolt, NETWORK::send_blocker, NETWORK::send_buf, NETWORK::sendbolt, and NETWORK::threaded_engine_status.
Referenced by netw_accept_from_ex(), netw_bind_udp(), netw_close(), netw_connect_ex(), netw_connect_udp(), netw_make_listening(), netw_recv_func(), netw_send_func(), and netw_stop_thr_engine().
Here is the call graph for this function:
Here is the caller graph for this function:| int netw_set_blocking | ( | NETWORK * | netw, |
| unsigned long int | is_blocking | ||
| ) |
set blocking mode
set blocking mode
| netw | The network to configure |
| is_blocking | 0 NON BLOCk , 1 BLOCK |
Definition at line 871 of file n_network.c.
References __n_assert, _netw_capture_error(), _str, FreeNoLog, N_SOCKET::is_blocking, NETWORK::link, LOG_DEBUG, LOG_ERR, n_log, neterrno, netstrerror, netw, netw_close(), and N_SOCKET::sock.
Referenced by main(), and netw_accept_from_ex().
Here is the call graph for this function:
Here is the caller graph for this function:| int netw_set_crypto | ( | NETWORK * | netw, |
| char * | key, | ||
| char * | certificate | ||
| ) |
set SSL
set SSL
| netw | the NETWORK instance to configure |
| key | path to the key file |
| certificate | path to the certificate file |
Definition at line 1321 of file n_network.c.
References __n_assert, NETWORK::certificate, NETWORK::crypto_algo, NETWORK::ctx, FreeNoLog, key, NETWORK::key, NETWORK::link, LOG_ERR, NETWORK::method, n_log, netw, NETW_ENCRYPT_OPENSSL, netw_init_openssl(), netw_ssl_print_errors(), NETWORK::recv_data, recv_ssl_data(), NETWORK::send_data, send_ssl_data(), and N_SOCKET::sock.
Referenced by main(), netw_connect_ex(), and netw_set_crypto_chain().
Here is the call graph for this function:
Here is the caller graph for this function:| int netw_set_crypto_chain | ( | NETWORK * | netw, |
| char * | key, | ||
| char * | certificate, | ||
| char * | ca_file | ||
| ) |
set SSL certificate chain from PEM file
set SSL certificate chain from PEM file
| netw | the NETWORK to configure |
| key | path to the key file |
| certificate | path to the certificate file |
| ca_file | path to the CA certificate file for chain verification |
Definition at line 1473 of file n_network.c.
References __n_assert, ca_file, NETWORK::ctx, key, NETWORK::link, LOG_ERR, n_log, netw, netw_set_crypto(), netw_ssl_print_errors(), and N_SOCKET::sock.
Referenced by main().
Here is the call graph for this function:
Here is the caller graph for this function:| int netw_set_crypto_chain_pem | ( | NETWORK * | netw, |
| const char * | key_pem, | ||
| const char * | cert_pem, | ||
| const char * | ca_pem | ||
| ) |
set SSL certificate chain from PEM strings in memory
set SSL certificate chain from PEM strings in memory
| netw | the NETWORK to configure |
| key_pem | PEM-formatted private key string |
| cert_pem | PEM-formatted certificate string |
| ca_pem | PEM-formatted CA certificate string for verification |
Definition at line 1508 of file n_network.c.
References __n_assert, NETWORK::ctx, LOG_ERR, n_log, netw, and netw_set_crypto_pem().
Here is the call graph for this function:| int netw_set_crypto_pem | ( | NETWORK * | netw, |
| const char * | key_pem, | ||
| const char * | cert_pem | ||
| ) |
set SSL from PEM strings in memory
set SSL from PEM strings in memory
| netw | the NETWORK to configure |
| key_pem | PEM-formatted private key string |
| cert_pem | PEM-formatted certificate string |
Definition at line 1395 of file n_network.c.
References __n_assert, cert, NETWORK::crypto_algo, NETWORK::ctx, NETWORK::link, LOG_ERR, NETWORK::method, n_log, netw, NETW_ENCRYPT_OPENSSL, netw_init_openssl(), netw_ssl_print_errors(), NETWORK::recv_data, recv_ssl_data(), NETWORK::send_data, send_ssl_data(), and N_SOCKET::sock.
Referenced by netw_set_crypto_chain_pem().
Here is the call graph for this function:
Here is the caller graph for this function:| int netw_set_user_id | ( | NETWORK * | netw, |
| int | id | ||
| ) |
set user id on a netw
set user id on a netw
| netw | targeted network |
| id | id we want to associated with |
Definition at line 4036 of file n_network.c.
References __n_assert, netw, and NETWORK::user_id.
| int netw_setsockopt | ( | NETWORK * | netw, |
| int | optname, | ||
| int | value | ||
| ) |
Set common socket options (disable naggle, send/recv buf, reuse addr)
Set common socket options (disable naggle, send/recv buf, reuse addr)
| netw | The socket to configure |
| optname | NETWORK_DEPLETE_SOCKET_TIMEOUT,NETWORK_DEPLETE_QUEUES_TIMEOUT,NETWORK_WAIT_CLOSE_TIMEOUT,NETWORK_CONSECUTIVE_SEND_WAIT ,SO_REUSEADDR,SO_REUSEPORT,SO_KEEPALIVE,TCP_NODELAY,SO_SNDBUF,SO_RCVBUF,SO_LINGER,SO_RCVTIMEO,SO_SNDTIMEO,TCP_USER_TIMEOUT. Please refer to man setsockopt for details |
| value | The value of the socket parameter |
Definition at line 929 of file n_network.c.
References __n_assert, _netw_capture_error(), _str, NETWORK::deplete_queues_timeout, NETWORK::deplete_socket_timeout, FreeNoLog, NETWORK::link, LOG_ERR, n_log, neterrno, netstrerror, netw, NETWORK_CONSECUTIVE_SEND_WAIT, NETWORK_DEPLETE_QUEUES_TIMEOUT, NETWORK_DEPLETE_SOCKET_TIMEOUT, NETWORK_WAIT_CLOSE_TIMEOUT, NETWORK::send_queue_consecutive_wait, NETWORK::so_keepalive, NETWORK::so_linger, NETWORK::so_rcvbuf, NETWORK::so_rcvtimeo, NETWORK::so_reuseaddr, NETWORK::so_sndbuf, NETWORK::so_sndtimeo, N_SOCKET::sock, NETWORK::tcpnodelay, and NETWORK::wait_close_timeout.
Referenced by main(), netw_accept_from_ex(), netw_bind_udp(), and netw_make_listening().
Here is the call graph for this function:
Here is the caller graph for this function:| int netw_ssl_connect | ( | NETWORK ** | netw, |
| char * | host, | ||
| char * | port, | ||
| int | ip_version, | ||
| char * | ssl_key_file, | ||
| char * | ssl_cert_file | ||
| ) |
connect ssl helper
connect ssl helper
| 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 |
| ssl_key_file | NULL or the path to the SSL key file to use. If set, a ssl_cert_file must also be provided |
| ssl_cert_file | NULL or the path to the SSL certificate file to use. If set, a ssl_key_file must also be provided |
Definition at line 1830 of file n_network.c.
References _str, ip_version, LOG_INFO, MAX_LIST_ITEMS, n_log, netw, netw_connect_ex(), and port.
Here is the call graph for this function:| int netw_ssl_connect_client | ( | NETWORK ** | netw, |
| char * | host, | ||
| char * | port, | ||
| int | ip_version | ||
| ) |
connect as SSL client without client certificate (TCP + SSL_CTX, no handshake yet)
connect as SSL client without client certificate (TCP + SSL_CTX, no handshake yet)
Performs TCP connect, creates an SSL_CTX with TLS_client_method and loads default system verify paths. Does NOT perform the SSL handshake. Call netw_ssl_set_ca / netw_ssl_set_verify to configure verification, then netw_ssl_do_handshake to complete the connection.
| netw | output: new NETWORK (must be NULL on entry) |
| host | hostname to connect to |
| port | port string |
| ip_version | NETWORK_IPALL, NETWORK_IPV4, or NETWORK_IPV6 |
Definition at line 1849 of file n_network.c.
References __n_assert, ip_version, MAX_LIST_ITEMS, netw, netw_close(), netw_connect_ex(), NETW_ENCRYPT_OPENSSL, netw_init_openssl(), netw_ssl_print_errors(), port, recv_ssl_data(), and send_ssl_data().
Referenced by n_sse_connect(), and n_ws_connect().
Here is the call graph for this function:
Here is the caller graph for this function:| int netw_ssl_do_handshake | ( | NETWORK * | netw, |
| const char * | sni_hostname | ||
| ) |
complete the SSL handshake on a NETWORK whose ctx was already created
complete the SSL handshake on a NETWORK whose ctx was already created
The NETWORK must have a valid SSL_CTX (from netw_ssl_connect_client or netw_set_crypto). Optionally sets the SNI hostname for virtual hosting support.
| netw | connected NETWORK with ctx set |
| sni_hostname | hostname for SNI extension, or NULL to skip |
Definition at line 1888 of file n_network.c.
References __n_assert, _netw_capture_error(), _str, NETWORK::ctx, N_SOCKET::ip, NETWORK::link, LOG_DEBUG, LOG_ERR, n_log, netw, netw_ssl_print_errors(), N_SOCKET::port, N_SOCKET::sock, and NETWORK::ssl.
Referenced by n_sse_connect(), and n_ws_connect().
Here is the call graph for this function:
Here is the caller graph for this function:| int netw_ssl_set_ca | ( | NETWORK * | netw, |
| const char * | ca_file, | ||
| const char * | ca_path | ||
| ) |
set custom CA verify path or file
set custom CA verify path or file
| netw | the NETWORK to configure |
| ca_file | path to a CA certificate file, or NULL |
| ca_path | path to a directory of CA certificates, or NULL |
Definition at line 1581 of file n_network.c.
References __n_assert, _netw_capture_error(), _str, ca_file, NETWORK::ctx, NETWORK::link, LOG_ERR, n_log, netw, netw_ssl_print_errors(), and N_SOCKET::sock.
Here is the call graph for this function:| int netw_ssl_set_client_cert | ( | NETWORK * | netw, |
| const char * | cert_file, | ||
| const char * | key_file | ||
| ) |
load client certificate and private key for mTLS
load client certificate and private key for mTLS
| netw | the NETWORK to configure |
| cert_file | path to the client certificate file (PEM) |
| key_file | path to the client private key file (PEM), or NULL to use cert_file |
Definition at line 1626 of file n_network.c.
References __n_assert, _netw_capture_error(), NETWORK::ctx, NETWORK::link, LOG_ERR, n_log, netw, netw_ssl_print_errors(), and N_SOCKET::sock.
Here is the call graph for this function:| int netw_ssl_set_verify | ( | NETWORK * | netw, |
| int | enable | ||
| ) |
enable or disable peer certificate verification
enable or disable peer certificate verification
| netw | the NETWORK to configure |
| enable | 1 to enable verification, 0 to disable |
Definition at line 1606 of file n_network.c.
References __n_assert, NETWORK::ctx, LOG_ERR, n_log, and netw.
Referenced by main().
Here is the caller graph for this function:| int netw_start_thr_engine | ( | NETWORK * | netw | ) |
Create the sending and receiving thread of a NETWORK.
Create the sending and receiving thread of a NETWORK.
Create a sending & receiving thread.
| netw | The aimed NETWORK connection to start receiving data |
Definition at line 3050 of file n_network.c.
References __n_assert, _netw_capture_error(), _str, NETWORK::eventbolt, N_SOCKET::ip, NETWORK::link, LOG_ERR, n_log, NETWORK::nb_running_threads, netw, netw_recv_func(), netw_send_func(), NETW_THR_ENGINE_STARTED, NETWORK::recv_thr, NETWORK::send_thr, and NETWORK::threaded_engine_status.
Referenced by client_worker_echo(), handle_client(), main(), and manage_client().
Here is the call graph for this function:
Here is the caller graph for this function:| int netw_stop_thr_engine | ( | NETWORK * | netw | ) |
Stop a NETWORK connection sending and receiving thread.
Stop a NETWORK connection sending and receiving thread.
| netw | The aimed NETWORK conection to stop |
Definition at line 3346 of file n_network.c.
References __n_assert, _netw_capture_error(), NETWORK::link, LOG_DEBUG, LOG_ERR, n_log, netw, NETW_EXIT_ASKED, NETW_EXITED, netw_get_state(), netw_set(), NETW_THR_ENGINE_STARTED, NETW_THR_ENGINE_STOPPED, NETWORK::recv_thr, NETWORK::send_blocker, NETWORK::send_thr, and N_SOCKET::sock.
Referenced by netw_close().
Here is the call graph for this function:
Here is the caller graph for this function:| ssize_t netw_udp_recvfrom | ( | NETWORK * | netw, |
| char * | buf, | ||
| uint32_t | n, | ||
| struct sockaddr * | src_addr, | ||
| socklen_t * | src_len | ||
| ) |
UDP recvfrom with source address capture.
UDP recvfrom with source address capture.
| netw | NETWORK to use for receiving |
| buf | pointer to buffer |
| n | max number of bytes to receive |
| src_addr | pointer to store source address (can be NULL) |
| src_len | pointer to length of src_addr (can be NULL) |
Definition at line 2682 of file n_network.c.
References __n_assert, _netw_capture_error(), _str, FreeNoLog, NETWORK::link, LOG_ERR, n_log, neterrno, netstrerror, netw, NETW_BUFLEN_CAST, NETW_SOCKET_ERROR, and N_SOCKET::sock.
Referenced by main(), and run_server().
Here is the call graph for this function:
Here is the caller graph for this function:| ssize_t netw_udp_sendto | ( | NETWORK * | netw, |
| char * | buf, | ||
| uint32_t | n, | ||
| struct sockaddr * | dest_addr, | ||
| socklen_t | dest_len | ||
| ) |
UDP sendto with explicit destination.
UDP sendto with explicit destination.
| netw | NETWORK to use for sending |
| buf | pointer to buffer |
| n | number of bytes to send |
| dest_addr | destination sockaddr |
| dest_len | length of dest_addr |
Definition at line 2650 of file n_network.c.
References __n_assert, _netw_capture_error(), _str, FreeNoLog, NETWORK::link, LOG_ERR, n_log, neterrno, netstrerror, netw, NETW_BUFLEN_CAST, NETW_SOCKET_ERROR, and N_SOCKET::sock.
Referenced by main(), and run_server().
Here is the call graph for this function:
Here is the caller graph for this function:| int netw_unload_openssl | ( | void | ) |
unload ssl helper
unload ssl helper
Initialize openssl
Definition at line 1302 of file n_network.c.
References netw_kill_locks(), and OPENSSL_IS_INITIALIZED.
Here is the call graph for this function:| char * netw_urldecode | ( | const char * | str | ) |
URL-decode a string.
URL-decode a string.
| str | input string to decode |
Definition at line 4375 of file n_network.c.
References __n_assert, Free, LOG_ERR, and n_log.
Referenced by netw_parse_post_data().
Here is the caller graph for this function:| char * netw_urlencode | ( | const char * | str, |
| size_t | len | ||
| ) |
URL-encode a string.
URL-encode a string.
| str | input string |
| len | input string length |
Definition at line 4192 of file n_network.c.
References __n_assert, and netw_calculate_urlencoded_size().
Here is the call graph for this function:| int netw_wait_close | ( | NETWORK ** | netw | ) |
Closing for peer.
| int netw_wait_close_timed | ( | NETWORK ** | netw, |
| size_t | timeout | ||
| ) |
Closing for peer with timeout.
Wait a message from aimed NETWORK.
Recheck each 'refresh' usec until 'timeout' usec
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 2998 of file n_network.c.
References __n_assert, _netw_capture_error(), NETWORK::link, LOG_DEBUG, LOG_ERR, N_ENUM_ENTRY, n_log, netw, NETW_ERROR, NETW_EXITED, netw_get_msg(), netw_get_state(), NETW_RUN, N_SOCKET::sock, and u_sleep().
Referenced by client_worker_echo(), handle_client(), and main().
Here is the call graph for this function:
Here is the caller graph for this function:| size_t ntohst | ( | size_t | value | ) |
network to host size_t
| value | the size_t value to convert to host order |
Definition at line 151 of file n_network.c.
| ssize_t recv_data | ( | void * | netw, |
| char * | buf, | ||
| uint32_t | n | ||
| ) |
Reading from a socket.
Reading from a socket.
| netw | connected NETWORK |
| buf | pointer to buffer |
| n | number of characters we want |
Definition at line 3447 of file n_network.c.
References __n_assert, _netw_capture_error(), _str, endif, FreeNoLog, LOG_DEBUG, LOG_ERR, n_log, neterrno, netstrerror, netw, NETW_BUFLEN_CAST, NETW_CALL_RETRY, NETW_MAX_RETRIES, NETW_SOCKET_DISCONNECTED, and NETW_SOCKET_ERROR.
Referenced by netw_new().
Here is the call graph for this function:
Here is the caller graph for this function:| ssize_t recv_php | ( | SOCKET | s, |
| int * | _code, | ||
| char ** | buf | ||
| ) |
receive from php
receive from php
| s | connected socket |
| _code | pointer to store the code |
| buf | pointer to buffer |
Definition at line 3736 of file n_network.c.
References _str, Free, FreeNoLog, HEAD_CODE, HEAD_SIZE, LOG_ERR, Malloc, n_log, neterrno, netstrerror, and NETW_BUFLEN_CAST.
| ssize_t recv_ssl_data | ( | void * | netw, |
| char * | buf, | ||
| uint32_t | n | ||
| ) |
SSL Reading from a socket.
SSL Reading from a socket.
| netw | connected NETWORK |
| buf | pointer to buffer |
| n | number of characters we want |
Definition at line 3582 of file n_network.c.
References __n_assert, _netw_capture_error(), _str, FreeNoLog, LOG_ERR, n_log, neterrno, netstrerror, and netw.
Referenced by netw_accept_from_ex(), netw_set_crypto(), netw_set_crypto_pem(), and netw_ssl_connect_client().
Here is the call graph for this function:
Here is the caller graph for this function:| ssize_t recv_udp_data | ( | void * | netw, |
| char * | buf, | ||
| uint32_t | n | ||
| ) |
UDP recv data from socket.
UDP recv data from socket.
| netw | connected NETWORK |
| buf | pointer to buffer |
| n | max number of bytes to receive |
Definition at line 2614 of file n_network.c.
References __n_assert, _netw_capture_error(), _str, FreeNoLog, LOG_DEBUG, LOG_ERR, n_log, neterrno, netstrerror, netw, NETW_BUFLEN_CAST, and NETW_SOCKET_ERROR.
Referenced by main(), netw_bind_udp(), netw_connect_udp(), and run_client().
Here is the call graph for this function:
Here is the caller graph for this function:| ssize_t send_data | ( | void * | netw, |
| char * | buf, | ||
| uint32_t | n | ||
| ) |
Writing to a socket.
Writing to a socket.
| netw | connected NETWORK |
| buf | pointer to buffer |
| n | number of characters we want to send |
Definition at line 3386 of file n_network.c.
References __n_assert, _netw_capture_error(), _str, endif, FreeNoLog, LOG_DEBUG, LOG_ERR, n_log, neterrno, netstrerror, netw, NETW_BUFLEN_CAST, NETW_CALL_RETRY, NETW_MAX_RETRIES, NETW_SOCKET_DISCONNECTED, and NETW_SOCKET_ERROR.
Referenced by netw_new().
Here is the call graph for this function:
Here is the caller graph for this function:| ssize_t send_php | ( | SOCKET | s, |
| int | _code, | ||
| char * | buf, | ||
| int | n | ||
| ) |
sending to php
sending to php
| s | connected socket |
| buf | pointer to buffer |
| n | number of characters we want to send |
| _code | Code for php decoding rule |
Definition at line 3653 of file n_network.c.
References _str, FreeNoLog, HEAD_CODE, HEAD_SIZE, LOG_ERR, n_log, neterrno, netstrerror, and NETW_BUFLEN_CAST.
| ssize_t send_ssl_data | ( | void * | netw, |
| char * | buf, | ||
| uint32_t | n | ||
| ) |
SSL Writing to a socket.
SSL Writing to a socket.
| netw | connected NETWORK in SSL mode |
| buf | pointer to buffer |
| n | number of characters we want to send |
Definition at line 3512 of file n_network.c.
References __n_assert, _netw_capture_error(), _str, FreeNoLog, LOG_ERR, n_log, neterrno, netstrerror, and netw.
Referenced by handle_request(), netw_accept_from_ex(), netw_set_crypto(), netw_set_crypto_pem(), and netw_ssl_connect_client().
Here is the call graph for this function:
Here is the caller graph for this function:| ssize_t send_udp_data | ( | void * | netw, |
| char * | buf, | ||
| uint32_t | n | ||
| ) |
UDP send data to connected peer or specified addr.
UDP send data to connected peer or specified addr.
| netw | connected NETWORK |
| buf | pointer to buffer |
| n | number of bytes to send |
Definition at line 2573 of file n_network.c.
References __n_assert, _netw_capture_error(), _str, endif, FreeNoLog, LOG_DEBUG, LOG_ERR, n_log, neterrno, netstrerror, netw, NETW_BUFLEN_CAST, NETW_SOCKET_DISCONNECTED, and NETW_SOCKET_ERROR.
Referenced by main(), netw_bind_udp(), netw_connect_udp(), and run_client().
Here is the call graph for this function:
Here is the caller graph for this function: