Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved the blaster

  • Loading branch information...
commit 784fbd7cfb7632f0e839c237f6720c65fe955210 1 parent 4a747d0
@hintjens hintjens authored
Showing with 18 additions and 17 deletions.
  1. +14 −12 209/2-1/hwserver.c
  2. +4 −5 209/blast.c
View
26 209/2-1/hwserver.c
@@ -11,23 +11,25 @@ int main (void)
void *responder = zmq_socket (context, ZMQ_REP);
zmq_bind (responder, "tcp://*:5560");
+ int count = 0;
while (1) {
// Wait for next request from client
zmq_msg_t request;
zmq_msg_init (&request);
- zmq_recv (responder, &request, 0);
- printf ("Received Hello\n");
- zmq_msg_close (&request);
+ if (zmq_recv (responder, &request, 0) == 0) {
+ printf ("Received message %d\n", ++count);
+ zmq_msg_close (&request);
- // Do some 'work'
- sleep (1);
-
- // Send reply back to client
- zmq_msg_t reply;
- zmq_msg_init_size (&reply, 5);
- memcpy (zmq_msg_data (&reply), "World", 5);
- zmq_send (responder, &reply, 0);
- zmq_msg_close (&reply);
+ // Send reply back to client
+ zmq_msg_t reply;
+ zmq_msg_init_size (&reply, 5);
+ memcpy (zmq_msg_data (&reply), "World", 5);
+ zmq_send (responder, &reply, 0);
+ zmq_msg_close (&reply);
+ }
+ else
+ if (errno != EFAULT)
+ fprintf (stderr, "Error: %s\n", zmq_strerror (errno));
}
// We never get here but if we did, this would be how we end
zmq_close (responder);
View
9 209/blast.c
@@ -64,14 +64,13 @@ int main (void)
int byte_nbr;
for (byte_nbr = 0; byte_nbr < BLOCKSIZE; byte_nbr++)
block [byte_nbr] = randof (256);
-
rc = write (handle, block, BLOCKSIZE);
- if (rc != BLOCKSIZE) {
- printf ("Test failed at count %d\n", block_nbr);
+ if (rc == -1) {
+ fprintf (stderr, "Test failed at count %d\n", block_nbr);
break;
}
}
if (block_nbr == BLOCKS)
- printf ("Successful!\n");
+ fprintf (stderr, "Successful!\n");
return 0;
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.