#include "portable.h"
#if 0
-# include <unistd.h> /* close() pipe() read() write() */
# include <signal.h> /* close() pipe() read() write() */
-# include <netinet/in.h> /* sometimes required for #include <arpa/inet.h> */
-# include <netinet/tcp.h> /* TCP_NODELAY */
-# include <arpa/inet.h> /* inet_ntoa() */
-# include <netdb.h> /* getprotobyname() */
-# include <sys/time.h> /* struct timeval */
-# include <errno.h> /* errno */
# include <sys/wait.h> /* waitpid() */
-# include <sys/socket.h> /* getpeername() socket() */
-# include <stdlib.h>
-# include <string.h> /* memset */
#endif
typedef struct {
fd_set msg_socks;
- fd_set raw_socks;
+ fd_set meas_socks;
} gras_trp_tcp_plug_data_t;
/***
gras_trp_tcp_plug_data_t *data = xbt_new(gras_trp_tcp_plug_data_t,1);
FD_ZERO(&(data->msg_socks));
- FD_ZERO(&(data->raw_socks));
+ FD_ZERO(&(data->meas_socks));
plug->socket_client = gras_trp_tcp_socket_client;
plug->socket_server = gras_trp_tcp_socket_server;
void gras_trp_tcp_exit(gras_trp_plugin_t *plug) {
DEBUG1("Exit plugin TCP (free %p)", plug->data);
- xbt_free(plug->data);
+ free(plug->data);
}
xbt_error_t gras_trp_tcp_socket_client(gras_trp_plugin_t *self,
addr.sin_family = AF_INET;
addr.sin_port = htons (sock->peer_port);
+ DEBUG2("Connect to %s:%d",sock->peer_name, sock->peer_port);
if (connect (sock->sd, (struct sockaddr*) &addr, sizeof (addr)) < 0) {
tcp_close(sock->sd);
RAISE3(system_error,
RAISE2(system_error,"Cannot bind to port %d: %s",sock->port, sock_errstr);
}
+ DEBUG1("Listen on port %d",sock->port);
if (listen(sock->sd, 5) < 0) {
tcp_close(sock->sd);
- RAISE2(system_error,"Cannot listen to port %d: %s",sock->port,sock_errstr);
+ RAISE2(system_error,"Cannot listen on port %d: %s",sock->port,sock_errstr);
}
- if (sock->raw)
- FD_SET(sock->sd, &(tcp->raw_socks));
+ if (sock->meas)
+ FD_SET(sock->sd, &(tcp->meas_socks));
else
FD_SET(sock->sd, &(tcp->msg_socks));
sd = accept(sock->sd, (struct sockaddr *)&peer_in, &peer_in_len);
tmp_errno = errno;
- if(sd == -1) {
+ if (sd == -1) {
gras_socket_close(sock);
RAISE1(system_error,
"Accept failed (%s). Droping server socket.", sock_errstr);
}
}
- VERB3("accepted socket %d to %s:%d", sd, res->peer_name,res->peer_port);
+ VERB3("Accepted socket %d to %s:%d", sd, res->peer_name,res->peer_port);
*dst = res;
/* forget about the socket
... but not when using winsock since accept'ed socket can not fit
into the fd_set*/
- if (sock->raw){
- FD_CLR(sock->sd, &(tcp->raw_socks));
+ if (sock->meas){
+ FD_CLR(sock->sd, &(tcp->meas_socks));
} else {
FD_CLR(sock->sd, &(tcp->msg_socks));
}
status = tcp_write(sock->sd, data, (size_t)size);
DEBUG3("write(%d, %p, %ld);", sock->sd, data, size);
- if (status <= 0) {
+ if (status < 0) {
RAISE4(system_error,"write(%d,%p,%ld) failed: %s",
sock->sd, data, size,
sock_errstr);
size -= status;
data += status;
} else {
- RAISE0(system_error,"file descriptor closed");
+ RAISE1(system_error,"file descriptor closed (%s)",
+ sock_errstr);
}
}
status = tcp_read(sock->sd, data, (size_t)size);
DEBUG3("read(%d, %p, %ld);", sock->sd, data, size);
- if (status <= 0) {
+ if (status < 0) {
RAISE4(system_error,"read(%d,%p,%d) failed: %s",
sock->sd, data, (int)size,
sock_errstr);
size -= status;
data += status;
} else {
- RAISE0(system_error,"file descriptor closed");
+ RAISE0(system_error,"file descriptor closed (nothing read on the socket)");
}
}
return returnValue;
}
-/* Data exchange over raw sockets. Placing this in there is a kind of crude hack.
- It means that the only possible raw are TCP where we may want to do UDP for them.
+#if 0 /* KILLME */
+/* Data exchange over measurement sockets. Placing this in there is a kind of crude hack.
+ It means that the only possible measurement sockets are TCP where we may want to do UDP for them.
But I fail to find a good internal organization for now. We may want to split
- raw and regular sockets more efficiently.
+ meas and regular sockets more efficiently.
*/
-xbt_error_t gras_socket_raw_exchange(gras_socket_t peer,
+xbt_error_t gras_socket_meas_exchange(gras_socket_t peer,
int sender,
unsigned int timeout,
unsigned long int exp_size,
}
if (res_last == 0) {
/* No progress done, bail out */
- xbt_free(chunk);
+ free(chunk);
RAISE0(unknown_error,"Not exchanged a single byte, bailing out");
}
}
}
- xbt_free(chunk);
+ free(chunk);
return no_error;
}
-
+#endif
#ifdef HAVE_WINSOCK_H
#define RETSTR( x ) case x: return #x