ZeroCopyReturnValue: Add structure to return ZMQ zero copy buffer

This commit is contained in:
2023-05-09 16:17:13 +02:00
parent 2c62d01759
commit eac366cbe5
9 changed files with 35 additions and 16 deletions
+6 -6
View File
@@ -77,19 +77,19 @@ void ZMQSocket::Send(zmq_msg_t *msg) {
}
void zmq_socket_free(void *data, void *hint) {
auto s = (std::binary_semaphore *) hint;
s->release();
auto z = (ZeroCopyReturnValue *) hint;
z->fifo->Put(z->handle);
}
void ZMQSocket::SendZeroCopy(const void *buf, size_t buf_size, std::binary_semaphore *sempahore) {
void ZMQSocket::SendZeroCopy(const void *buf, size_t buf_size, ZeroCopyReturnValue *zero_copy_ret_val) {
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();
if (zmq_msg_init_data(&msg, const_cast<void *>(buf), buf_size, zmq_socket_free, zero_copy_ret_val) != 0) {
zero_copy_ret_val->release();
throw JFJochException(JFJochExceptionCategory::ZeroMQ, "zmq_msg_init_data failed");
}
if (zmq_msg_send(&msg, socket, 0) < 0) {
sempahore->release();
zero_copy_ret_val->release();
throw JFJochException(JFJochExceptionCategory::ZeroMQ, "zmq_msg_send failed");
}
}