FD_ZERO(&FDS);
max_fds = -1;
xbt_dynar_foreach(sockets,cursor,sock_iter) {
+ if (!sock_iter->valid)
+ continue;
+
if (sock_iter->incoming) {
DEBUG1("Considering socket %d for select",sock_iter->sd);
#ifndef HAVE_WINSOCK_H
continue; /* this was a timeout */
}
- xbt_dynar_foreach(sockets,cursor,sock_iter) {
+ xbt_dynar_foreach(sockets,cursor,sock_iter) {
if(!FD_ISSET(sock_iter->sd, &FDS)) { /* this socket is not ready */
continue;
}
} else if (recvd == 0) {
/* Connection reset (=closed) by peer. */
DEBUG1("Connection %d reset by peer", sock_iter->sd);
- gras_socket_close(sock_iter);
- cursor--;
+ sock_iter->valid=0; /* don't close it. User may keep references to it */
} else {
/* Got a suited socket ! */
XBT_OUT;
}
- XBT_OUT;
- return NULL;
+ /* No socket found. Maybe we had timeout=0 and nothing to do */
+ DEBUG0("TIMEOUT");
+ THROW0(timeout_error,0,"Timeout");
}
void gras_trp_sg_setup(gras_trp_plugin_t plug) {
gras_socket_t sock=xbt_new0(s_gras_socket_t,1);
- DEBUG1("Create a new socket (%p)", (void*)sock);
+ VERB1("Create a new socket (%p)", (void*)sock);
sock->plugin = NULL;
sock->accepting = incoming ? 1:0;
sock->meas = 0;
sock->recv_ok = 1;
+ sock->valid = 1;
sock->sd = -1;
sock->port = -1;
int cursor;
XBT_IN;
+ VERB1("Close %p",sock);
/* FIXME: Issue an event when the socket is closed */
if (sock) {
xbt_dynar_foreach(sockets,cursor,sock_iter) {
* Freeing procdata for this module
*/
static void gras_trp_procdata_free(void *data) {
- gras_trp_procdata_t res = (gras_trp_procdata_t)data;
-
- xbt_dynar_free(&( res->sockets ));
- free(res->name);
- free(res);
+ gras_trp_procdata_t res = (gras_trp_procdata_t)data;
+
+ xbt_dynar_free(&( res->sockets ));
+ free(res->name);
+ free(res);
+}
+
+void gras_trp_socketset_dump(const char *name) {
+ gras_trp_procdata_t procdata =
+ (gras_trp_procdata_t)gras_libdata_by_id(gras_trp_libdata_id);
+
+ int it;
+ gras_socket_t s;
+
+ INFO1("** Dump the socket set %s",name);
+ xbt_dynar_foreach(procdata->sockets, it, s) {
+ INFO4(" %p -> %s:%d %s",
+ s,gras_socket_peer_name(s),gras_socket_peer_port(s),
+ s->valid?"(valid)":"(peer dead)");
+ }
+ INFO1("** End of socket set %s",name);
}
/*
int accepting :1; /* true if master incoming sock in tcp */
int meas :1; /* true if this is an experiment socket instead of messaging */
int recv_ok :1; /* true if it is valid to recv() on the socket (false if it is a file) */
+ int valid :1; /* false if a select returned that the peer quitted, forcing us to "close" the socket */
unsigned long int buf_size; /* what to say to the OS. field here to remember it when accepting */