[zeromq-dev] "Socket operation on non-socket" error

Ilya Shpigor petrsum at gmail.com
Fri Nov 30 14:46:08 CET 2012


Hi,

I write a simple client-server application with TCP protocol.

Server receives messages from client, performs some actions and sends
answer. Server and each client work in different processes.

The server communication with first connected client is well. But
server get "Socket operation on non-socket" error after zmq_poll call
when first client finishing his work and second client connects and
sends request.

This is server initialization function:

void zero_cache::CreateReactorConnection(ReactorArgs& args)
{
    args.context = zctx_new ();
    args.socket = zsocket_new(args.context, ZMQ_DEALER);

    zsocket_bind(args.socket, "tcp://*:5570");
    zsocket_set_hwm(args.socket, 1000);

    zmq_pollitem_t items[1] = { { args.socket, 0, ZMQ_POLLIN, 0 } };
    memcpy(&args.items, &items, sizeof(items));
}

Server loop for processing client's messages:

void* zero_cache::ReactorLoop(void* reactor_args)
{
    ReactorArgs* args = static_cast<ReactorArgs*>(reactor_args);

    while (true)
    {
        if ( zmq_poll(args->items, 1, -1) == -1 )
	{
	    /* ERROR OCCURS HERE */
            cout << "ReactorLoop() - error = " <<
zmq_strerror(zmq_errno()) << endl;
	}

        if ( args->items[0].revents & ZMQ_POLLIN )
        {
            zmsg_t* msg = zmsg_recv(args->socket);
            assert( msg != NULL );
            zframe_t* command = zmsg_pop(msg);
            zframe_t* key = zmsg_pop(msg);

            // Some processing...

            zmsg_destroy(&msg);
        }
    }
    zctx_destroy(&args->context);
}

This is client initialization:

Client::Client(string log_file, string connection) : DebugClient(log_file)
{
    context_ = zctx_new();
    socket_ = zsocket_new(context_, ZMQ_DEALER);

    zsocket_connect(socket_, "tcp://localhost:5570");
    zsocket_set_hwm(socket_, 10);
}

And client request sending function:

void Client::WriteData(string key, void* data, size_t size)
{
    Command command = kSet;

    zframe_t* command_frame = zframe_new(&command, sizeof(Command));
    zframe_t* key_frame = zframe_new(key.c_str(), key.size());
    zframe_t* data_frame = zframe_new(data, size);

    zframe_send(&command_frame, socket_, ZFRAME_MORE);
    zframe_send(&key_frame, socket_, ZFRAME_MORE);
    zframe_send(&data_frame, socket_, 0);
}

Have anybody faced with same problem? How this error can be fixed?

Thanks,
Ilya



More information about the zeromq-dev mailing list