0

相当简单的问题。我有一些代码可以从序列化的 protobuf 事件中发送消息(也尝试使用简单的 char * 字符串)。但是,当我调用发送时,我收到错误“非套接字上的套接字操作”。我尝试了很多东西,但无济于事。

void send_event(tp::Event event, void * z_pub)
{
  assert(z_pub != NULL);

  zmq_msg_t msg;
  int size = event.ByteSize();
  uint8_t sev[size];

  event.SerializeWithCachedSizesToArray(sev);

  int rc = zmq_msg_init_size(&msg, size);

  memcpy(zmq_msg_data(&msg), &sev, size);

  if (zmq_sendmsg(z_pub, &msg, 0) != 0)
    {
      cout << "Send err code: " << " " << zmq_strerror(zmq_errno())  << endl;
    }

  if (zmq_msg_close(&msg) != 0)
    {
      cout << "Closing message err code: " << zmq_strerror(zmq_errno())  << endl;
    }
}

随着事情的开始:

void * z_ctx_pub = zmq_ctx_new();

void * z_pub = zmq_socket(z_ctx_pub, ZMQ_PUB);

if (z_pub == NULL)
  cerr << "Error creating output socket for process" << endl;


if (zmq_bind(z_pub, z_pub_uri.c_str()) != 0)
  {
    cout << "Binding to PUB err code: " << " " << zmq_strerror(zmq_errno())  << endl;
    abort();
  } 
else 
  cout << "Bound to " << z_pub_uri << endl;

编辑:我现在已经将 init 移动到我正在发送的同一个线程中,我得到:

Resource temporarily unavailable

http://paste.ubuntu.com/5984515/

4

0 回答 0