/*
- * $Source$
- * $Header$
+ * $Source$
+ * $Header$
*/
#ifndef lint
static char *rcsid_gdb_conn_c = "$Header$";
#endif lint
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/************************************************************************/
-/*
-/* gdb_conn.c
-/*
-/* GDB - Connection Management Services
-/*
-/* Author: Noah Mendelsohn
-/* Copyright: 1986 MIT Project Athena
-/* For copying and distribution information, please see
-/* the file <mit-copyright.h>.
-/*
-/* Routines used in the creation and maintenance of CONNECTIONS.
-/* Note: these are closely related to the services provided
-/* by gdb_trans.c and gdb_trans2.c.
-/*
-/*
-/************************************************************************/
+/************************************************************************
+ *
+ * gdb_conn.c
+ *
+ * GDB - Connection Management Services
+ *
+ * Author: Noah Mendelsohn
+ * Copyright: 1986 MIT Project Athena
+ * For copying and distribution information, please see
+ * the file <mit-copyright.h>.
+ *
+ * Routines used in the creation and maintenance of CONNECTIONS.
+ * Note: these are closely related to the services provided
+ * by gdb_trans.c and gdb_trans2.c.
+ *
+ *
+ ************************************************************************/
#include <mit-copyright.h>
#include <stdio.h>
-#include <strings.h>
+#include <string.h>
#include "gdb.h"
#include <sys/types.h>
#include <sys/uio.h>
#include <netinet/in.h>
#include <netdb.h>
#include <errno.h>
+#ifdef SOLARIS
+#include <sys/filio.h>
+#endif /* SOLARIS */
extern int errno;
#ifdef vax
CONNECTION gdb_allocate_connection();
-/************************************************************************/
-/*
-/* start_peer_connection (start_peer_connection)
-/*
-/* Starts a connection to another process which itself will be
-/* issuing a start_peer_connection to us. Current implementation
-/* builds at most one stream, with the risk of a hang if
-/* the attempts to connect cross in the night. This is a bug,
-/* but this level of support is acceptable for casual debugging
-/* of applications, and perhaps for some production use in
-/* controlled settings. I think the only other way to do it
-/* is to risk building two streams in parallel, possibly tearing
-/* one down when the duplication is discovered. Seems complicated
-/* and messy.
-/*
-/************************************************************************/
+/************************************************************************
+ *
+ * start_peer_connection (start_peer_connection)
+ *
+ * Starts a connection to another process which itself will be
+ * issuing a start_peer_connection to us. Current implementation
+ * builds at most one stream, with the risk of a hang if
+ * the attempts to connect cross in the night. This is a bug,
+ * but this level of support is acceptable for casual debugging
+ * of applications, and perhaps for some production use in
+ * controlled settings. I think the only other way to do it
+ * is to risk building two streams in parallel, possibly tearing
+ * one down when the duplication is discovered. Seems complicated
+ * and messy.
+ *
+ ************************************************************************/
CONNECTION
start_peer_connection(id)
} else
return NULL;
}
-\f
+
+
/************************************************************************/
/*
/* g_make_con
}
-\f/************************************************************************/
+
+/************************************************************************/
/*
/* g_null_con
/*
}
-\f
+
/************************************************************************/
/*
/* gdb_allocate_connection
return &gdb_cons[i]; /* return new highest con */
/* ever used*/
}
-\f
+
+
/************************************************************************/
/*
/* g_try_connecting
{
int peer; /* socket for talking to
peer */
+ int on = 1; /* flag for ioctl */
struct sockaddr_in target; /* build the peer address */
/* here */
struct hostent *peer_host; /* host where peer is */
/*
/*----------------------------------------------------------*/
- bzero((char *)&target, sizeof(target));
+ memset((char *)&target, 0, sizeof(target));
g_parse_target(id, &peer_host, &target.sin_port);
if (peer_host == NULL) {
fprintf(gdb_log,"gdb: g_try_connecting... '%s' is not a valid host:server\n",
/*----------------------------------------------------------*/
- bcopy(peer_host->h_addr, (char *)&target.sin_addr, peer_host->h_length);
+ memcpy((char *)&target.sin_addr,peer_host->h_addr,peer_host->h_length);
target.sin_family = peer_host->h_addrtype;
/*----------------------------------------------------------*/
}
}
+ if ((gdb_Options & GDB_OPT_KEEPALIVE) &&
+ setsockopt(peer, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)) < 0) {
+ gdb_perror("gdb: unable to start keepalives");
+ g_stop_with_errno(con);
+ return(TRUE);
+ }
+
/*----------------------------------------------------------*/
/*
/* The connection has been made, fill in the connection
return TRUE;
}
-\f
+
+
/************************************************************************/
/*
/* g_parse_target
*port = serv->s_port;
}
}
-\f
+
+
/************************************************************************/
/*
/* g_try_accepting
/*
/*----------------------------------------------------------*/
- bzero((char *)&self, sizeof(self));
+ memset((char *)&self, 0, sizeof(self));
g_parse_target(id, &peer_host, &self.sin_port);
if (peer_host == NULL) {
GDB_GIVEUP("gdb_try_accepting: bad port not caught by try connecting")
con->out.fd = peer;
con->status = CON_STARTING;
}
-\f
+
+
/************************************************************************/
/*
/* g_ver_oprotocol
#endif !VERIFY_PROTOCOL
}
+
/************************************************************************/
/*
/* g_ver_iprotocol
#endif
}
-\f
+
/************************************************************************/
/*
/* sever_connection (sever_connection)
return NULL;
}
+
/************************************************************************/
/*
/* g_stop_with_errno
/*
/************************************************************************/
-
int
g_stop_with_errno(con)
CONNECTION con;
}
+
/************************************************************************/
/*
/* g_stop_connection
/*
* Remove the file descriptor from the select bit maps
*/
- if (!(con->in.flags & HCON_UNUSED))
+ if (!(con->in.flags & HCON_UNUSED) && con->in.fd >= 0)
FD_CLR(con->in.fd, &gdb_crfds);
- if (!(con->out.flags & HCON_UNUSED))
+ if (!(con->out.flags & HCON_UNUSED) && con->out.fd >= 0)
FD_CLR(con->out.fd, &gdb_cwfds);
/*
* Close the file descriptor. Note, this presumes that in fact
return;
}
-\f
+
/************************************************************************/
/*
/* gdb_de_allocate_connection
gdb_mcons = i + 1;
}
-\f
+
+
/************************************************************************/
/*
/* g_cleanup_half_conection
current = next;
}
}
-\f
+
+
/************************************************************************/
/*
/* create_listening_connection (create_listening_connection)
/*
/*----------------------------------------------------------*/
- bzero((char *)&self, sizeof(self));
+ memset((char *)&self, 0, sizeof(self));
/*
* Determine our port number
*/
gdb_mfd = con->in.fd + 1;
return con;
}
-\f
+
+
/************************************************************************/
/*
/* g_allocate_connection_buffers