29 #include <sys/types.h>
31 #ifdef HAVE_SYS_FILIO_H
32 #include <sys/filio.h>
34 #ifdef HAVE_SYS_IOCTL_H
35 #include <sys/ioctl.h>
43 #define ETIMEDOUT WSAETIMEDOUT
45 #define close(fd) closesocket (fd)
46 #define ioctl ioctlsocket
48 #include <netinet/in.h>
49 #include <arpa/inet.h>
51 #include <sys/socket.h>
52 #include <netinet/tcp.h>
58 #ifndef HAVE_SOCKLEN_T
59 typedef int socklen_t;
79 #define POLL_INTERVAL 5
109 if (*polls < POLL_INTERVAL)
122 fd_set rset, wset, eset;
125 FD_SET (scb->
fd, &rset);
137 n = select (scb->
fd + 1, &rset, &wset, &eset, &t);
145 if (n > 0 || *polls < POLL_INTERVAL)
158 char *port_str, hostname[100];
161 struct hostent *hostent;
162 struct sockaddr_in sockaddr;
168 unsigned int polls = 0;
179 port_str = strchr (name,
':');
182 error (
_(
"net_open: No colon in host name!"));
185 tmp =
min (port_str - name, (
int)
sizeof hostname - 1);
186 strncpy (hostname, name, tmp);
187 hostname[tmp] =
'\000';
188 port = atoi (port_str + 1);
192 strcpy (hostname,
"localhost");
194 hostent = gethostbyname (hostname);
202 sockaddr.sin_family = PF_INET;
203 sockaddr.sin_port = htons (port);
204 memcpy (&sockaddr.sin_addr.s_addr, hostent->h_addr,
205 sizeof (
struct in_addr));
219 ioctl (scb->
fd, FIONBIO, &ioarg);
223 n = connect (scb->
fd, (
struct sockaddr *) &sockaddr, sizeof (sockaddr));
228 int err = WSAGetLastError();
237 && err == WSAECONNREFUSED
239 && err == ECONNREFUSED
251 err != WSAEWOULDBLOCK
285 res = getsockopt (scb->
fd, SOL_SOCKET, SO_ERROR, (
void *) &err, &len);
291 && err == WSAECONNREFUSED
293 && err == ECONNREFUSED
309 ioctl (scb->
fd, FIONBIO, &ioarg);
315 setsockopt (scb->
fd, IPPROTO_TCP, TCP_NODELAY,
316 (
char *)&tmp, sizeof (tmp));
322 signal (SIGPIPE, SIG_IGN);
344 return recv (scb->
fd, (
void *) scb->
buf, count, 0);
350 return send (scb->
fd, buf, count, 0);
417 TCP protocol specific variables\n\
418 Configure variables specific to remote TCP connections"),
419 &tcp_set_cmdlist,
"set tcp ",
422 TCP protocol specific variables\n\
423 Configure variables specific to remote TCP connections"),
424 &tcp_show_cmdlist,
"show tcp ",
429 Set auto-retry on socket connect"),
_(
"\
430 Show auto-retry on socket connect"),
432 &tcp_set_cmdlist, &tcp_show_cmdlist);
436 Set timeout limit in seconds for socket connection"),
_(
"\
437 Show timeout limit in seconds for socket connection"),
_(
"\
438 If set to \"unlimited\", GDB will keep attempting to establish a\n\
439 connection forever, unless interrupted with Ctrl-c.\n\
440 The default is 15 seconds."),
442 &tcp_set_cmdlist, &tcp_show_cmdlist);
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc, struct cmd_list_element **prefixlist, const char *prefixname, int allow_unknown, struct cmd_list_element **list)
int ser_base_set_tty_state(struct serial *scb, serial_ttystate ttystate)
int ser_base_flush_output(struct serial *scb)
struct ui_file * gdb_stdout
int net_write_prim(struct serial *scb, const void *buf, size_t count)
static int tcp_auto_retry
int serial_write(struct serial *scb, const void *buf, size_t count)
int ser_base_setbaudrate(struct serial *scb, int rate)
int gdb_socket_cloexec(int domain, int style, int protocol)
int ser_base_setstopbits(struct serial *scb, int num)
static unsigned int tcp_retry_limit
void ser_base_raw(struct serial *scb)
void ser_base_async(struct serial *scb, int async_p)
struct cmd_list_element * setlist
int net_read_prim(struct serial *scb, size_t count)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t err
void add_setshow_uinteger_cmd(const char *name, enum command_class theclass, unsigned int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
struct cmd_list_element * showlist
int ser_base_noflush_set_tty_state(struct serial *scb, serial_ttystate new_ttystate, serial_ttystate old_ttystate)
static void set_tcp_cmd(char *args, int from_tty)
static int startswith(const char *string, const char *pattern)
int gdb_select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
static struct cmd_list_element * tcp_show_cmdlist
void _initialize_ser_tcp(void)
int ser_base_drain_output(struct serial *scb)
unsigned char buf[BUFSIZ]
static struct cmd_list_element * tcp_set_cmdlist
static int wait_for_connect(struct serial *scb, unsigned int *polls)
static void show_tcp_cmd(char *args, int from_tty)
void ser_base_print_tty_state(struct serial *scb, serial_ttystate ttystate, struct ui_file *stream)
void help_list(struct cmd_list_element *list, const char *cmdtype, enum command_class theclass, struct ui_file *stream)
int ser_base_setparity(struct serial *scb, int parity)
void serial_add_interface(const struct serial_ops *optable)
struct ui_file * gdb_stderr
int ser_base_flush_input(struct serial *scb)
int ser_base_readchar(struct serial *scb, int timeout)
int ser_base_write(struct serial *scb, const void *buf, size_t count)
void net_close(struct serial *scb)
int ser_tcp_send_break(struct serial *scb)
serial_ttystate ser_base_copy_tty_state(struct serial *scb, serial_ttystate ttystate)
void error(const char *fmt,...)
void add_setshow_boolean_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
int(* deprecated_ui_loop_hook)(int signo)
serial_ttystate ser_base_get_tty_state(struct serial *scb)
const ULONGEST const LONGEST len
int net_open(struct serial *scb, const char *name)