1 /* Copyright (c) 2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include <sys/types.h>
11 #include <sys/socket.h>
15 #include "mc_protocol.h"
16 #include "mc_client.h"
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_protocol, mc, "Generic MC protocol logic");
20 int MC_protocol_send(int socket, void* message, size_t size)
22 while (send(socket, message, size, 0) == -1) {
31 int MC_protocol_send_simple_message(int socket, int type)
33 s_mc_message_t message;
35 return MC_protocol_send(socket, &message, sizeof(message));
38 int MC_protocol_hello(int socket)
41 if ((e = MC_protocol_send_simple_message(socket, MC_MESSAGE_HELLO)) != 0) {
42 XBT_ERROR("Could not send HELLO message: %s", strerror(e));
46 s_mc_message_t message;
47 message.type = MC_MESSAGE_NONE;
50 while ((s = recv(socket, &message, sizeof(message), 0)) == -1) {
54 XBT_ERROR("Could not receive HELLO message: %s", strerror(errno));
58 if (s < sizeof(message) || message.type != MC_MESSAGE_HELLO) {
59 XBT_ERROR("Did not receive suitable HELLO message. Who are you?");