A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
(wip) Move the MCed public API in the same file
[simgrid.git]
/
src
/
mc
/
mc_client.c
diff --git
a/src/mc/mc_client.c
b/src/mc/mc_client.c
index
2f30581
..
6a8d4ee
100644
(file)
--- a/
src/mc/mc_client.c
+++ b/
src/mc/mc_client.c
@@
-13,23
+13,27
@@
#include <xbt/log.h>
#include <xbt/sysdep.h>
#include <xbt/log.h>
#include <xbt/sysdep.h>
+#include <xbt/mmalloc.h>
#include "mc_protocol.h"
#include "mc_client.h"
#include "mc_protocol.h"
#include "mc_client.h"
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_client, mc, "MC client logic");
+// We won't need those once the separation MCer/MCed is complete:
+#include "mc_mmalloc.h"
+#include "mc_ignore.h"
+#include "mc_model_checker.h"
-typedef struct s_mc_client {
- int active;
- int fd;
-} s_mc_client_t, mc_client_t;
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_client, mc, "MC client logic");
-
static s_
mc_client_t mc_client;
+mc_client_t mc_client;
void MC_client_init(void)
{
void MC_client_init(void)
{
- mc_client.fd = -1;
- mc_client.active = 1;
+ if (mc_client) {
+ XBT_WARN("MC_client_init called more than once.");
+ return;
+ }
+
char* fd_env = getenv(MC_ENV_SOCKET_FD);
if (!fd_env)
xbt_die("MC socket not found");
char* fd_env = getenv(MC_ENV_SOCKET_FD);
if (!fd_env)
xbt_die("MC socket not found");
@@
-45,26
+49,41
@@
void MC_client_init(void)
xbt_die("Unexpected socket type %i", type);
XBT_DEBUG("Model-checked application found expected socket type");
xbt_die("Unexpected socket type %i", type);
XBT_DEBUG("Model-checked application found expected socket type");
- mc_client.fd = fd;
+ mc_client = xbt_new0(s_mc_client_t, 1);
+ mc_client->fd = fd;
+ mc_client->active = 1;
}
void MC_client_hello(void)
{
XBT_DEBUG("Greeting the MC server");
}
void MC_client_hello(void)
{
XBT_DEBUG("Greeting the MC server");
- if (MC_protocol_hello(mc_client
.
fd) != 0)
+ if (MC_protocol_hello(mc_client
->
fd) != 0)
xbt_die("Could not say hello the MC server");
XBT_DEBUG("Greeted the MC server");
}
xbt_die("Could not say hello the MC server");
XBT_DEBUG("Greeted the MC server");
}
+void MC_client_send_message(void* message, size_t size)
+{
+ if (MC_protocol_send(mc_client->fd, message, size))
+ xbt_die("Could not send message %i", (int) ((mc_message_t)message)->type);
+}
+
void MC_client_handle_messages(void)
{
while (1) {
XBT_DEBUG("Waiting messages from model-checker");
void MC_client_handle_messages(void)
{
while (1) {
XBT_DEBUG("Waiting messages from model-checker");
- s_mc_message_t message;
- if (recv(mc_client.fd, &message, sizeof(message), 0) == -1)
+
+ char message_buffer[MC_MESSAGE_LENGTH];
+ size_t s;
+ if ((s = recv(mc_client->fd, &message_buffer, sizeof(message_buffer), 0)) == -1)
xbt_die("Could not receive commands from the model-checker: %s",
strerror(errno));
xbt_die("Could not receive commands from the model-checker: %s",
strerror(errno));
+
XBT_DEBUG("Receive message from model-checker");
XBT_DEBUG("Receive message from model-checker");
+ s_mc_message_t message;
+ if (s < sizeof(message))
+ xbt_die("Message is too short");
+ memcpy(&message, message_buffer, sizeof(message));
switch (message.type) {
case MC_MESSAGE_CONTINUE:
return;
switch (message.type) {
case MC_MESSAGE_CONTINUE:
return;