Starting on push/pull example
This commit is contained in:
parent
fc056f0d8b
commit
b612f4dfc6
1
zeromq/.gitignore
vendored
1
zeromq/.gitignore
vendored
@ -2,3 +2,4 @@ hwserver
|
||||
hwclient
|
||||
wuserver
|
||||
wuclient
|
||||
taskvent
|
||||
|
@ -1,13 +1,14 @@
|
||||
CFLAGS += -I. -I/usr/local/include
|
||||
LDFLAGS += -lstdc++ -lpthread -luuid -lrt
|
||||
LIBZMQ := /usr/local/lib/libzmq.a
|
||||
TARGETS := hwserver hwclient wuserver wuclient taskvent
|
||||
|
||||
|
||||
%:%.c
|
||||
$(CC) $(CFLAGS) -o $@ $^ $(LIBZMQ) $(LDFLAGS)
|
||||
|
||||
|
||||
all: hwserver hwclient wuserver wuclient
|
||||
all: $(TARGETS)
|
||||
|
||||
|
||||
.PHONY: all
|
||||
|
37
zeromq/taskvent.c
Normal file
37
zeromq/taskvent.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user