OpenOCD
server.c File Reference
Include dependency graph for server.c:

Go to the source code of this file.

Enumerations

enum  shutdown_reason { CONTINUE_MAIN_LOOP , SHUTDOWN_REQUESTED , SHUTDOWN_WITH_ERROR_CODE , SHUTDOWN_WITH_SIGNAL_CODE }
 

Functions

static int add_connection (struct service *service, struct command_context *cmd_ctx)
 
int add_service (const struct service_driver *driver, const char *port, int max_connections, void *priv)
 
 COMMAND_HANDLER (handle_bindto_command)
 
 COMMAND_HANDLER (handle_poll_period_command)
 
 COMMAND_HANDLER (handle_shutdown_command)
 
 COMMAND_HELPER (server_pipe_command, char **out)
 Defines an extended command handler function declaration to enable access to (and manipulation of) the server port number. More...
 
 COMMAND_HELPER (server_port_command, unsigned short *out)
 
int connection_read (struct connection *connection, void *data, int len)
 
int connection_write (struct connection *connection, const void *data, int len)
 
void exit_on_signal (int sig)
 
static void free_service (struct service *c)
 
bool openocd_is_shutdown_pending (void)
 
static int remove_connection (struct service *service, struct connection *connection)
 
static void remove_connections (struct service *service)
 
int remove_service (const char *name, const char *port)
 
static int remove_services (void)
 
void server_free (void)
 
int server_host_os_close (void)
 
int server_host_os_entry (void)
 
int server_init (struct command_context *cmd_ctx)
 
void server_keep_clients_alive (void)
 
int server_loop (struct command_context *command_context)
 
int server_preinit (void)
 
int server_quit (void)
 
int server_register_commands (struct command_context *cmd_ctx)
 
static void sig_handler (int sig)
 
static void sigkey_handler (int sig)
 

Variables

static char * bindto_name
 
static int last_signal
 
static int polling_period = 100
 
static const struct command_registration server_command_handlers []
 
static struct serviceservices
 
static enum shutdown_reason shutdown_openocd = CONTINUE_MAIN_LOOP
 

Enumeration Type Documentation

◆ shutdown_reason

Enumerator
CONTINUE_MAIN_LOOP 
SHUTDOWN_REQUESTED 
SHUTDOWN_WITH_ERROR_CODE 
SHUTDOWN_WITH_SIGNAL_CODE 

Definition at line 40 of file server.c.

Function Documentation

◆ add_connection()

◆ add_service()

◆ COMMAND_HANDLER() [1/3]

COMMAND_HANDLER ( handle_bindto_command  )

Definition at line 788 of file server.c.

References bindto_name, CMD, CMD_ARGC, CMD_ARGV, command_print(), ERROR_COMMAND_SYNTAX_ERROR, and ERROR_OK.

◆ COMMAND_HANDLER() [2/3]

COMMAND_HANDLER ( handle_poll_period_command  )

Definition at line 776 of file server.c.

References CMD_ARGC, CMD_ARGV, COMMAND_PARSE_NUMBER, ERROR_OK, LOG_INFO, LOG_WARNING, and polling_period.

◆ COMMAND_HANDLER() [3/3]

COMMAND_HANDLER ( handle_shutdown_command  )

◆ COMMAND_HELPER() [1/2]

COMMAND_HELPER ( server_pipe_command  ,
char **  out 
)

Defines an extended command handler function declaration to enable access to (and manipulation of) the server port number.

Call server_port like a normal COMMAND_HANDLER with an extra out parameter to receive the specified port number.

Definition at line 866 of file server.c.

References CMD, CMD_ARGC, CMD_ARGV, CMD_CTX, COMMAND_EXEC, command_print(), ERROR_COMMAND_ARGUMENT_INVALID, ERROR_COMMAND_SYNTAX_ERROR, ERROR_OK, and LOG_WARNING.

◆ COMMAND_HELPER() [2/2]

COMMAND_HELPER ( server_port_command  ,
unsigned short *  out 
)

◆ connection_read()

◆ connection_write()

int connection_write ( struct connection connection,
const void *  data,
int  len 
)

◆ exit_on_signal()

void exit_on_signal ( int  sig)

Definition at line 723 of file server.c.

Referenced by openocd_main().

◆ free_service()

static void free_service ( struct service c)
static

Definition at line 191 of file server.c.

References service::name, and service::port.

Referenced by add_service(), and remove_service().

◆ openocd_is_shutdown_pending()

◆ remove_connection()

◆ remove_connections()

static void remove_connections ( struct service service)
static

Definition at line 340 of file server.c.

References service::connections, connection::next, and remove_connection().

Referenced by remove_service(), and remove_services().

◆ remove_service()

int remove_service ( const char *  name,
const char *  port 
)

◆ remove_services()

static int remove_services ( void  )
static

◆ server_free()

void server_free ( void  )

◆ server_host_os_close()

int server_host_os_close ( void  )

Definition at line 653 of file server.c.

References ERROR_OK.

Referenced by openocd_main().

◆ server_host_os_entry()

int server_host_os_entry ( void  )

Definition at line 633 of file server.c.

References ERROR_FAIL, ERROR_OK, LOG_ERROR, and WORD.

Referenced by openocd_main().

◆ server_init()

int server_init ( struct command_context cmd_ctx)

Definition at line 681 of file server.c.

References ERROR_OK, remove_services(), tcl_init(), and telnet_init().

Referenced by openocd_thread().

◆ server_keep_clients_alive()

void server_keep_clients_alive ( void  )

Definition at line 414 of file server.c.

References connection::next, service::next, and services.

Referenced by keep_alive().

◆ server_loop()

◆ server_preinit()

int server_preinit ( void  )

Definition at line 661 of file server.c.

References ERROR_OK, sig_handler(), and sigkey_handler().

Referenced by openocd_thread().

◆ server_quit()

int server_quit ( void  )

Definition at line 698 of file server.c.

References ERROR_OK, last_signal, remove_services(), and target_quit().

Referenced by openocd_thread().

◆ server_register_commands()

int server_register_commands ( struct command_context cmd_ctx)

◆ sig_handler()

static void sig_handler ( int  sig)
static

◆ sigkey_handler()

static void sigkey_handler ( int  sig)
static

Definition at line 621 of file server.c.

References LOG_DEBUG, and sig_handler().

Referenced by server_preinit().

Variable Documentation

◆ bindto_name

char* bindto_name
static

Definition at line 55 of file server.c.

Referenced by add_service(), COMMAND_HANDLER(), and server_free().

◆ last_signal

int last_signal
static

Definition at line 49 of file server.c.

Referenced by openocd_thread(), server_quit(), and sig_handler().

◆ polling_period

int polling_period = 100
static

Definition at line 52 of file server.c.

Referenced by COMMAND_HANDLER(), and server_loop().

◆ server_command_handlers

const struct command_registration server_command_handlers[]
static
Initial value:
= {
{
.name = "shutdown",
.handler = &handle_shutdown_command,
.mode = COMMAND_ANY,
.usage = "",
.help = "shut the server down",
},
{
.name = "poll_period",
.handler = &handle_poll_period_command,
.mode = COMMAND_ANY,
.usage = "",
.help = "set the servers polling period",
},
{
.name = "bindto",
.handler = &handle_bindto_command,
.mode = COMMAND_CONFIG,
.usage = "[name]",
.help = "Specify address by name on which to listen for "
"incoming TCP/IP connections",
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_CONFIG
Definition: command.h:41
@ COMMAND_ANY
Definition: command.h:42

Definition at line 788 of file server.c.

Referenced by server_register_commands().

◆ services

struct service* services
static

◆ shutdown_openocd

enum shutdown_reason shutdown_openocd = CONTINUE_MAIN_LOOP
static

Definition at line 38 of file server.c.

Referenced by COMMAND_HANDLER(), openocd_is_shutdown_pending(), server_loop(), and sig_handler().