Hi Pieter,
See attached source code.
Thank you,
--Rakesh
On Thu, Feb 28, 2013 at 10:31 AM, Rakesh Patel
<[email protected]>wrote:
> Hi Pieter,
>
> Yes, it is easily reproducible in following steps.
>
> 1) Sever creates "ZMQ_REP" socket and bind it to "tcp://*:5555" and
> blocks on zmq_recv.
> 2) Client creates "ZMQ_REQ" socket and connect it to
> "tcp://localhost:5555".
> 3) Client send "hello" message and waits for Sever response.
> 4) Sever receive "hello" message, Server reply with two messages
> (multi-part messages). First message "Fine" and send_more to true. Second
> message "ZERO length message" and send_more to false.
> 5) Client receives first "FINE" message on first zmq_recv and failed with
> zmq errno 156384763 on second zmq_recv.
>
> Why zmq_send not able to send "zero length message" ?
>
> Thank you,
>
> --Rakesh
>
> Message: 3
> Date: Wed, 27 Feb 2013 19:19:27 +0100
> From: Pieter Hintjens <[email protected]>
> Subject: Re: [zeromq-dev] zmq errno 156384763
> To: ZeroMQ development list <[email protected]>
> Message-ID:
> <CADL5_si386wLUmRv-=
> [email protected]>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi Rakesh,
>
> Can you reproduce this with a minimal test case?
>
> -Pieter
>
> On Wed, Feb 27, 2013 at 6:01 PM, Rakesh Patel
> <[email protected]> wrote:
> > Hi ,
> >
> > I am trying to send multi-part messages using zmq_send function. In the
> last
> > message, i set send_more to zero and this is zero sized message. On the
> > receiving end using zmq_recv, it sets zmq errno 156384763 when receiving
> > last message. In the documentation, it has written "You may send
> zero-length
> > messages, e.g. for sending a signal from one thread to another." then
> why it
> > is giving error.
> >
> > Is it going to cause any issue (memory leak ?? or any) ?
> >
> > Please let me know,
> >
> > Thank you,
> >
> > --Rakesh
> >
> >
> > _______________________________________________
> > zeromq-dev mailing list
> > [email protected]
> > http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> >
>
/*
* server.cpp
*
* Created on: Feb 28, 2013
* Author: rpatel2
*/
#include <zmq.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <iostream>
#include <string>
int main (void)
{
// Socket to talk to clients
void *context = zmq_init(1);
void *responder = zmq_socket (context, ZMQ_REP);
int rc = zmq_bind (responder, "tcp://*:5555");
assert (rc == 0);
while (1) {
zmq_msg_t reply;
zmq_msg_init(&reply);
if(zmq_recv( responder, &reply, 0 ) < 0) {
std::cout << "First recv failed \n";
}
std::string rstr1((const char *)zmq_msg_data(&reply));
std::cout << rstr1 << std::endl;
std::string str("fine");
zmq_msg_init_size( &reply, strlen(str.c_str())+1 );
memcpy( zmq_msg_data (&reply), str.c_str(), strlen (str.c_str())+1 );
zmq_send( responder, &reply, 1);
std::string null_message("");
zmq_msg_init_size( &reply, 0);
memcpy( zmq_msg_data (&reply), null_message.c_str(), 0);
zmq_send( responder, &reply , 0 );
sleep (1); // Do some 'work'
}
return 0;
}
/*
* client.cpp
*
* Created on: Feb 28, 2013
* Author: rpatel2
*/
#include <zmq.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <iostream>
#include <string>
int main (void)
{
void *context = zmq_init(1);
void *requester = zmq_socket (context, ZMQ_REQ);
zmq_connect (requester, "tcp://localhost:5555");
zmq_msg_t query;
std::string str("Hello");
zmq_msg_init_size( &query, strlen(str.c_str())+1 );
memcpy( zmq_msg_data (&query), str.c_str(), strlen (str.c_str())+1 );
zmq_send( requester, &query, 0 );
zmq_msg_t reply;
zmq_msg_init(&reply);
if(zmq_recv( requester, &reply, 0 ) < 0) {
std::cout << "First recv failed \n";
}
std::string rstr1((const char *)zmq_msg_data(&reply));
std::cout << rstr1 << std::endl;
zmq_msg_init(&reply);
if(zmq_recv( requester, &reply, 0 ) < 0) {
std::cout << "second recv failed : " << zmq_errno() << std::endl;
}
std::string rstr2((const char *)zmq_msg_data(&reply));
std::cout << rstr2 << std::endl;
zmq_close (requester);
zmq_term(context);
return 0;
}
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev