[zeromq-dev] zmq_recvmsg jni

gonzalo diethelm gdiethelm at dcv.cl
Mon Sep 30 13:05:18 CEST 2013


Can you do something like this?

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);
    CORRECT_TYPE dbb = env->NewDirectByteBuffer(data, size);
    zmq_msg_close(&msg);
    return dbb;
}

-- 
Gonzalo Diethelm
DCV Chile

> -----Original Message-----
> From: zeromq-dev-bounces at lists.zeromq.org [mailto:zeromq-dev-
> bounces at lists.zeromq.org] On Behalf Of Trevor Bernard
> Sent: Saturday, September 28, 2013 6:49 PM
> To: ZeroMQ development list
> Subject: [zeromq-dev] zmq_recvmsg jni
> 
> 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


----------------------------------------- 
Declaración de confidencialidad: Este Mensaje esta destinado para
el uso de la o las personas o entidades a quien ha sido dirigido y
puede contener información reservada y confidencial que no puede
ser divulgada, difundida, ni aprovechada en forma alguna. El uso no
autorizado de la información contenida en este correo podrá ser
sancionado de conformidad con la ley chilena. 
Si usted ha recibido este correo electrónico por error, le pedimos
eliminarlo junto con los archivos adjuntos y avisar inmediatamente
al remitente, respondiendo este mensaje. 

"Before printing this e-mail think if is really necesary".
Disclosure: This Message is to be used by the individual,
individuals or entities that it is addressed to and may include
private and confidential information that may not be disclosed,
made public nor used in any way at all. Unauthorized use of the
information in this electronic mail message may be subject to the
penalties set forth by Chilean law. 
If you have received this electronic mail message in error, we ask
you to destroy the message and its attached file(s) and to
immediately notify the sender by answering this message. 



More information about the zeromq-dev mailing list