38 lines
881 B
C
38 lines
881 B
C
|
#include "zhelpers.h"
|
||
|
|
||
|
int main(void)
|
||
|
{
|
||
|
void *context = zmq_init(1);
|
||
|
|
||
|
void *sender = zmq_socket(context, ZMQ_PUSH);
|
||
|
zmq_bind(sender, "tcp://*:5557");
|
||
|
|
||
|
void *sink = zmq_socket(context, ZMQ_PUSH);
|
||
|
zmq_connect(sink, "tcp://localhost:5558");
|
||
|
|
||
|
printf("Press Enter when the workers are ready: ");
|
||
|
getchar();
|
||
|
printf("Sending tasks to workers...\n");
|
||
|
|
||
|
s_send(sink, "0");
|
||
|
srandom((unsigned) time(NULL));
|
||
|
|
||
|
int task_nbr;
|
||
|
int total_msec = 0;
|
||
|
for (task_nbr = 0; task_nbr < 100; task_nbr++) {
|
||
|
int workload;
|
||
|
workload = randof(100) + 1;
|
||
|
total_msec += workload;
|
||
|
char string[10];
|
||
|
sprintf(string, "%d", workload);
|
||
|
s_send(sender, string);
|
||
|
}
|
||
|
printf("Total expected cost: %d msec\n", total_msec);
|
||
|
sleep(1);
|
||
|
|
||
|
zmq_close(sink);
|
||
|
zmq_close(sender);
|
||
|
zmq_term(context);
|
||
|
return 0;
|
||
|
}
|