JFJochReceiver: Use zero-copy ZeroMQ sending
This commit is contained in:
@@ -76,6 +76,24 @@ void ZMQSocket::Send(zmq_msg_t *msg) {
|
||||
throw JFJochException(JFJochExceptionCategory::ZeroMQ, "zmq_msg_send failed");
|
||||
}
|
||||
|
||||
void zmq_socket_free(void *data, void *hint) {
|
||||
auto s = (std::binary_semaphore *) hint;
|
||||
s->release();
|
||||
}
|
||||
|
||||
void ZMQSocket::SendZeroCopy(const void *buf, size_t buf_size, std::binary_semaphore *sempahore) {
|
||||
std::unique_lock<std::mutex> ul(m);
|
||||
zmq_msg_t msg;
|
||||
if (zmq_msg_init_data(&msg, const_cast<void *>(buf), buf_size, zmq_socket_free, sempahore) != 0) {
|
||||
sempahore->release();
|
||||
throw JFJochException(JFJochExceptionCategory::ZeroMQ, "zmq_msg_init_data failed");
|
||||
}
|
||||
if (zmq_msg_send(&msg, socket, 0) < 0) {
|
||||
sempahore->release();
|
||||
throw JFJochException(JFJochExceptionCategory::ZeroMQ, "zmq_msg_send failed");
|
||||
}
|
||||
}
|
||||
|
||||
int64_t ZMQSocket::Receive(bool blocking) {
|
||||
std::vector<uint8_t> msg;
|
||||
return Receive(msg, blocking, true);
|
||||
|
||||
Reference in New Issue
Block a user