27#include "gdbsupport/filestuff.h"
28#include "gdbsupport/netstuff.h"
32#ifdef HAVE_SYS_FILIO_H
35#ifdef HAVE_SYS_IOCTL_H
39#include "gdbsupport/gdb_sys_time.h"
44#define ETIMEDOUT WSAETIMEDOUT
50#define close(fd) closesocket (fd)
51#define ioctl ioctlsocket
53#include <netinet/in.h>
56#include <sys/socket.h>
57#include <netinet/tcp.h>
61#include "gdbsupport/gdb_select.h"
83#define POLL_INTERVAL 5
127 fd_set rset, wset, eset;
130 FD_SET (sock, &rset);
142 n = select (sock + 1, &rset, &wset, &eset, &t);
166 int sock = gdb_socket_cloexec (ainfo->ai_family, ainfo->ai_socktype,
179 ioctl (sock, FIONBIO, &ioarg);
183 if (connect (sock, ainfo->ai_addr, ainfo->ai_addrlen) < 0)
186 int err = WSAGetLastError();
195 err == WSAECONNREFUSED
214 err != WSAEWOULDBLOCK
234 int saved_errno = errno;
252 int ret = getsockopt (sock, SOL_SOCKET, SO_ERROR, (
char *) &
err, &len);
256 int saved_errno = errno;
262 else if (ret == 0 &&
err != 0)
278 struct addrinfo hint;
279 struct addrinfo *ainfo;
281 memset (&hint, 0,
sizeof (hint));
284 hint.ai_family = AF_UNSPEC;
285 hint.ai_socktype = SOCK_STREAM;
286 hint.ai_protocol = IPPROTO_TCP;
288 parsed_connection_spec parsed = parse_connection_spec (
name, &hint);
290 if (parsed.port_str.empty ())
291 error (_(
"Missing port on hostname '%s'"),
name);
293 int r = getaddrinfo (parsed.host_str.c_str (),
294 parsed.port_str.c_str (),
300 name, gai_strerror (r));
305 scoped_free_addrinfo free_ainfo (ainfo);
309 bool got_connrefused;
312 struct addrinfo *success_ainfo = NULL;
313 unsigned int polls = 0;
320 got_connrefused =
false;
322 for (addrinfo *iter = ainfo; iter != NULL; iter = iter->ai_next)
333 success_ainfo = iter;
339 errno == WSAECONNREFUSED
341 errno == ECONNREFUSED
344 got_connrefused =
true;
354 && success_ainfo == NULL
358 if (success_ainfo == NULL)
371 ioctl (scb->
fd, FIONBIO, &ioarg);
373 if (success_ainfo->ai_protocol == IPPROTO_TCP)
378 setsockopt (scb->
fd, IPPROTO_TCP, TCP_NODELAY,
379 (
char *) &tmp, sizeof (tmp));
385 signal (SIGPIPE, SIG_IGN);
407 return recv (scb->
fd, (
char *) scb->
buf, count, 0);
417 return send (scb->
fd, (
const char *) buf, count, 0);
471TCP protocol specific variables.\n\
472Configure variables specific to remote TCP connections."),
474TCP protocol specific variables.\n\
475Configure variables specific to remote TCP connections."),
481Set auto-retry on socket connect."), _(
"\
482Show auto-retry on socket connect."),
488Set timeout limit in seconds for socket connection."), _(
"\
489Show timeout limit in seconds for socket connection."), _(
"\
490If set to \"unlimited\", GDB will keep attempting to establish a\n\
491connection forever, unless interrupted with Ctrl-c.\n\
492The default is 15 seconds."),
struct cmd_list_element * showlist
struct cmd_list_element * setlist
set_show_commands add_setshow_uinteger_cmd(const char *name, enum command_class theclass, unsigned int *var, const literal_def *extra_literals, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
set_show_commands add_setshow_prefix_cmd(const char *name, command_class theclass, const char *set_doc, const char *show_doc, cmd_list_element **set_subcommands_list, cmd_list_element **show_subcommands_list, cmd_list_element **set_list, cmd_list_element **show_list)
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_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)
int interruptible_select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
void ser_base_async(struct serial *scb, int async_p)
void ser_base_print_tty_state(struct serial *scb, serial_ttystate ttystate, struct ui_file *stream)
void ser_base_raw(struct serial *scb)
int ser_base_set_tty_state(struct serial *scb, serial_ttystate ttystate)
serial_ttystate ser_base_get_tty_state(struct serial *scb)
int ser_base_drain_output(struct serial *scb)
int ser_base_setbaudrate(struct serial *scb, int rate)
serial_ttystate ser_base_copy_tty_state(struct serial *scb, serial_ttystate ttystate)
int ser_base_write(struct serial *scb, const void *buf, size_t count)
int ser_base_setstopbits(struct serial *scb, int num)
int ser_base_flush_output(struct serial *scb)
int ser_base_flush_input(struct serial *scb)
int ser_base_readchar(struct serial *scb, int timeout)
int ser_base_setparity(struct serial *scb, int parity)
static struct cmd_list_element * tcp_set_cmdlist
static int try_connect(const struct addrinfo *ainfo, unsigned int *polls)
static const struct serial_ops tcp_ops
int net_write_prim(struct serial *scb, const void *buf, size_t count)
void _initialize_ser_tcp()
static int wait_for_connect(int sock, unsigned int *polls)
static bool tcp_auto_retry
int net_read_prim(struct serial *scb, size_t count)
static struct cmd_list_element * tcp_show_cmdlist
int net_open(struct serial *scb, const char *name)
static unsigned int tcp_retry_limit
int ser_tcp_send_break(struct serial *scb)
void net_close(struct serial *scb)
int serial_write(struct serial *scb, const void *buf, size_t count)
void serial_add_interface(const struct serial_ops *optable)
unsigned char buf[BUFSIZ]
void gdb_printf(struct ui_file *stream, const char *format,...)