From edcd2651f9d3a8bb0961ade1990e602b2dc73cae Mon Sep 17 00:00:00 2001 From: mquinson Date: Mon, 5 Sep 2005 22:46:23 +0000 Subject: [PATCH] Tweak gras_trp_*_recv() prototype. This is now (sock, char*data,int size, int bufsize). Size is the data I absolutely want to get, and buffsize is the size of my buffer in which I copy them. This allows the buffer transport to get more data than mandatory of tcp and file transports (thus minimizing the call to the syscall read() without having to separately exchange the buffer size) git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@1694 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/gras/Transport/transport_interface.h | 3 ++- src/gras/Transport/transport_plugin_buf.c | 10 ++++++---- src/gras/Transport/transport_plugin_file.c | 16 ++++++++++------ src/gras/Transport/transport_plugin_sg.c | 9 +++++++-- src/gras/Transport/transport_plugin_tcp.c | 19 +++++++++++-------- 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/gras/Transport/transport_interface.h b/src/gras/Transport/transport_interface.h index e1e8548cee..249db65393 100644 --- a/src/gras/Transport/transport_interface.h +++ b/src/gras/Transport/transport_interface.h @@ -58,7 +58,8 @@ struct gras_trp_plugin_ { unsigned long int size); void (*chunk_recv)(gras_socket_t sd, char *data, - unsigned long int size); + unsigned long int size, + unsigned long int bufsize); /* flush has to make sure that the pending communications are achieved */ void (*flush)(gras_socket_t sd); diff --git a/src/gras/Transport/transport_plugin_buf.c b/src/gras/Transport/transport_plugin_buf.c index ed64bc3244..0dc830da8d 100644 --- a/src/gras/Transport/transport_plugin_buf.c +++ b/src/gras/Transport/transport_plugin_buf.c @@ -41,7 +41,8 @@ void gras_trp_buf_chunk_send(gras_socket_t sd, void gras_trp_buf_chunk_recv(gras_socket_t sd, char *data, - unsigned long int size); + unsigned long int size, + unsigned long int bufsize); void gras_trp_buf_flush(gras_socket_t sock); @@ -221,7 +222,8 @@ gras_trp_buf_chunk_send(gras_socket_t sock, void gras_trp_buf_chunk_recv(gras_socket_t sock, char *chunk, - unsigned long int size) { + unsigned long int size, + unsigned long int bufsize) { xbt_ex_t e; gras_trp_bufdata_t *data=sock->bufdata; @@ -242,7 +244,7 @@ gras_trp_buf_chunk_recv(gras_socket_t sock, if (gras_if_RL()) { DEBUG0("Recv the size"); TRY { - _buf_super->chunk_recv(sock,(char*)&nextsize, 4); + _buf_super->chunk_recv(sock,(char*)&nextsize, 4,4); } CATCH(e) { RETHROW3("Unable to get the chunk size on %p (peer = %s:%d): %s", sock,gras_socket_peer_name(sock),gras_socket_peer_port(sock)); @@ -253,7 +255,7 @@ gras_trp_buf_chunk_recv(gras_socket_t sock, data->in.size = -1; } - _buf_super->chunk_recv(sock, data->in.data, data->in.size); + _buf_super->chunk_recv(sock, data->in.data, data->in.size, data->in.size); if (gras_if_RL()) { data->in.pos=0; diff --git a/src/gras/Transport/transport_plugin_file.c b/src/gras/Transport/transport_plugin_file.c index a85fa4bdfa..7e7eae0aa5 100644 --- a/src/gras/Transport/transport_plugin_file.c +++ b/src/gras/Transport/transport_plugin_file.c @@ -25,7 +25,8 @@ void gras_trp_file_chunk_send(gras_socket_t sd, void gras_trp_file_chunk_recv(gras_socket_t sd, char *data, - unsigned long int size); + unsigned long int size, + unsigned long int bufsize); /*** @@ -202,16 +203,18 @@ gras_trp_file_chunk_send(gras_socket_t sock, void gras_trp_file_chunk_recv(gras_socket_t sock, char *data, - unsigned long int size) { + unsigned long int size, + unsigned long int bufsize) { xbt_assert0(sock, "Cannot recv on an NULL socket"); xbt_assert0(sock->incoming, "Cannot recv on client file socket"); xbt_assert0(size >= 0, "Cannot receive a negative amount of data"); - + xbt_assert0(bufsize>=size,"Not enough buffer size to receive that much data"); + while (size) { int status = 0; - status = read(sock->sd, data, (long int)size); + status = read(sock->sd, data, (long int)bufsize); DEBUG3("read(%d, %p, %ld);", sock->sd, data, size); if (status == -1) { @@ -221,8 +224,9 @@ gras_trp_file_chunk_recv(gras_socket_t sock, } if (status) { - size -= status; - data += status; + size -= status; + bufsize -= status; + data += status; } else { THROW0(system_error,0,"file descriptor closed"); } diff --git a/src/gras/Transport/transport_plugin_sg.c b/src/gras/Transport/transport_plugin_sg.c index e777b589a7..8c81ca2ad3 100644 --- a/src/gras/Transport/transport_plugin_sg.c +++ b/src/gras/Transport/transport_plugin_sg.c @@ -42,7 +42,8 @@ void gras_trp_sg_chunk_send(gras_socket_t sd, void gras_trp_sg_chunk_recv(gras_socket_t sd, char *data, - unsigned long int size); + unsigned long int size, + unsigned long int bufsize); /*** *** Specific plugin part @@ -242,6 +243,8 @@ void gras_trp_sg_chunk_send(gras_socket_t sock, gras_trp_sg_sock_data_t *sock_data = (gras_trp_sg_sock_data_t *)sock->data; sg_task_data_t *task_data; + xbt_assert0(sock->meas, "SG chunk exchange shouldn't be used on non-measurement sockets"); + sprintf(name,"Chunk[%d]",count++); task_data=xbt_new(sg_task_data_t,1); @@ -261,13 +264,15 @@ void gras_trp_sg_chunk_send(gras_socket_t sock, void gras_trp_sg_chunk_recv(gras_socket_t sock, char *data, - unsigned long int size){ + unsigned long int size, + unsigned long int bufsize){ gras_trp_procdata_t pd=(gras_trp_procdata_t)gras_libdata_get("gras_trp"); m_task_t task=NULL; sg_task_data_t *task_data; gras_trp_sg_sock_data_t *sock_data = sock->data; + xbt_assert0(sock->meas, "SG chunk exchange shouldn't be used on non-measurement sockets"); XBT_IN; DEBUG4("recv chunk on %s -> %s:%d (size=%ld)", MSG_host_get_name(sock_data->to_host), diff --git a/src/gras/Transport/transport_plugin_tcp.c b/src/gras/Transport/transport_plugin_tcp.c index 51f44fa65f..21cdf355db 100644 --- a/src/gras/Transport/transport_plugin_tcp.c +++ b/src/gras/Transport/transport_plugin_tcp.c @@ -34,7 +34,8 @@ void gras_trp_tcp_chunk_send(gras_socket_t sd, void gras_trp_tcp_chunk_recv(gras_socket_t sd, char *data, - unsigned long int size); + unsigned long int size, + unsigned long int bufsize); void gras_trp_tcp_exit(gras_trp_plugin_t plug); @@ -328,17 +329,19 @@ gras_trp_tcp_chunk_send(gras_socket_t sock, void gras_trp_tcp_chunk_recv(gras_socket_t sock, char *data, - unsigned long int size) { + unsigned long int size, + unsigned long int bufsize) { /* TCP sockets are in duplex mode, don't check direction */ xbt_assert0(sock, "Cannot recv on an NULL socket"); xbt_assert0(size >= 0, "Cannot receive a negative amount of data"); + xbt_assert0(bufsize>=size,"Not enough buffer size to receive that much data"); while (size) { int status = 0; DEBUG3("read(%d, %p, %ld);", sock->sd, data, size); - status = tcp_read(sock->sd, data, (size_t)size); + status = tcp_read(sock->sd, data, (size_t)bufsize); if (status < 0) { THROW4(system_error,0,"read(%d,%p,%d) failed: %s", @@ -347,12 +350,12 @@ gras_trp_tcp_chunk_recv(gras_socket_t sock, } if (status) { - size -= status; - data += status; + size -= status; + bufsize -= status; + data += status; } else { - THROW3(system_error,0, - "file descriptor closed (nothing read(%d, %p, %ld) on the socket)", - sock->sd, data, size); + gras_socket_close(sock); + THROW0(system_error,0,"Socket closed by remote side"); } } } -- 2.20.1