[zeromq-dev] Named pipe

BLOTTIERE Paul paul.blottiere at fr.thalesgroup.com
Tue Aug 23 11:36:59 CEST 2011


Hi,

I'm working with debian and I would like using named pipe with zmq. So, I modified the Broker in the Request-Reply-Broker (example in the Guide) in order to poll the named pipe with the file descriptor:

int main (void)
{
	//socket//
	void *context = zmq_init (1);
	void *frontend = zmq_socket (context, ZMQ_ROUTER);
	void *backend = zmq_socket (context, ZMQ_DEALER);
	zmq_bind (frontend, "tcp://*:5559");
	zmq_bind (backend, "tcp://*:5560");

        //named pipe//
        FILE *fichier;
        int fd;
        char *nom_tube = "tube1";
        char buffer[128];

        fd = open (nom_tube, O_RDONLY);
        fichier = fdopen (fd, "r");
 
	//poll set//
	zmq_pollitem_t items [3];

	items[0].socket = frontend;
	items[0].events = ZMQ_POLLIN;

	items[1].socket = backend;
	items[1].events = ZMQ_POLLIN;

        items[2].socket = NULL;
	items[2].fd = fd;
	items[2].events = ZMQ_POLLIN;

	//switch//
	while (1) {
		zmq_msg_t message;
		int64_t more;

		zmq_poll (items, 3, -1);

		if (items [0].revents & ZMQ_POLLIN) {
			while (1) {
				zmq_msg_init (&message);
				zmq_recv (frontend, &message, 0);
				size_t more_size = sizeof (more);
				zmq_getsockopt (frontend, ZMQ_RCVMORE, &more, &more_size);
				zmq_send (backend, &message, more? ZMQ_SNDMORE: 0);
				zmq_msg_close (&message);
				if (!more)
					break;
			}
		}

		if (items [1].revents & ZMQ_POLLIN) {
			while (1) {
				zmq_msg_init (&message);
				zmq_recv (backend, &message, 0);
				size_t more_size = sizeof (more);
				zmq_getsockopt (backend, ZMQ_RCVMORE, &more, &more_size);
				zmq_send (frontend, &message, more? ZMQ_SNDMORE: 0);
				zmq_msg_close (&message);
				if (!more)
					break;
			}
		}

		if (items [2].revents & ZMQ_POLLIN) {
				read(fd,buffer,128);
				zmq_msg_init_size (&message, strlen (buffer));
				memcpy (zmq_msg_data (&message), buffer, strlen (buffer));
				zmq_send (backend, &message, 0);
				//assert(0);
				zmq_msg_close (&message);
		}
	}


	zmq_close (frontend);
	zmq_close (backend);
	zmq_term (context);
        fclose (fichier);
        close(fd);

	return 0;
}


With the assert(0), I checked the broker well receives the message when the buffer is not empty (i.e when a client writes on the other side of the named pipe). However, the server doesn't receive the message. Why? 

Would you mind helping me please?

Rgds,

Paul B. 



More information about the zeromq-dev mailing list