[zeromq-dev] zmq_recvmsg jni
Pieter Hintjens
ph at imatix.com
Sun Sep 29 13:11:58 CEST 2013
I think we lack a recv function that delivers data as a fresh blob
that can be freed using the standard free() method. I.e. like
zmq_msg_init_data but for receipt, not sending...
On Sat, Sep 28, 2013 at 11:48 PM, Trevor Bernard
<trevor.bernard at gmail.com> wrote:
> Hi guys,
>
> I messing around with JNI and libzmq and I was wondering if there was
> a way to avoid the memcpy?
>
> JNIEXPORT
> jobject JNICALL
> Java_org_zeromq_jni_ZMQ_zmq_1recv__JI (JNIEnv *env, jclass c, jlong
> socket, jint flags)
> {
> zmq_msg_t msg;
> zmq_msg_init (&msg);
> zmq_recvmsg ((void *) socket, &msg, flags);
> int size = zmq_msg_size (&msg);
> void *data = malloc(size);
> memcpy(data, zmq_msg_data (&msg), size);
> zmq_msg_close(&msg);
> return env->NewDirectByteBuffer(data, size);
> }
>
> Cheers,
>
> Trev
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
More information about the zeromq-dev
mailing list