Filling in taskwork and tasksink parts of PUSH/PULL example

This commit is contained in:
Dan Buch 2012-03-18 17:13:17 -04:00
parent b612f4dfc6
commit 1a278e5ae3
4 changed files with 62 additions and 1 deletions

2
zeromq/.gitignore vendored
View File

@ -3,3 +3,5 @@ hwclient
wuserver wuserver
wuclient wuclient
taskvent taskvent
taskwork
tasksink

View File

@ -1,7 +1,7 @@
CFLAGS += -I. -I/usr/local/include CFLAGS += -I. -I/usr/local/include
LDFLAGS += -lstdc++ -lpthread -luuid -lrt LDFLAGS += -lstdc++ -lpthread -luuid -lrt
LIBZMQ := /usr/local/lib/libzmq.a LIBZMQ := /usr/local/lib/libzmq.a
TARGETS := hwserver hwclient wuserver wuclient taskvent TARGETS := hwserver hwclient wuserver wuclient taskvent taskwork tasksink
%:%.c %:%.c

32
zeromq/tasksink.c Normal file
View File

@ -0,0 +1,32 @@
#include "zhelpers.h"
int main(void)
{
void *context = zmq_init(1);
void *receiver = zmq_socket(context, ZMQ_PULL);
zmq_bind(receiver, "tcp://*:5558");
char *string = s_recv(receiver);
free(string);
int64_t start_time = s_clock();
int task_nbr;
for (task_nbr = 0; task_nbr < 100; task_nbr++) {
char *string = s_recv(receiver);
free(string);
if ((task_nbr / 10) * 10 == task_nbr) {
printf(":");
} else {
printf(".");
}
fflush(stdout);
}
printf("Total elapsed time: %d msec\n",
(int) (s_clock() - start_time));
zmq_close(receiver);
zmq_term(context);
return 0;
}

27
zeromq/taskwork.c Normal file
View File

@ -0,0 +1,27 @@
#include "zhelpers.h"
int main(void)
{
void *context = zmq_init(1);
void *receiver = zmq_socket(context, ZMQ_PULL);
zmq_connect(receiver, "tcp://localhost:5557");
void *sender = zmq_socket(context, ZMQ_PUSH);
zmq_connect(sender, "tcp://localhost:5558");
while (1) {
char *string = s_recv(receiver);
fflush(stdout);
printf("%s.", string);
s_sleep(atoi(string));
free(string);
s_send(sender, "");
}
zmq_close(receiver);
zmq_close(sender);
zmq_term(context);
return 0;
}