Filling in taskwork and tasksink parts of PUSH/PULL example
This commit is contained in:
parent
b612f4dfc6
commit
1a278e5ae3
2
zeromq/.gitignore
vendored
2
zeromq/.gitignore
vendored
@ -3,3 +3,5 @@ hwclient
|
||||
wuserver
|
||||
wuclient
|
||||
taskvent
|
||||
taskwork
|
||||
tasksink
|
||||
|
@ -1,7 +1,7 @@
|
||||
CFLAGS += -I. -I/usr/local/include
|
||||
LDFLAGS += -lstdc++ -lpthread -luuid -lrt
|
||||
LIBZMQ := /usr/local/lib/libzmq.a
|
||||
TARGETS := hwserver hwclient wuserver wuclient taskvent
|
||||
TARGETS := hwserver hwclient wuserver wuclient taskvent taskwork tasksink
|
||||
|
||||
|
||||
%:%.c
|
||||
|
32
zeromq/tasksink.c
Normal file
32
zeromq/tasksink.c
Normal 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
27
zeromq/taskwork.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user