相当简单的问题。我有一些代码从序列化的protobuf事件发送消息(也尝试只使用一个简单的char *字符串)。但是,当我调用send时,我得到错误“非套接字上的套接字操作”。我尝试过很多东西,但无济于事。
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