#include "xbt/ex.h"
#include "portable.h"
#include "gras/Transport/transport_private.h"
-XBT_LOG_EXTERNAL_CATEGORY(transport);
-XBT_LOG_DEFAULT_CATEGORY(transport);
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(gras_trp);
/**
* gras_trp_select:
while (done == -1) {
if (timeout > 0) { /* did we timeout already? */
now = gras_os_time();
+ DEBUG2("wakeup=%f now=%f",wakeup, now);
if (now == -1 || now >= wakeup) {
- done = 0; /* didn't find anything */
- break;
+ /* didn't find anything */
+ THROW1(timeout_error,0,
+ "Timeout (%f) elapsed with selecting for incomming connexions",
+ timeout);
}
}
if (timeout > 0) {
/* set the timeout */
- tout.tv_sec = (unsigned long)((wakeup - now)/1000000);
- tout.tv_usec = (unsigned long)(wakeup - now) % 1000000;
+ tout.tv_sec = (unsigned long)(wakeup - now);
+ tout.tv_usec = ((wakeup -now) - ((unsigned long)(wakeup - now))) * 1000000;
p_tout = &tout;
} else if (timeout == 0) {
/* polling only */
p_tout = NULL;
}
- DEBUG1("Selecting over %d socket(s)", max_fds-1);
+ DEBUG2("Selecting over %d socket(s); timeout=%f", max_fds-1,timeout);
ready = select(max_fds, &FDS, NULL, NULL, p_tout);
+ DEBUG1("select returned %d", ready);
if (ready == -1) {
switch (errno) {
case EINTR: /* a signal we don't care about occured. we don't care */
accepted = (sock_iter->plugin->socket_accept)(sock_iter);
DEBUG2("accepted=%p,&accepted=%p",accepted,&accepted);
accepted->meas = sock_iter->meas;
- } else {
-#if 0
- FIXME: this fails of files. quite logical
+
+ } else if (sock_iter->recv_ok) {
/* Make sure the socket is still alive by reading the first byte */
char lookahead;
int recvd;
if (recvd < 0) {
WARN2("socket %d failed: %s", sock_iter->sd, strerror(errno));
/* done with this socket */
- gras_socket_close(&sock_iter);
+ gras_socket_close(sock_iter);
cursor--;
} else if (recvd == 0) {
/* Connection reset (=closed) by peer. */
DEBUG1("Connection %d reset by peer", sock_iter->sd);
- gras_socket_close(&sock_iter);
+ gras_socket_close(sock_iter);
cursor--;
} else {
-#endif
/* Got a suited socket ! */
XBT_OUT;
return sock_iter;
-#if 0
}
-#endif
+
+ } else {
+ /* This is a file socket. Cannot recv() on it, but it must be alive */
+ XBT_OUT;
+ return sock_iter;
}