@@ -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