Starting on push/pull example

This commit is contained in:
Dan Buch 2012-03-18 13:49:50 -04:00
parent fc056f0d8b
commit b612f4dfc6
3 changed files with 40 additions and 1 deletions

1
zeromq/.gitignore vendored
View File

@ -2,3 +2,4 @@ hwserver
hwclient hwclient
wuserver wuserver
wuclient wuclient
taskvent

View File

@ -1,13 +1,14 @@
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
%:%.c %:%.c
$(CC) $(CFLAGS) -o $@ $^ $(LIBZMQ) $(LDFLAGS) $(CC) $(CFLAGS) -o $@ $^ $(LIBZMQ) $(LDFLAGS)
all: hwserver hwclient wuserver wuclient all: $(TARGETS)
.PHONY: all .PHONY: all

37
zeromq/taskvent.c Normal file
View File

@ -0,0 +1,37 @@
#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;
}