Skip to content

Commit fca6b92

Browse files
committed
BF: lab.separate() now works
1 parent 79ce368 commit fca6b92

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

pymatbridge/matlab/matlabserver.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function matlabserver(socket_address, exit_when_done)
3131

3232
case {'separate'}
3333
desktop; %no-op if desktop is already up
34+
exit_when_done = false;
3435
break;
3536

3637
otherwise
@@ -40,14 +41,16 @@ function matlabserver(socket_address, exit_when_done)
4041
end
4142

4243
if nargin > 1 && exit_when_done
43-
c.task();
44+
%c.task(); % already executed by "finish"
4445
exit;
4546
end
4647

4748
end %matlabserver
4849

4950
function stop_messenger()
50-
messenger('exit');
51+
if messenger('check')
52+
messenger('exit');
53+
end
5154
end
5255

5356
function initialize_environment()
24 Bytes
Binary file not shown.

pymatbridge/messenger/src/messenger.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void mexFunction(int nlhs, mxArray *plhs[],
7171
/* we'll return true on completion of valid command, else false */
7272
plhs[0] = mxCreateLogicalMatrix(1, 1);
7373
p = mxGetLogicals(plhs[0]);
74-
p[0] = 0;
74+
p[0] = false;
7575
/* Initialize a new server session */
7676
if (strcmp(cmd, "init") == 0) {
7777
char *socket_addr;
@@ -84,7 +84,7 @@ void mexFunction(int nlhs, mxArray *plhs[],
8484
}
8585
if (!initialized) {
8686
if (!initialize(socket_addr)) {
87-
p[0] = 1;
87+
p[0] = true;
8888
mexPrintf("Socket created at: %s\n", socket_addr);
8989
} else {
9090
mexErrMsgTxt("Socket creation failed.");
@@ -116,12 +116,11 @@ void mexFunction(int nlhs, mxArray *plhs[],
116116
sprintf(recv_buffer, "Failed to receive a message due to ZMQ error %s", strerror(errno));
117117
mexErrMsgTxt(recv_buffer);
118118
}
119-
p[0] = 1;
119+
p[0] = true;
120120
/* Send a message out */
121121
} else if (strcmp(cmd, "respond") == 0) {
122122
size_t msglen;
123123
char *msg_out;
124-
mxLogical *p;
125124

126125
/* Check if the input format is valid */
127126
if (nrhs != 2) {
@@ -133,25 +132,23 @@ void mexFunction(int nlhs, mxArray *plhs[],
133132
msglen = mxGetNumberOfElements(prhs[1]);
134133
msg_out = mxArrayToString(prhs[1]);
135134

136-
plhs[0] = mxCreateLogicalMatrix(1, 1);
137-
p = mxGetLogicals(plhs[0]);
138-
139135
if (msglen == (size_t) zmq_send(socket_ptr, msg_out, msglen, 0)) {
140-
p[0] = 1;
136+
p[0] = true;
141137
} else {
142138
mexErrMsgTxt("Failed to send message due to ZMQ error");
143139
}
144140
/* Close the socket and context */
145141
} else if (strcmp(cmd, "exit") == 0) {
146142
if (initialized) {
147143
cleanup();
148-
p[0] = 1;
144+
p[0] = true;
145+
initialized = 0;
149146
} else {
150147
mexErrMsgTxt("No open socket to exit.");
151148
}
152149
} else if (strcmp(cmd, "check") == 0) {
153150
if (initialized) {
154-
p[0] = 1;
151+
p[0] = true;
155152
}
156153
} else {
157154
mexErrMsgTxt("Unidentified command");

0 commit comments

Comments
 (0)