OpenOCD
server.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 /***************************************************************************
4  * Copyright (C) 2005 by Dominic Rath *
5  * Dominic.Rath@gmx.de *
6  * *
7  * Copyright (C) 2007,2008 Øyvind Harboe *
8  * oyvind.harboe@zylin.com *
9  * *
10  * Copyright (C) 2008 by Spencer Oliver *
11  * spen@spen-soft.co.uk *
12  ***************************************************************************/
13 
14 #ifndef OPENOCD_SERVER_SERVER_H
15 #define OPENOCD_SERVER_SERVER_H
16 
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20 
21 #include <helper/log.h>
22 #include <helper/replacements.h>
23 
24 #ifdef HAVE_NETINET_IN_H
25 #include <netinet/in.h>
26 #endif
27 
32 };
33 
34 #define CONNECTION_LIMIT_UNLIMITED (-1)
35 
36 struct connection {
37  int fd;
38  int fd_out; /* When using pipes we're writing to a different fd */
39  struct sockaddr_in sin;
41  struct service *service;
43  void *priv;
44  struct connection *next;
45 };
46 
49  const char *name;
65 };
66 
67 struct service {
68  char *name;
69  enum connection_type type;
70  char *port;
71  unsigned short portnumber;
72  int fd;
73  struct sockaddr_in sin;
78  int (*input)(struct connection *connection);
81  void *priv;
82  struct service *next;
83 };
84 
85 int add_service(const struct service_driver *driver, const char *port,
86  int max_connections, void *priv);
87 int remove_service(const char *name, const char *port);
88 
89 int server_host_os_entry(void);
90 int server_host_os_close(void);
91 
92 int server_preinit(void);
93 int server_init(struct command_context *cmd_ctx);
94 int server_quit(void);
95 void server_free(void);
96 void exit_on_signal(int sig);
97 
98 void server_keep_clients_alive(void);
99 
101 
102 int server_register_commands(struct command_context *context);
103 
104 int connection_write(struct connection *connection, const void *data, int len);
105 int connection_read(struct connection *connection, void *data, int len);
106 
107 bool openocd_is_shutdown_pending(void);
108 
115 COMMAND_HELPER(server_pipe_command, char **out);
116 
117 COMMAND_HELPER(server_port_command, unsigned short *out);
118 
119 #define ERROR_SERVER_REMOTE_CLOSED (-400)
120 #define ERROR_CONNECTION_REJECTED (-401)
121 #define ERROR_SERVER_INTERRUPTED (-402)
122 
123 #endif /* OPENOCD_SERVER_SERVER_H */
const char * name
Definition: armv4_5.c:76
static struct esp_usb_jtag * priv
Definition: esp_usb_jtag.c:219
void exit_on_signal(int sig)
Definition: server.c:723
int connection_write(struct connection *connection, const void *data, int len)
Definition: server.c:732
int server_preinit(void)
Definition: server.c:661
int connection_read(struct connection *connection, void *data, int len)
Definition: server.c:744
COMMAND_HELPER(server_pipe_command, char **out)
Defines an extended command handler function declaration to enable access to (and manipulation of) th...
Definition: server.c:866
int server_host_os_close(void)
Definition: server.c:653
void server_free(void)
Definition: server.c:713
int server_register_commands(struct command_context *context)
Definition: server.c:830
int server_host_os_entry(void)
Definition: server.c:633
void server_keep_clients_alive(void)
Definition: server.c:414
bool openocd_is_shutdown_pending(void)
Definition: server.c:752
int server_loop(struct command_context *command_context)
Definition: server.c:422
int remove_service(const char *name, const char *port)
Definition: server.c:355
int server_quit(void)
Definition: server.c:698
connection_type
Definition: server.h:28
@ CONNECTION_PIPE
Definition: server.h:30
@ CONNECTION_STDINOUT
Definition: server.h:31
@ CONNECTION_TCP
Definition: server.h:29
int add_service(const struct service_driver *driver, const char *port, int max_connections, void *priv)
Definition: server.c:198
int server_init(struct command_context *cmd_ctx)
Definition: server.c:681
struct sockaddr_in sin
Definition: server.h:39
struct command_context * cmd_ctx
Definition: server.h:40
void * priv
Definition: server.h:43
int fd_out
Definition: server.h:38
int fd
Definition: server.h:37
struct service * service
Definition: server.h:41
struct connection * next
Definition: server.h:44
bool input_pending
Definition: server.h:42
const char * name
the name of the server
Definition: server.h:49
int(* connection_closed_handler)(struct connection *connection)
callback to tear down the connection
Definition: server.h:62
void(* keep_client_alive_handler)(struct connection *connection)
called periodically to send keep-alive messages on the connection
Definition: server.h:64
int(* new_connection_handler)(struct connection *connection)
complete code to accept a new connection.
Definition: server.h:58
int(* new_connection_during_keep_alive_handler)(struct connection *connection)
optional minimal setup to accept a connection during keep-alive
Definition: server.h:51
int(* input_handler)(struct connection *connection)
callback to handle incoming data
Definition: server.h:60
Definition: server.h:67
struct service * next
Definition: server.h:82
int fd
Definition: server.h:72
void * priv
Definition: server.h:81
int max_connections
Definition: server.h:74
int(* new_connection_during_keep_alive)(struct connection *connection)
Definition: server.h:76
struct sockaddr_in sin
Definition: server.h:73
struct connection * connections
Definition: server.h:75
int(* input)(struct connection *connection)
Definition: server.h:78
char * name
Definition: server.h:68
char * port
Definition: server.h:70
int(* connection_closed)(struct connection *connection)
Definition: server.h:79
unsigned short portnumber
Definition: server.h:71
void(* keep_client_alive)(struct connection *connection)
Definition: server.h:80
enum connection_type type
Definition: server.h:69
int(* new_connection)(struct connection *connection)
Definition: server.h:77