Permalink
Browse files

Add missing command frame handling

  • Loading branch information...
1 parent 7d6bcfc commit d172823660d667f7277a5dbf10c23d5017f802a8 @akitada akitada committed Mar 30, 2013
Showing with 13 additions and 4 deletions.
  1. +1 −1 libmdp/include/mdp_client.h
  2. +8 −1 libmdp/src/mdp_client.c
  3. +1 −1 libmdp/src/test_client.c
  4. +3 −1 libmdp/src/trader.c
@@ -49,7 +49,7 @@ CZMQ_EXPORT int
CZMQ_EXPORT void
mdp_client_send (mdp_client_t *self, char *service, zmsg_t **request_p);
CZMQ_EXPORT zmsg_t *
- mdp_client_recv (mdp_client_t *self, char **service_p);
+ mdp_client_recv (mdp_client_t *self, char **command_p, char **service_p);
// @end
View
@@ -153,7 +153,7 @@ mdp_client_send (mdp_client_t *self, char *service, zmsg_t **request_p)
// to service string. It is caller's responsibility to free it.
zmsg_t *
-mdp_client_recv (mdp_client_t *self, char **service_p)
+mdp_client_recv (mdp_client_t *self, char **command_p, char **service_p)
{
assert (self);
@@ -185,6 +185,13 @@ mdp_client_recv (mdp_client_t *self, char **service_p)
assert (zframe_streq (header, MDPC_CLIENT));
zframe_destroy (&header);
+ zframe_t *command = zmsg_pop (msg);
+ assert (zframe_streq (command, MDPC_REPORT) ||
+ zframe_streq (command, MDPC_NAK));
+ if (command_p)
+ *command_p = zframe_strdup (command);
+ zframe_destroy (&command);
+
zframe_t *service = zmsg_pop (msg);
if (service_p)
*service_p = zframe_strdup (service);
View
@@ -14,7 +14,7 @@ int main (int argc, char *argv [])
zmsg_t *request = zmsg_new ();
zmsg_pushstr (request, "Hello world");
mdp_client_send (session, "echo", &request);
- zmsg_t *reply = mdp_client_recv (session, NULL);
+ zmsg_t *reply = mdp_client_recv (session, NULL, NULL);
if (reply)
zmsg_destroy (&reply);
else
View
@@ -30,8 +30,9 @@ int main (int argc, char *argv [])
// Wait for all trading reports
while (1) {
+ char *command = NULL;
char *service = NULL;
- zmsg_t *report = mdp_client_recv (client, &service);
+ zmsg_t *report = mdp_client_recv (client, &command, &service);
if (report == NULL)
break;
assert (zmsg_size (report) >= 2);
@@ -44,6 +45,7 @@ int main (int argc, char *argv [])
printf ("%s: %s %s shares\n", service, report_type_str, volume_str);
+ free (command);
free (service);
free (report_type_str);
free (volume_str);

0 comments on commit d172823

Please sign in to comment.