X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/3c5b31c9766da42c82473b8c9dbf5910b74f3cb0..9b7c007d68cc9aabd52746479c68a8287a087fe3:/src/mc/mc_protocol.c diff --git a/src/mc/mc_protocol.c b/src/mc/mc_protocol.c index 3396a38396..0034148403 100644 --- a/src/mc/mc_protocol.c +++ b/src/mc/mc_protocol.c @@ -13,15 +13,13 @@ #include #include "mc_protocol.h" +#include "mc_client.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_protocol, mc, "Generic MC protocol logic"); -int MC_protocol_send_simple_message(int socket, int type) +int MC_protocol_send(int socket, void* message, size_t size) { - s_mc_message_t message; - message.type = type; - - while (send(socket, &message, sizeof(message), 0) == -1) { + while (send(socket, message, size, 0) == -1) { if (errno == EINTR) continue; else @@ -30,6 +28,13 @@ int MC_protocol_send_simple_message(int socket, int type) return 0; } +int MC_protocol_send_simple_message(int socket, int type) +{ + s_mc_message_t message; + message.type = type; + return MC_protocol_send(socket, &message, sizeof(message)); +} + int MC_protocol_hello(int socket) { int e; @@ -41,7 +46,8 @@ int MC_protocol_hello(int socket) s_mc_message_t message; message.type = MC_MESSAGE_NONE; - while (recv(socket, &message, sizeof(message), 0) == -1) { + size_t s; + while ((s = recv(socket, &message, sizeof(message), 0)) == -1) { if (errno == EINTR) continue; else { @@ -49,10 +55,15 @@ int MC_protocol_hello(int socket) return 2; } } - if (message.type != MC_MESSAGE_HELLO) { + if (s < sizeof(message) || message.type != MC_MESSAGE_HELLO) { XBT_ERROR("Did not receive suitable HELLO message. Who are you?"); return 3; } return 0; } + +ssize_t MC_receive_message(int socket, void* message, size_t size) +{ + return recv(socket, message, size, 0); +}