aboutsummaryrefslogtreecommitdiff
path: root/gdb/ser-tcp.c
diff options
context:
space:
mode:
authorStu Grossman <grossman@cygnus>1993-06-26 00:22:30 +0000
committerStu Grossman <grossman@cygnus>1993-06-26 00:22:30 +0000
commita037b21e7588263dba78ac0b1651abd56237ca93 (patch)
tree7c35de6074a134ee3c08e439f9b4c3d33c6124dc /gdb/ser-tcp.c
parent2685ead7d6ccad3988f6fbffbc3a96ebada3d4dc (diff)
downloadgdb-a037b21e7588263dba78ac0b1651abd56237ca93.zip
gdb-a037b21e7588263dba78ac0b1651abd56237ca93.tar.gz
gdb-a037b21e7588263dba78ac0b1651abd56237ca93.tar.bz2
* remote.c: Add arg names to prototypes, in a modest effort at
clarification. Also add prototypes for some new functions. * (remote_wait): Better error reporting for 'T' responses. * ser-go32.c (strncasecmp): Make str1 & str2 be const. * (dos_async_init): Make usage message reflect requested port #. * ser-tcp.c (tcp_open): Terminate hostname properly to prevent random hostname lookup failures. Add nicer message for unknown host error. (wait_for): Wake up in case of exceptions. Also, restart select() if we got EINTR. * ser-unix.c (wait_for): Restart select() if we got EINTR. * serial.c: (serial_close): Clean up code.
Diffstat (limited to 'gdb/ser-tcp.c')
-rw-r--r--gdb/ser-tcp.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c
index 3b30bf1..5afe63e 100644
--- a/gdb/ser-tcp.c
+++ b/gdb/ser-tcp.c
@@ -64,14 +64,16 @@ tcp_open(scb, name)
if (!port_str)
error ("tcp_open: No colon in host name!"); /* Shouldn't ever happen */
- tmp = min(port_str - name + 1, sizeof hostname);
- strncpy (hostname, name, tmp - 1); /* Don't want colon */
+ tmp = min (port_str - name, sizeof hostname - 1);
+ strncpy (hostname, name, tmp); /* Don't want colon */
+ hostname[tmp] = '\000'; /* Tie off host name */
port = atoi (port_str + 1);
hostent = gethostbyname (hostname);
if (!hostent)
{
+ fprintf (stderr, "%s: unknown host\n", hostname);
errno = ENOENT;
return -1;
}
@@ -93,9 +95,10 @@ tcp_open(scb, name)
memcpy (&sockaddr.sin_addr.s_addr, hostent->h_addr,
sizeof (struct in_addr));
- if (connect(scb->fd, &sockaddr, sizeof(sockaddr)))
+ if (connect (scb->fd, &sockaddr, sizeof(sockaddr)))
{
close(scb->fd);
+ scb->fd = -1;
return -1;
}
@@ -158,27 +161,34 @@ wait_for(scb, timeout)
{
int numfds;
struct timeval tv;
- fd_set readfds;
+ fd_set readfds, exceptfds;
FD_ZERO (&readfds);
+ FD_ZERO (&exceptfds);
tv.tv_sec = timeout;
tv.tv_usec = 0;
FD_SET(scb->fd, &readfds);
+ FD_SET(scb->fd, &exceptfds);
- if (timeout >= 0)
- numfds = select(scb->fd+1, &readfds, 0, 0, &tv);
- else
- numfds = select(scb->fd+1, &readfds, 0, 0, 0);
-
- if (numfds <= 0)
- if (numfds == 0)
- return SERIAL_TIMEOUT;
- else
- return SERIAL_ERROR; /* Got an error from select or poll */
-
- return 0;
+ while (1)
+ {
+ if (timeout >= 0)
+ numfds = select(scb->fd+1, &readfds, 0, &exceptfds, &tv);
+ else
+ numfds = select(scb->fd+1, &readfds, 0, &exceptfds, 0);
+
+ if (numfds <= 0)
+ if (numfds == 0)
+ return SERIAL_TIMEOUT;
+ else if (errno == EINTR)
+ continue;
+ else
+ return SERIAL_ERROR; /* Got an error from select or poll */
+
+ return 0;
+ }
}
/* Read a character with user-specified timeout. TIMEOUT is number of seconds