Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ex_network_ssl_nonblock.c File Reference
#include "nilorea/n_common.h"
#include "nilorea/n_log.h"
#include "nilorea/n_network.h"
#include "nilorea/n_str.h"
#include "nilorea/n_x509.h"
#include <poll.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <openssl/bio.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/x509.h>
Include dependency graph for ex_network_ssl_nonblock.c:

Go to the source code of this file.

Data Structures

struct  SRV
 server worker context More...

Macros

#define MSG   "nonblock-client->server"
 client->server probe (both messages share this fixed length)
#define MSG_LEN   24
 exchanged length: 23 chars + NUL, identical for MSG and REPLY
#define REPLY   "nonblock-server->client"
 server->client probe

Functions

static NETWORK * bind_free (char *port_out, size_t port_out_len)
static int drive_connect (NETWORK *netw)
static int drive_handshake (NETWORK *netw, int is_server, SSL_CTX *sctx)
static int io_full (NETWORK *netw, char *buf, uint32_t n, int is_send)
static void leave_stale_openssl_error (void)
 leave a genuine error on this thread's OpenSSL queue (portable: a failed PEM parse, no deprecated ERR_put_error / 3.0-only ERR_raise)
int main (int argc, char **argv)
static SSL_CTX * make_server_ctx (const N_STR *cert_pem, const N_STR *key_pem)
static int poll_fd (SOCKET fd, int want_write, int timeout_ms)
static void process_args (int argc, char **argv)
static void * server_fn (void *p)

Data Structure Documentation

◆ SRV

struct SRV

server worker context

Examples
ex_network_alpn.c, ex_network_sni.c, and ex_network_ssl_nonblock.c.

Definition at line 67 of file ex_network_alpn.c.

Collaboration diagram for SRV:
Data Fields
CA_CTX * ca the CA to mint leaves with
SSL_CTX * ctx shared server ctx (owned by main)
char h2_path[128] the :path of the last HTTP/2 request
int h2_requests requests served over HTTP/2
NETWORK * listen the listening socket

listening NETWORK

int ok set to 1 once the server completed the exchange
int rounds_done how many connections it served
char selected[3][32] what ALPN the server answered per round

Macro Definition Documentation

◆ MSG

#define MSG   "nonblock-client->server"

client->server probe (both messages share this fixed length)

Examples
ex_network_ssl_nonblock.c.

Definition at line 50 of file ex_network_ssl_nonblock.c.

Referenced by main(), and server_fn().

◆ MSG_LEN

#define MSG_LEN   24

exchanged length: 23 chars + NUL, identical for MSG and REPLY

Definition at line 54 of file ex_network_ssl_nonblock.c.

◆ REPLY

#define REPLY   "nonblock-server->client"

server->client probe

Examples
ex_network_ssl_nonblock.c.

Definition at line 52 of file ex_network_ssl_nonblock.c.

Referenced by main(), and server_fn().

Function Documentation

◆ bind_free()

NETWORK * bind_free ( char * port_out,
size_t port_out_len )
static

Definition at line 281 of file ex_network_ssl_nonblock.c.

References netw_close(), netw_make_listening(), and NETWORK_IPALL.

Here is the call graph for this function:

◆ drive_connect()

int drive_connect ( NETWORK * netw)
static
Examples
ex_network_ssl_nonblock.c.

Definition at line 211 of file ex_network_ssl_nonblock.c.

References netw, netw_connect_check(), NETW_IO_WANT_WRITE, and poll_fd().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drive_handshake()

int drive_handshake ( NETWORK * netw,
int is_server,
SSL_CTX * sctx )
static
Examples
ex_network_ssl_nonblock.c.

Definition at line 188 of file ex_network_ssl_nonblock.c.

References netw, NETW_IO_WANT_READ, NETW_IO_WANT_WRITE, netw_ssl_handshake_once(), netw_ssl_server_handshake_once(), and poll_fd().

Referenced by main(), and server_fn().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ io_full()

int io_full ( NETWORK * netw,
char * buf,
uint32_t n,
int is_send )
static
Examples
ex_network_ssl_nonblock.c.

Definition at line 228 of file ex_network_ssl_nonblock.c.

References done, netw, NETW_IO_WANT_READ, NETW_IO_WANT_WRITE, poll_fd(), recv_ssl_data_once(), and send_ssl_data_once().

Referenced by main(), and server_fn().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ leave_stale_openssl_error()

void leave_stale_openssl_error ( void )
static

leave a genuine error on this thread's OpenSSL queue (portable: a failed PEM parse, no deprecated ERR_put_error / 3.0-only ERR_raise)

Examples
ex_network_ssl_nonblock.c.

Definition at line 60 of file ex_network_ssl_nonblock.c.

Referenced by main().

Here is the caller graph for this function:

◆ main()

◆ make_server_ctx()

SSL_CTX * make_server_ctx ( const N_STR * cert_pem,
const N_STR * key_pem )
static
Examples
ex_network_ssl_nonblock.c.

Definition at line 117 of file ex_network_ssl_nonblock.c.

References N_STR::data, NETW_TLS_MAX_VERSION, and N_STR::written.

Referenced by main().

Here is the caller graph for this function:

◆ poll_fd()

int poll_fd ( SOCKET fd,
int want_write,
int timeout_ms )
static
Examples
ex_network_ssl_nonblock.c.

Definition at line 159 of file ex_network_ssl_nonblock.c.

Referenced by drive_connect(), drive_handshake(), io_full(), and server_fn().

Here is the caller graph for this function:

◆ process_args()

void process_args ( int argc,
char ** argv )
static

Definition at line 78 of file ex_network_ssl_nonblock.c.

References LOG_DEBUG, LOG_ERR, LOG_INFO, LOG_NOTICE, LOG_NULL, and set_log_level().

Here is the call graph for this function:

◆ server_fn()

void * server_fn ( void * p)
static