arguments for the accepting thread More...
#include <tcptls.h>
Data Fields | |
int | accept_fd |
void *(* | accept_fn )(void *) |
char | hostname [MAXHOSTNAMELEN] |
struct sockaddr_in | local_address |
pthread_t | master |
const char * | name |
struct sockaddr_in | old_address |
void(* | periodic_fn )(void *) |
int | poll_timeout |
struct sockaddr_in | remote_address |
struct ast_tls_config * | tls_cfg |
void *(* | worker_fn )(void *) |
arguments for the accepting thread
The following code implements a generic mechanism for starting services on a TCP or TLS socket. The service is configured in the struct session_args, and then started by calling server_start(desc) on the descriptor. server_start() first verifies if an instance of the service is active, and in case shuts it down. Then, if the service must be started, creates a socket and a thread in charge of doing the accept().
The body of the thread is desc->accept_fn(desc), which the user can define freely. We supply a sample implementation, server_root(), structured as an infinite loop. At the beginning of each iteration it runs periodic_fn() if defined (e.g. to perform some cleanup etc.) then issues a poll() or equivalent with a timeout of 'poll_timeout' milliseconds, and if the following accept() is successful it creates a thread in charge of running the session, whose body is desc->worker_fn(). The argument of worker_fn() is a struct ast_tcptls_session_instance, which contains the address of the other party, a pointer to desc, the file descriptors (fd) on which we can do a select/poll (but NOT I/O), and a FILE *on which we can do I/O. We have both because we want to support plain and SSL sockets, and going through a FILE * lets us provide the encryption/decryption on the stream without using an auxiliary thread.
int accept_fd |
Definition at line 121 of file tcptls.h.
Referenced by app_exec(), ast_tcptls_client_create(), ast_tcptls_client_start(), ast_tcptls_server_root(), ast_tcptls_server_start(), ast_tcptls_server_stop(), reload_config(), and sip_prepare_socket().
void*(* accept_fn)(void *) |
the function in charge of doing the accept
Definition at line 124 of file tcptls.h.
Referenced by ast_tcptls_server_start().
char hostname[MAXHOSTNAMELEN] |
only necessary for SSL clients so we can compare to common name
Definition at line 119 of file tcptls.h.
Referenced by handle_tcptls_connection(), and sip_prepare_socket().
struct sockaddr_in local_address |
Definition at line 116 of file tcptls.h.
Referenced by __ast_http_load(), __init_manager(), app_exec(), ast_sip_ouraddrfor(), ast_tcptls_client_create(), ast_tcptls_server_start(), reload_config(), sip_show_settings(), and transmit_register().
pthread_t master |
Definition at line 123 of file tcptls.h.
Referenced by ast_tcptls_server_start(), ast_tcptls_server_stop(), sip_prepare_socket(), and unload_module().
const char* name |
Definition at line 127 of file tcptls.h.
Referenced by ast_tcptls_client_create(), ast_tcptls_client_start(), ast_tcptls_server_start(), ast_tcptls_server_stop(), sip_prepare_socket(), and sip_tcptls_client_args_destructor().
struct sockaddr_in old_address |
copy of the local or remote address depending on if its a client or server session
Definition at line 117 of file tcptls.h.
Referenced by ast_tcptls_client_create(), ast_tcptls_server_start(), handle_show_http(), and httpstatus_callback().
void(* periodic_fn)(void *) |
something we may want to run before after select on the accept socket
Definition at line 125 of file tcptls.h.
Referenced by ast_tcptls_server_root().
int poll_timeout |
Definition at line 122 of file tcptls.h.
Referenced by ast_tcptls_server_root().
struct sockaddr_in remote_address |
Definition at line 118 of file tcptls.h.
Referenced by ast_tcptls_client_create(), ast_tcptls_client_start(), and sip_prepare_socket().
struct ast_tls_config* tls_cfg |
points to the SSL configuration if any
Definition at line 120 of file tcptls.h.
Referenced by __ast_http_load(), __init_manager(), ast_tcptls_client_start(), handle_tcptls_connection(), reload_config(), sip_prepare_socket(), and sip_tcptls_client_args_destructor().
void*(* worker_fn)(void *) |
the function in charge of doing the actual work
Definition at line 126 of file tcptls.h.
Referenced by ast_tcptls_client_create(), and handle_tcptls_connection().