I have attached some minimal code here where doing a TCP connect to
the PUSH bind socket makes the latter writable.
Tested on 4.1.4
On 30 June 2016 at 23:11, Doron Somech <[email protected]> wrote:
> I think it might be the ZeroMQ behavior (which is probably a bug), once the
> connection is open ZeroMQ start to queue messages for the connection, even
> if handshake is not yet completed, so when you do telnet the message is not
> discarded but queue for the telnet connection.
>
> I think only PUSH is affected by this behavior, also fixing it might be
> hard, it also might be security issue, right now PUSH socket type is not
> safe for internet use because of this.
>
> If you can I suggest you reverse the bind/connection so PUSH will connect
> and PULL will bind. If not an option try to use ROUTER instead and have some
> kind of handshake.
>
> Nice catch, I still want to make sure that is really what happen and see if
> it possible to fix this easily..
>
> On Thu, Jun 30, 2016 at 11:32 AM, 王运来 <[email protected]> wrote:
>>
>> Hi every guys:
>> I got a problem which ZMQ will lost some messages with PUSH/PULL
>> ZMQ socket.
>> The scene like this:
>> A: PUSH socket, bind address "tcp://*.1209"
>> B: PULL socket, connect to "tcp://localhost:1209"
>>
>> Run the command "telnet localhost 1209" while A sending message to
>> B.
>>
>> The result is B will miss messages even if I set the option of
>> ZMQ_IMMEDIATE to 1 like this:
>> int immediate = 1;
>> zmq_setsockopt(pSock, ZMQ_IMMEDIATE, &immediate, sizeof(immediate));
>>
>> Is it right in this scene or is it should be?
>>
>>
>>
>>
>>
>> _______________________________________________
>> zeromq-dev mailing list
>> [email protected]
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
>
> _______________________________________________
> zeromq-dev mailing list
> [email protected]
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
#include <assert.h>
#include <string.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <zmq.h>
int main()
{
void *zctx = zmq_ctx_new();
void *zsock = zmq_socket(zctx, ZMQ_PUSH);
int rc = zmq_bind(zsock, "tcp://127.0.0.1:34567");
assert(rc!=-1);
rc = zmq_send(zsock, "ABC", 3, ZMQ_DONTWAIT);
assert(rc==-1); // expected not writable
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in saddr = {AF_INET, htons(34567), htonl(INADDR_LOOPBACK)};
rc = connect(sockfd, (struct sockaddr*)&saddr, sizeof(saddr));
assert(rc==0);
zmq_pollitem_t item = {zsock, 0, ZMQ_POLLOUT};
rc = zmq_poll(&item, 1, 100);
assert(rc==1); // oops, became writable
rc = zmq_send(zsock, "ABC", 3, ZMQ_DONTWAIT);
assert(rc==3); // write succeeds despite no PULL socket connecting
close(sockfd);
int linger = 0;
rc = zmq_setsockopt(zsock, ZMQ_LINGER, &linger, sizeof(linger));
assert(rc==0);
rc = zmq_close(zsock);
assert(rc==0);
// sometimes this blocks...
printf("destroying\n");
zmq_ctx_destroy(zctx);
}
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev