2005-06-13 21:32:01 +00:00
|
|
|
/* Serial interface for raw TCP connections on Un*x like systems.
|
|
|
|
|
2007-01-09 17:59:20 +00:00
|
|
|
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2001, 2005, 2006,
|
2011-01-01 15:34:07 +00:00
|
|
|
2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
1999-04-16 01:35:26 +00:00
|
|
|
|
1999-07-07 20:19:36 +00:00
|
|
|
This file is part of GDB.
|
1999-04-16 01:35:26 +00:00
|
|
|
|
1999-07-07 20:19:36 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-08-23 18:08:50 +00:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
1999-07-07 20:19:36 +00:00
|
|
|
(at your option) any later version.
|
1999-04-16 01:35:26 +00:00
|
|
|
|
1999-07-07 20:19:36 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
1999-04-16 01:35:26 +00:00
|
|
|
|
1999-07-07 20:19:36 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
2007-08-23 18:08:50 +00:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
#include "serial.h"
|
2005-03-25 19:47:23 +00:00
|
|
|
#include "ser-base.h"
|
* NEWS: Mention native Windows support.
* Makefile.in (gdb_select_h, ser_tcp_h): New.
(ALLDEPFILES): Add ser-mingw.c.
(event-loop.o, inflow.o, mingw-hdep.o, posix-hdep.o, ser-base.o)
(ser-tcp.o, ser-unix.o): Update.
(ser-mingw.o): New rule.
* configure: Regenerated.
* configure.ac: Add ser-mingw.o for mingw32.
* ser-mingw.c: New file.
* event-loop.c: Include "gdb_select.h".
(gdb_select): Remove, moved to mingw-hdep.c and posix-hdep.c.
* ser-base.c: Include "gdb_select.h".
(ser_base_wait_for): Use gdb_select.
* serial.c (serial_for_fd): New function.
(serial_fdopen): Try "terminal" before "hardwire". Initialize
the allocated struct serial.
(serial_wait_handle): New function.
* serial.h (serial_for_fd, serial_wait_handle): New prototypes.
(struct serial_ops) [USE_WIN32API]: Add wait_handle.
* gdb_select.h: New file.
* ser-tcp.c: Include "ser-tcp.h". Remove unused "ser-unix.h" include.
(net_close, net_read_prim, net_write_prim): Make global.
(net_open): Likewise. Pass an exception set to select. Whitespace fix.
Document why we can not use gdb_select.
(_initialize_ser_tcp) [USE_WIN32API]: Do not register TCP support here.
* ser-tcp.h: New file.
* inflow.c (gdb_has_a_terminal): Don't initialize stdin_serial here.
(handle_sigio): Use gdb_select.
(initialize_stdin_serial): New function.
* terminal.h (initialize_stdin_serial): New prototype.
* top.c (gdb_init): Call initialize_stdin_serial.
* mingw-hdep.c (gdb_select): New function, moved from gdb_select in
event-loop.c. Add exception condition support. Use serial_for_fd
and serial_wait_handle. Fix timeout handling.
* posix-hdep.c: Include "gdb_select.h".
(gdb_select): New function.
* remote-st.c (connect_command): Use gdb_select.
* ser-unix.c: Include "gdb_select.h".
(hardwire_send_break, wait_for): Use gdb_select.
2006-02-10 22:01:43 +00:00
|
|
|
#include "ser-tcp.h"
|
2009-01-06 17:07:08 +00:00
|
|
|
#include "gdbcmd.h"
|
|
|
|
#include "cli/cli-decode.h"
|
|
|
|
#include "cli/cli-setshow.h"
|
1999-09-22 03:28:34 +00:00
|
|
|
|
1999-04-16 01:35:26 +00:00
|
|
|
#include <sys/types.h>
|
2001-12-07 17:57:05 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_SYS_FILIO_H
|
2011-01-11 21:53:25 +00:00
|
|
|
#include <sys/filio.h> /* For FIONBIO. */
|
2001-12-07 17:57:05 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
2011-01-11 21:53:25 +00:00
|
|
|
#include <sys/ioctl.h> /* For FIONBIO. */
|
2001-12-07 17:57:05 +00:00
|
|
|
#endif
|
|
|
|
|
1999-04-16 01:35:26 +00:00
|
|
|
#include <sys/time.h>
|
2005-04-21 05:34:33 +00:00
|
|
|
|
|
|
|
#ifdef USE_WIN32API
|
|
|
|
#include <winsock2.h>
|
2011-10-28 13:32:05 +00:00
|
|
|
#ifndef ETIMEDOUT
|
2005-04-21 05:34:33 +00:00
|
|
|
#define ETIMEDOUT WSAETIMEDOUT
|
2011-10-28 13:32:05 +00:00
|
|
|
#endif
|
2005-07-24 23:02:41 +00:00
|
|
|
#define close(fd) closesocket (fd)
|
2005-04-21 05:34:33 +00:00
|
|
|
#define ioctl ioctlsocket
|
|
|
|
#else
|
1999-04-16 01:35:26 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/tcp.h>
|
2005-04-21 05:34:33 +00:00
|
|
|
#endif
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2001-02-06 04:17:03 +00:00
|
|
|
#include <signal.h>
|
1999-04-16 01:35:26 +00:00
|
|
|
#include "gdb_string.h"
|
2009-01-06 17:07:08 +00:00
|
|
|
#include "gdb_select.h"
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2005-06-13 21:32:01 +00:00
|
|
|
#ifndef HAVE_SOCKLEN_T
|
|
|
|
typedef int socklen_t;
|
|
|
|
#endif
|
|
|
|
|
1999-09-22 03:28:34 +00:00
|
|
|
void _initialize_ser_tcp (void);
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2009-01-06 17:07:08 +00:00
|
|
|
/* For "set tcp" and "show tcp". */
|
|
|
|
|
|
|
|
static struct cmd_list_element *tcp_set_cmdlist;
|
|
|
|
static struct cmd_list_element *tcp_show_cmdlist;
|
|
|
|
|
|
|
|
/* Whether to auto-retry refused connections. */
|
|
|
|
|
|
|
|
static int tcp_auto_retry = 1;
|
|
|
|
|
|
|
|
/* Timeout period for connections, in seconds. */
|
|
|
|
|
|
|
|
static int tcp_retry_limit = 15;
|
|
|
|
|
2011-01-11 21:53:25 +00:00
|
|
|
/* How many times per second to poll deprecated_ui_loop_hook. */
|
2009-01-06 17:07:08 +00:00
|
|
|
|
|
|
|
#define POLL_INTERVAL 5
|
|
|
|
|
|
|
|
/* Helper function to wait a while. If SCB is non-null, wait on its
|
|
|
|
file descriptor. Otherwise just wait on a timeout, updating *POLLS.
|
|
|
|
Returns -1 on timeout or interrupt, otherwise the value of select. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
wait_for_connect (struct serial *scb, int *polls)
|
|
|
|
{
|
|
|
|
struct timeval t;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
/* While we wait for the connect to complete,
|
|
|
|
poll the UI so it can update or the user can
|
|
|
|
interrupt. */
|
|
|
|
if (deprecated_ui_loop_hook && deprecated_ui_loop_hook (0))
|
|
|
|
{
|
|
|
|
errno = EINTR;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for timeout. */
|
|
|
|
if (*polls > tcp_retry_limit * POLL_INTERVAL)
|
|
|
|
{
|
|
|
|
errno = ETIMEDOUT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Back off to polling once per second after the first POLL_INTERVAL
|
|
|
|
polls. */
|
|
|
|
if (*polls < POLL_INTERVAL)
|
|
|
|
{
|
|
|
|
t.tv_sec = 0;
|
|
|
|
t.tv_usec = 1000000 / POLL_INTERVAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
t.tv_sec = 1;
|
|
|
|
t.tv_usec = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scb)
|
|
|
|
{
|
|
|
|
fd_set rset, wset, eset;
|
2010-05-16 23:49:58 +00:00
|
|
|
|
2009-01-06 17:07:08 +00:00
|
|
|
FD_ZERO (&rset);
|
|
|
|
FD_SET (scb->fd, &rset);
|
|
|
|
wset = rset;
|
|
|
|
eset = rset;
|
|
|
|
|
|
|
|
/* POSIX systems return connection success or failure by signalling
|
|
|
|
wset. Windows systems return success in wset and failure in
|
|
|
|
eset.
|
|
|
|
|
|
|
|
We must call select here, rather than gdb_select, because
|
|
|
|
the serial structure has not yet been initialized - the
|
|
|
|
MinGW select wrapper will not know that this FD refers
|
|
|
|
to a socket. */
|
|
|
|
n = select (scb->fd + 1, &rset, &wset, &eset, &t);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* Use gdb_select here, since we have no file descriptors, and on
|
|
|
|
Windows, plain select doesn't work in that case. */
|
|
|
|
n = gdb_select (0, NULL, NULL, NULL, &t);
|
|
|
|
|
|
|
|
/* If we didn't time out, only count it as one poll. */
|
|
|
|
if (n > 0 || *polls < POLL_INTERVAL)
|
|
|
|
(*polls)++;
|
|
|
|
else
|
|
|
|
(*polls) += POLL_INTERVAL;
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
2001-12-04 06:12:56 +00:00
|
|
|
|
2011-01-11 21:53:25 +00:00
|
|
|
/* Open a tcp socket. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
* NEWS: Mention native Windows support.
* Makefile.in (gdb_select_h, ser_tcp_h): New.
(ALLDEPFILES): Add ser-mingw.c.
(event-loop.o, inflow.o, mingw-hdep.o, posix-hdep.o, ser-base.o)
(ser-tcp.o, ser-unix.o): Update.
(ser-mingw.o): New rule.
* configure: Regenerated.
* configure.ac: Add ser-mingw.o for mingw32.
* ser-mingw.c: New file.
* event-loop.c: Include "gdb_select.h".
(gdb_select): Remove, moved to mingw-hdep.c and posix-hdep.c.
* ser-base.c: Include "gdb_select.h".
(ser_base_wait_for): Use gdb_select.
* serial.c (serial_for_fd): New function.
(serial_fdopen): Try "terminal" before "hardwire". Initialize
the allocated struct serial.
(serial_wait_handle): New function.
* serial.h (serial_for_fd, serial_wait_handle): New prototypes.
(struct serial_ops) [USE_WIN32API]: Add wait_handle.
* gdb_select.h: New file.
* ser-tcp.c: Include "ser-tcp.h". Remove unused "ser-unix.h" include.
(net_close, net_read_prim, net_write_prim): Make global.
(net_open): Likewise. Pass an exception set to select. Whitespace fix.
Document why we can not use gdb_select.
(_initialize_ser_tcp) [USE_WIN32API]: Do not register TCP support here.
* ser-tcp.h: New file.
* inflow.c (gdb_has_a_terminal): Don't initialize stdin_serial here.
(handle_sigio): Use gdb_select.
(initialize_stdin_serial): New function.
* terminal.h (initialize_stdin_serial): New prototype.
* top.c (gdb_init): Call initialize_stdin_serial.
* mingw-hdep.c (gdb_select): New function, moved from gdb_select in
event-loop.c. Add exception condition support. Use serial_for_fd
and serial_wait_handle. Fix timeout handling.
* posix-hdep.c: Include "gdb_select.h".
(gdb_select): New function.
* remote-st.c (connect_command): Use gdb_select.
* ser-unix.c: Include "gdb_select.h".
(hardwire_send_break, wait_for): Use gdb_select.
2006-02-10 22:01:43 +00:00
|
|
|
int
|
2002-05-14 04:26:25 +00:00
|
|
|
net_open (struct serial *scb, const char *name)
|
1999-04-16 01:35:26 +00:00
|
|
|
{
|
2001-12-04 06:12:56 +00:00
|
|
|
char *port_str, hostname[100];
|
|
|
|
int n, port, tmp;
|
2002-05-14 04:26:25 +00:00
|
|
|
int use_udp;
|
1999-04-16 01:35:26 +00:00
|
|
|
struct hostent *hostent;
|
|
|
|
struct sockaddr_in sockaddr;
|
2005-04-21 05:34:33 +00:00
|
|
|
#ifdef USE_WIN32API
|
|
|
|
u_long ioarg;
|
|
|
|
#else
|
|
|
|
int ioarg;
|
|
|
|
#endif
|
2009-01-06 17:07:08 +00:00
|
|
|
int polls = 0;
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2002-05-14 04:26:25 +00:00
|
|
|
use_udp = 0;
|
|
|
|
if (strncmp (name, "udp:", 4) == 0)
|
|
|
|
{
|
|
|
|
use_udp = 1;
|
|
|
|
name = name + 4;
|
|
|
|
}
|
|
|
|
else if (strncmp (name, "tcp:", 4) == 0)
|
|
|
|
name = name + 4;
|
|
|
|
|
1999-04-16 01:35:26 +00:00
|
|
|
port_str = strchr (name, ':');
|
|
|
|
|
|
|
|
if (!port_str)
|
2011-01-11 21:53:25 +00:00
|
|
|
error (_("net_open: No colon in host name!")); /* Shouldn't ever
|
|
|
|
happen. */
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
|
|
tmp = min (port_str - name, (int) sizeof hostname - 1);
|
2011-01-11 21:53:25 +00:00
|
|
|
strncpy (hostname, name, tmp); /* Don't want colon. */
|
|
|
|
hostname[tmp] = '\000'; /* Tie off host name. */
|
1999-04-16 01:35:26 +00:00
|
|
|
port = atoi (port_str + 1);
|
|
|
|
|
2011-01-11 21:53:25 +00:00
|
|
|
/* Default hostname is localhost. */
|
2001-08-02 09:08:03 +00:00
|
|
|
if (!hostname[0])
|
|
|
|
strcpy (hostname, "localhost");
|
|
|
|
|
1999-04-16 01:35:26 +00:00
|
|
|
hostent = gethostbyname (hostname);
|
|
|
|
if (!hostent)
|
|
|
|
{
|
|
|
|
fprintf_unfiltered (gdb_stderr, "%s: unknown host\n", hostname);
|
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-01-06 17:07:08 +00:00
|
|
|
sockaddr.sin_family = PF_INET;
|
|
|
|
sockaddr.sin_port = htons (port);
|
|
|
|
memcpy (&sockaddr.sin_addr.s_addr, hostent->h_addr,
|
|
|
|
sizeof (struct in_addr));
|
|
|
|
|
|
|
|
retry:
|
|
|
|
|
2002-05-14 04:26:25 +00:00
|
|
|
if (use_udp)
|
|
|
|
scb->fd = socket (PF_INET, SOCK_DGRAM, 0);
|
|
|
|
else
|
|
|
|
scb->fd = socket (PF_INET, SOCK_STREAM, 0);
|
|
|
|
|
2010-05-26 22:40:24 +00:00
|
|
|
if (scb->fd == -1)
|
2001-12-04 06:12:56 +00:00
|
|
|
return -1;
|
|
|
|
|
2011-01-11 21:53:25 +00:00
|
|
|
/* Set socket nonblocking. */
|
2005-04-21 05:34:33 +00:00
|
|
|
ioarg = 1;
|
|
|
|
ioctl (scb->fd, FIONBIO, &ioarg);
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2011-01-05 22:22:53 +00:00
|
|
|
/* Use Non-blocking connect. connect() will return 0 if connected
|
2011-01-11 21:53:25 +00:00
|
|
|
already. */
|
2001-12-04 06:12:56 +00:00
|
|
|
n = connect (scb->fd, (struct sockaddr *) &sockaddr, sizeof (sockaddr));
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2009-01-06 17:07:08 +00:00
|
|
|
if (n < 0)
|
|
|
|
{
|
2005-04-21 05:34:33 +00:00
|
|
|
#ifdef USE_WIN32API
|
2009-01-06 17:07:08 +00:00
|
|
|
int err = WSAGetLastError();
|
2005-04-21 05:34:33 +00:00
|
|
|
#else
|
2009-01-06 17:07:08 +00:00
|
|
|
int err = errno;
|
2005-04-21 05:34:33 +00:00
|
|
|
#endif
|
2009-01-06 17:07:08 +00:00
|
|
|
|
|
|
|
/* Maybe we're waiting for the remote target to become ready to
|
|
|
|
accept connections. */
|
|
|
|
if (tcp_auto_retry
|
2005-04-21 05:34:33 +00:00
|
|
|
#ifdef USE_WIN32API
|
2009-01-06 17:07:08 +00:00
|
|
|
&& err == WSAECONNREFUSED
|
|
|
|
#else
|
|
|
|
&& err == ECONNREFUSED
|
2005-04-21 05:34:33 +00:00
|
|
|
#endif
|
2009-01-06 17:07:08 +00:00
|
|
|
&& wait_for_connect (NULL, &polls) >= 0)
|
|
|
|
{
|
|
|
|
close (scb->fd);
|
|
|
|
goto retry;
|
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2009-01-06 17:07:08 +00:00
|
|
|
if (
|
|
|
|
#ifdef USE_WIN32API
|
|
|
|
/* Under Windows, calling "connect" with a non-blocking socket
|
|
|
|
results in WSAEWOULDBLOCK, not WSAEINPROGRESS. */
|
|
|
|
err != WSAEWOULDBLOCK
|
|
|
|
#else
|
|
|
|
err != EINPROGRESS
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
|
|
|
errno = err;
|
|
|
|
net_close (scb);
|
|
|
|
return -1;
|
|
|
|
}
|
2001-12-04 06:12:56 +00:00
|
|
|
|
2011-01-11 21:53:25 +00:00
|
|
|
/* Looks like we need to wait for the connect. */
|
2001-12-04 06:12:56 +00:00
|
|
|
do
|
|
|
|
{
|
2009-01-06 17:07:08 +00:00
|
|
|
n = wait_for_connect (scb, &polls);
|
2001-12-04 06:12:56 +00:00
|
|
|
}
|
2009-01-06 17:07:08 +00:00
|
|
|
while (n == 0);
|
|
|
|
if (n < 0)
|
2001-12-04 06:12:56 +00:00
|
|
|
{
|
2002-05-14 04:26:25 +00:00
|
|
|
net_close (scb);
|
2001-12-04 06:12:56 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
1999-04-16 01:35:26 +00:00
|
|
|
|
2011-01-11 21:53:25 +00:00
|
|
|
/* Got something. Is it an error? */
|
2001-12-04 06:12:56 +00:00
|
|
|
{
|
2005-05-26 20:49:03 +00:00
|
|
|
int res, err;
|
|
|
|
socklen_t len;
|
2010-05-16 23:49:58 +00:00
|
|
|
|
* NEWS: Mention native Windows support.
* Makefile.in (gdb_select_h, ser_tcp_h): New.
(ALLDEPFILES): Add ser-mingw.c.
(event-loop.o, inflow.o, mingw-hdep.o, posix-hdep.o, ser-base.o)
(ser-tcp.o, ser-unix.o): Update.
(ser-mingw.o): New rule.
* configure: Regenerated.
* configure.ac: Add ser-mingw.o for mingw32.
* ser-mingw.c: New file.
* event-loop.c: Include "gdb_select.h".
(gdb_select): Remove, moved to mingw-hdep.c and posix-hdep.c.
* ser-base.c: Include "gdb_select.h".
(ser_base_wait_for): Use gdb_select.
* serial.c (serial_for_fd): New function.
(serial_fdopen): Try "terminal" before "hardwire". Initialize
the allocated struct serial.
(serial_wait_handle): New function.
* serial.h (serial_for_fd, serial_wait_handle): New prototypes.
(struct serial_ops) [USE_WIN32API]: Add wait_handle.
* gdb_select.h: New file.
* ser-tcp.c: Include "ser-tcp.h". Remove unused "ser-unix.h" include.
(net_close, net_read_prim, net_write_prim): Make global.
(net_open): Likewise. Pass an exception set to select. Whitespace fix.
Document why we can not use gdb_select.
(_initialize_ser_tcp) [USE_WIN32API]: Do not register TCP support here.
* ser-tcp.h: New file.
* inflow.c (gdb_has_a_terminal): Don't initialize stdin_serial here.
(handle_sigio): Use gdb_select.
(initialize_stdin_serial): New function.
* terminal.h (initialize_stdin_serial): New prototype.
* top.c (gdb_init): Call initialize_stdin_serial.
* mingw-hdep.c (gdb_select): New function, moved from gdb_select in
event-loop.c. Add exception condition support. Use serial_for_fd
and serial_wait_handle. Fix timeout handling.
* posix-hdep.c: Include "gdb_select.h".
(gdb_select): New function.
* remote-st.c (connect_command): Use gdb_select.
* ser-unix.c: Include "gdb_select.h".
(hardwire_send_break, wait_for): Use gdb_select.
2006-02-10 22:01:43 +00:00
|
|
|
len = sizeof (err);
|
2005-04-21 05:34:33 +00:00
|
|
|
/* On Windows, the fourth parameter to getsockopt is a "char *";
|
|
|
|
on UNIX systems it is generally "void *". The cast to "void *"
|
|
|
|
is OK everywhere, since in C "void *" can be implicitly
|
|
|
|
converted to any pointer type. */
|
|
|
|
res = getsockopt (scb->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len);
|
2001-12-04 06:12:56 +00:00
|
|
|
if (res < 0 || err)
|
|
|
|
{
|
2009-01-06 17:07:08 +00:00
|
|
|
/* Maybe the target still isn't ready to accept the connection. */
|
|
|
|
if (tcp_auto_retry
|
|
|
|
#ifdef USE_WIN32API
|
|
|
|
&& err == WSAECONNREFUSED
|
|
|
|
#else
|
|
|
|
&& err == ECONNREFUSED
|
|
|
|
#endif
|
|
|
|
&& wait_for_connect (NULL, &polls) >= 0)
|
|
|
|
{
|
|
|
|
close (scb->fd);
|
|
|
|
goto retry;
|
|
|
|
}
|
2001-12-04 06:12:56 +00:00
|
|
|
if (err)
|
|
|
|
errno = err;
|
2002-05-14 04:26:25 +00:00
|
|
|
net_close (scb);
|
2001-12-04 06:12:56 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2002-05-14 04:26:25 +00:00
|
|
|
|
2011-01-11 21:53:25 +00:00
|
|
|
/* Turn off nonblocking. */
|
2005-04-21 05:34:33 +00:00
|
|
|
ioarg = 0;
|
|
|
|
ioctl (scb->fd, FIONBIO, &ioarg);
|
2001-12-04 06:12:56 +00:00
|
|
|
|
2002-05-14 04:26:25 +00:00
|
|
|
if (use_udp == 0)
|
|
|
|
{
|
2011-01-11 21:53:25 +00:00
|
|
|
/* Disable Nagle algorithm. Needed in some cases. */
|
2002-05-14 04:26:25 +00:00
|
|
|
tmp = 1;
|
|
|
|
setsockopt (scb->fd, IPPROTO_TCP, TCP_NODELAY,
|
|
|
|
(char *)&tmp, sizeof (tmp));
|
|
|
|
}
|
|
|
|
|
2005-03-16 17:05:31 +00:00
|
|
|
#ifdef SIGPIPE
|
2001-12-04 06:12:56 +00:00
|
|
|
/* If we don't do this, then GDB simply exits
|
|
|
|
when the remote side dies. */
|
|
|
|
signal (SIGPIPE, SIG_IGN);
|
2005-03-16 17:05:31 +00:00
|
|
|
#endif
|
1999-04-16 01:35:26 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
* NEWS: Mention native Windows support.
* Makefile.in (gdb_select_h, ser_tcp_h): New.
(ALLDEPFILES): Add ser-mingw.c.
(event-loop.o, inflow.o, mingw-hdep.o, posix-hdep.o, ser-base.o)
(ser-tcp.o, ser-unix.o): Update.
(ser-mingw.o): New rule.
* configure: Regenerated.
* configure.ac: Add ser-mingw.o for mingw32.
* ser-mingw.c: New file.
* event-loop.c: Include "gdb_select.h".
(gdb_select): Remove, moved to mingw-hdep.c and posix-hdep.c.
* ser-base.c: Include "gdb_select.h".
(ser_base_wait_for): Use gdb_select.
* serial.c (serial_for_fd): New function.
(serial_fdopen): Try "terminal" before "hardwire". Initialize
the allocated struct serial.
(serial_wait_handle): New function.
* serial.h (serial_for_fd, serial_wait_handle): New prototypes.
(struct serial_ops) [USE_WIN32API]: Add wait_handle.
* gdb_select.h: New file.
* ser-tcp.c: Include "ser-tcp.h". Remove unused "ser-unix.h" include.
(net_close, net_read_prim, net_write_prim): Make global.
(net_open): Likewise. Pass an exception set to select. Whitespace fix.
Document why we can not use gdb_select.
(_initialize_ser_tcp) [USE_WIN32API]: Do not register TCP support here.
* ser-tcp.h: New file.
* inflow.c (gdb_has_a_terminal): Don't initialize stdin_serial here.
(handle_sigio): Use gdb_select.
(initialize_stdin_serial): New function.
* terminal.h (initialize_stdin_serial): New prototype.
* top.c (gdb_init): Call initialize_stdin_serial.
* mingw-hdep.c (gdb_select): New function, moved from gdb_select in
event-loop.c. Add exception condition support. Use serial_for_fd
and serial_wait_handle. Fix timeout handling.
* posix-hdep.c: Include "gdb_select.h".
(gdb_select): New function.
* remote-st.c (connect_command): Use gdb_select.
* ser-unix.c: Include "gdb_select.h".
(hardwire_send_break, wait_for): Use gdb_select.
2006-02-10 22:01:43 +00:00
|
|
|
void
|
2002-05-14 04:26:25 +00:00
|
|
|
net_close (struct serial *scb)
|
1999-04-16 01:35:26 +00:00
|
|
|
{
|
2010-05-26 22:40:24 +00:00
|
|
|
if (scb->fd == -1)
|
1999-04-16 01:35:26 +00:00
|
|
|
return;
|
|
|
|
|
1999-07-07 20:19:36 +00:00
|
|
|
close (scb->fd);
|
1999-04-16 01:35:26 +00:00
|
|
|
scb->fd = -1;
|
|
|
|
}
|
|
|
|
|
* NEWS: Mention native Windows support.
* Makefile.in (gdb_select_h, ser_tcp_h): New.
(ALLDEPFILES): Add ser-mingw.c.
(event-loop.o, inflow.o, mingw-hdep.o, posix-hdep.o, ser-base.o)
(ser-tcp.o, ser-unix.o): Update.
(ser-mingw.o): New rule.
* configure: Regenerated.
* configure.ac: Add ser-mingw.o for mingw32.
* ser-mingw.c: New file.
* event-loop.c: Include "gdb_select.h".
(gdb_select): Remove, moved to mingw-hdep.c and posix-hdep.c.
* ser-base.c: Include "gdb_select.h".
(ser_base_wait_for): Use gdb_select.
* serial.c (serial_for_fd): New function.
(serial_fdopen): Try "terminal" before "hardwire". Initialize
the allocated struct serial.
(serial_wait_handle): New function.
* serial.h (serial_for_fd, serial_wait_handle): New prototypes.
(struct serial_ops) [USE_WIN32API]: Add wait_handle.
* gdb_select.h: New file.
* ser-tcp.c: Include "ser-tcp.h". Remove unused "ser-unix.h" include.
(net_close, net_read_prim, net_write_prim): Make global.
(net_open): Likewise. Pass an exception set to select. Whitespace fix.
Document why we can not use gdb_select.
(_initialize_ser_tcp) [USE_WIN32API]: Do not register TCP support here.
* ser-tcp.h: New file.
* inflow.c (gdb_has_a_terminal): Don't initialize stdin_serial here.
(handle_sigio): Use gdb_select.
(initialize_stdin_serial): New function.
* terminal.h (initialize_stdin_serial): New prototype.
* top.c (gdb_init): Call initialize_stdin_serial.
* mingw-hdep.c (gdb_select): New function, moved from gdb_select in
event-loop.c. Add exception condition support. Use serial_for_fd
and serial_wait_handle. Fix timeout handling.
* posix-hdep.c: Include "gdb_select.h".
(gdb_select): New function.
* remote-st.c (connect_command): Use gdb_select.
* ser-unix.c: Include "gdb_select.h".
(hardwire_send_break, wait_for): Use gdb_select.
2006-02-10 22:01:43 +00:00
|
|
|
int
|
2005-04-21 05:34:33 +00:00
|
|
|
net_read_prim (struct serial *scb, size_t count)
|
|
|
|
{
|
|
|
|
return recv (scb->fd, scb->buf, count, 0);
|
|
|
|
}
|
|
|
|
|
* NEWS: Mention native Windows support.
* Makefile.in (gdb_select_h, ser_tcp_h): New.
(ALLDEPFILES): Add ser-mingw.c.
(event-loop.o, inflow.o, mingw-hdep.o, posix-hdep.o, ser-base.o)
(ser-tcp.o, ser-unix.o): Update.
(ser-mingw.o): New rule.
* configure: Regenerated.
* configure.ac: Add ser-mingw.o for mingw32.
* ser-mingw.c: New file.
* event-loop.c: Include "gdb_select.h".
(gdb_select): Remove, moved to mingw-hdep.c and posix-hdep.c.
* ser-base.c: Include "gdb_select.h".
(ser_base_wait_for): Use gdb_select.
* serial.c (serial_for_fd): New function.
(serial_fdopen): Try "terminal" before "hardwire". Initialize
the allocated struct serial.
(serial_wait_handle): New function.
* serial.h (serial_for_fd, serial_wait_handle): New prototypes.
(struct serial_ops) [USE_WIN32API]: Add wait_handle.
* gdb_select.h: New file.
* ser-tcp.c: Include "ser-tcp.h". Remove unused "ser-unix.h" include.
(net_close, net_read_prim, net_write_prim): Make global.
(net_open): Likewise. Pass an exception set to select. Whitespace fix.
Document why we can not use gdb_select.
(_initialize_ser_tcp) [USE_WIN32API]: Do not register TCP support here.
* ser-tcp.h: New file.
* inflow.c (gdb_has_a_terminal): Don't initialize stdin_serial here.
(handle_sigio): Use gdb_select.
(initialize_stdin_serial): New function.
* terminal.h (initialize_stdin_serial): New prototype.
* top.c (gdb_init): Call initialize_stdin_serial.
* mingw-hdep.c (gdb_select): New function, moved from gdb_select in
event-loop.c. Add exception condition support. Use serial_for_fd
and serial_wait_handle. Fix timeout handling.
* posix-hdep.c: Include "gdb_select.h".
(gdb_select): New function.
* remote-st.c (connect_command): Use gdb_select.
* ser-unix.c: Include "gdb_select.h".
(hardwire_send_break, wait_for): Use gdb_select.
2006-02-10 22:01:43 +00:00
|
|
|
int
|
2005-04-21 05:34:33 +00:00
|
|
|
net_write_prim (struct serial *scb, const void *buf, size_t count)
|
|
|
|
{
|
|
|
|
return send (scb->fd, buf, count, 0);
|
|
|
|
}
|
|
|
|
|
2008-09-03 23:54:19 +00:00
|
|
|
int
|
|
|
|
ser_tcp_send_break (struct serial *scb)
|
|
|
|
{
|
2011-01-11 21:53:25 +00:00
|
|
|
/* Send telnet IAC and BREAK characters. */
|
2008-09-03 23:54:19 +00:00
|
|
|
return (serial_write (scb, "\377\363", 2));
|
|
|
|
}
|
|
|
|
|
2009-01-06 17:07:08 +00:00
|
|
|
/* Support for "set tcp" and "show tcp" commands. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_tcp_cmd (char *args, int from_tty)
|
|
|
|
{
|
|
|
|
help_list (tcp_set_cmdlist, "set tcp ", -1, gdb_stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_tcp_cmd (char *args, int from_tty)
|
|
|
|
{
|
|
|
|
help_list (tcp_show_cmdlist, "show tcp ", -1, gdb_stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-16 01:35:26 +00:00
|
|
|
void
|
1999-09-22 03:28:34 +00:00
|
|
|
_initialize_ser_tcp (void)
|
1999-04-16 01:35:26 +00:00
|
|
|
{
|
2005-04-21 05:34:33 +00:00
|
|
|
#ifdef USE_WIN32API
|
* NEWS: Mention native Windows support.
* Makefile.in (gdb_select_h, ser_tcp_h): New.
(ALLDEPFILES): Add ser-mingw.c.
(event-loop.o, inflow.o, mingw-hdep.o, posix-hdep.o, ser-base.o)
(ser-tcp.o, ser-unix.o): Update.
(ser-mingw.o): New rule.
* configure: Regenerated.
* configure.ac: Add ser-mingw.o for mingw32.
* ser-mingw.c: New file.
* event-loop.c: Include "gdb_select.h".
(gdb_select): Remove, moved to mingw-hdep.c and posix-hdep.c.
* ser-base.c: Include "gdb_select.h".
(ser_base_wait_for): Use gdb_select.
* serial.c (serial_for_fd): New function.
(serial_fdopen): Try "terminal" before "hardwire". Initialize
the allocated struct serial.
(serial_wait_handle): New function.
* serial.h (serial_for_fd, serial_wait_handle): New prototypes.
(struct serial_ops) [USE_WIN32API]: Add wait_handle.
* gdb_select.h: New file.
* ser-tcp.c: Include "ser-tcp.h". Remove unused "ser-unix.h" include.
(net_close, net_read_prim, net_write_prim): Make global.
(net_open): Likewise. Pass an exception set to select. Whitespace fix.
Document why we can not use gdb_select.
(_initialize_ser_tcp) [USE_WIN32API]: Do not register TCP support here.
* ser-tcp.h: New file.
* inflow.c (gdb_has_a_terminal): Don't initialize stdin_serial here.
(handle_sigio): Use gdb_select.
(initialize_stdin_serial): New function.
* terminal.h (initialize_stdin_serial): New prototype.
* top.c (gdb_init): Call initialize_stdin_serial.
* mingw-hdep.c (gdb_select): New function, moved from gdb_select in
event-loop.c. Add exception condition support. Use serial_for_fd
and serial_wait_handle. Fix timeout handling.
* posix-hdep.c: Include "gdb_select.h".
(gdb_select): New function.
* remote-st.c (connect_command): Use gdb_select.
* ser-unix.c: Include "gdb_select.h".
(hardwire_send_break, wait_for): Use gdb_select.
2006-02-10 22:01:43 +00:00
|
|
|
/* Do nothing; the TCP serial operations will be initialized in
|
|
|
|
ser-mingw.c. */
|
|
|
|
#else
|
|
|
|
struct serial_ops *ops;
|
2010-05-16 23:49:58 +00:00
|
|
|
|
2005-04-21 05:34:33 +00:00
|
|
|
ops = XMALLOC (struct serial_ops);
|
2003-05-13 19:40:11 +00:00
|
|
|
memset (ops, 0, sizeof (struct serial_ops));
|
1999-09-22 03:28:34 +00:00
|
|
|
ops->name = "tcp";
|
|
|
|
ops->next = 0;
|
2002-05-14 04:26:25 +00:00
|
|
|
ops->open = net_open;
|
|
|
|
ops->close = net_close;
|
2005-04-21 05:34:33 +00:00
|
|
|
ops->readchar = ser_base_readchar;
|
2005-03-25 20:06:36 +00:00
|
|
|
ops->write = ser_base_write;
|
|
|
|
ops->flush_output = ser_base_flush_output;
|
|
|
|
ops->flush_input = ser_base_flush_input;
|
2008-09-03 23:54:19 +00:00
|
|
|
ops->send_break = ser_tcp_send_break;
|
2005-03-25 20:06:36 +00:00
|
|
|
ops->go_raw = ser_base_raw;
|
|
|
|
ops->get_tty_state = ser_base_get_tty_state;
|
2011-03-04 19:23:42 +00:00
|
|
|
ops->copy_tty_state = ser_base_copy_tty_state;
|
2005-03-25 20:06:36 +00:00
|
|
|
ops->set_tty_state = ser_base_set_tty_state;
|
|
|
|
ops->print_tty_state = ser_base_print_tty_state;
|
|
|
|
ops->noflush_set_tty_state = ser_base_noflush_set_tty_state;
|
|
|
|
ops->setbaudrate = ser_base_setbaudrate;
|
|
|
|
ops->setstopbits = ser_base_setstopbits;
|
|
|
|
ops->drain_output = ser_base_drain_output;
|
|
|
|
ops->async = ser_base_async;
|
2005-04-21 05:34:33 +00:00
|
|
|
ops->read_prim = net_read_prim;
|
|
|
|
ops->write_prim = net_write_prim;
|
1999-09-22 03:28:34 +00:00
|
|
|
serial_add_interface (ops);
|
* NEWS: Mention native Windows support.
* Makefile.in (gdb_select_h, ser_tcp_h): New.
(ALLDEPFILES): Add ser-mingw.c.
(event-loop.o, inflow.o, mingw-hdep.o, posix-hdep.o, ser-base.o)
(ser-tcp.o, ser-unix.o): Update.
(ser-mingw.o): New rule.
* configure: Regenerated.
* configure.ac: Add ser-mingw.o for mingw32.
* ser-mingw.c: New file.
* event-loop.c: Include "gdb_select.h".
(gdb_select): Remove, moved to mingw-hdep.c and posix-hdep.c.
* ser-base.c: Include "gdb_select.h".
(ser_base_wait_for): Use gdb_select.
* serial.c (serial_for_fd): New function.
(serial_fdopen): Try "terminal" before "hardwire". Initialize
the allocated struct serial.
(serial_wait_handle): New function.
* serial.h (serial_for_fd, serial_wait_handle): New prototypes.
(struct serial_ops) [USE_WIN32API]: Add wait_handle.
* gdb_select.h: New file.
* ser-tcp.c: Include "ser-tcp.h". Remove unused "ser-unix.h" include.
(net_close, net_read_prim, net_write_prim): Make global.
(net_open): Likewise. Pass an exception set to select. Whitespace fix.
Document why we can not use gdb_select.
(_initialize_ser_tcp) [USE_WIN32API]: Do not register TCP support here.
* ser-tcp.h: New file.
* inflow.c (gdb_has_a_terminal): Don't initialize stdin_serial here.
(handle_sigio): Use gdb_select.
(initialize_stdin_serial): New function.
* terminal.h (initialize_stdin_serial): New prototype.
* top.c (gdb_init): Call initialize_stdin_serial.
* mingw-hdep.c (gdb_select): New function, moved from gdb_select in
event-loop.c. Add exception condition support. Use serial_for_fd
and serial_wait_handle. Fix timeout handling.
* posix-hdep.c: Include "gdb_select.h".
(gdb_select): New function.
* remote-st.c (connect_command): Use gdb_select.
* ser-unix.c: Include "gdb_select.h".
(hardwire_send_break, wait_for): Use gdb_select.
2006-02-10 22:01:43 +00:00
|
|
|
#endif /* USE_WIN32API */
|
2009-01-06 17:07:08 +00:00
|
|
|
|
|
|
|
add_prefix_cmd ("tcp", class_maintenance, set_tcp_cmd, _("\
|
|
|
|
TCP protocol specific variables\n\
|
|
|
|
Configure variables specific to remote TCP connections"),
|
|
|
|
&tcp_set_cmdlist, "set tcp ",
|
|
|
|
0 /* allow-unknown */, &setlist);
|
|
|
|
add_prefix_cmd ("tcp", class_maintenance, show_tcp_cmd, _("\
|
|
|
|
TCP protocol specific variables\n\
|
|
|
|
Configure variables specific to remote TCP connections"),
|
|
|
|
&tcp_show_cmdlist, "show tcp ",
|
|
|
|
0 /* allow-unknown */, &showlist);
|
|
|
|
|
|
|
|
add_setshow_boolean_cmd ("auto-retry", class_obscure,
|
|
|
|
&tcp_auto_retry, _("\
|
|
|
|
Set auto-retry on socket connect"), _("\
|
|
|
|
Show auto-retry on socket connect"),
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
&tcp_set_cmdlist, &tcp_show_cmdlist);
|
|
|
|
|
|
|
|
add_setshow_uinteger_cmd ("connect-timeout", class_obscure,
|
|
|
|
&tcp_retry_limit, _("\
|
|
|
|
Set timeout limit for socket connection"), _("\
|
|
|
|
Show timeout limit for socket connection"),
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
&tcp_set_cmdlist, &tcp_show_cmdlist);
|
1999-04-16 01:35:26 +00:00
|
|
|
}
|