Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 4a475ac

Browse files
adeas31OpenModelica-Hudson
authored andcommitted
Improved the ZeroMQ server send method
1 parent 7827a66 commit 4a475ac

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Compiler/Main/Main.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ algorithm
878878
end if;
879879

880880
// Don't allow running omc as root due to security risks.
881-
if System.userIsRoot() and (Flags.isSet(Flags.INTERACTIVE) or Flags.isSet(Flags.INTERACTIVE_CORBA)) then
881+
if System.userIsRoot() and (Flags.isSet(Flags.INTERACTIVE) or Flags.isSet(Flags.INTERACTIVE_CORBA) or Flags.isSet(Flags.INTERACTIVE_ZMQ)) then
882882
Error.addMessage(Error.ROOT_USER_INTERACTIVE, {});
883883
print(ErrorExt.printMessagesStr(false));
884884
fail();

Compiler/runtime/zeromqimpl.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,15 @@ void ZeroMQ_sendReply(void *mmcZmqSocket, const char* reply)
8080
intptr_t zmqSocket = (intptr_t)MMC_FETCH(MMC_OFFSET(MMC_UNTAGPTR(mmcZmqSocket),1));
8181
// send the reply
8282
//fprintf(stdout, "Sending message %s\n", reply);fflush(NULL);
83-
zmq_send((void*)zmqSocket, reply, strlen(reply) + 1, 0);
83+
// Create an empty ZeroMQ message to hold the message part
84+
zmq_msg_t replyMsg;
85+
zmq_msg_init_size(&replyMsg, strlen(reply));
86+
// copy the char* to zmq_msg_t
87+
memcpy(zmq_msg_data(&replyMsg), reply, strlen(reply));
88+
// send the message
89+
zmq_msg_send(&replyMsg, (void*)zmqSocket, 0);
90+
// release the zmq_msg_t
91+
zmq_msg_close(&replyMsg);
8492
}
8593

8694
void ZeroMQ_close(void *mmcZmqSocket)

0 commit comments

Comments
 (0)