From c806aabb2d3e6b1ba9e3f61319f23d45c7f9a007 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Mon, 14 Sep 2009 11:25:57 +0200 Subject: java binding sets socket options using setsockopt function --- java/Socket.cpp | 114 +++++++++++++++++++---------------------------- java/org/zmq/Socket.java | 58 +++++++----------------- 2 files changed, 62 insertions(+), 110 deletions(-) (limited to 'java') diff --git a/java/Socket.cpp b/java/Socket.cpp index 51ee816..a7b2fe5 100644 --- a/java/Socket.cpp +++ b/java/Socket.cpp @@ -86,80 +86,60 @@ JNIEXPORT void JNICALL Java_org_zmq_Socket_finalize (JNIEnv *env, jobject obj) assert (rc == 0); } -JNIEXPORT void JNICALL Java_org_zmq_Socket_setHwm (JNIEnv *env, jobject obj, - jlong hwm) +JNIEXPORT void JNICALL Java_org_zmq_Socket_setsockopt__IJ (JNIEnv *env, + jobject obj, jint option, jlong optval) { - void *s = (void*) env->GetLongField (obj, socket_handle_fid); - assert (s); - int rc = zmq_setsockopt (s, ZMQ_HWM, &hwm, sizeof hwm); - if (rc == -1) - raise_exception (env, errno); -} - -JNIEXPORT void JNICALL Java_org_zmq_Socket_setLwm (JNIEnv *env, jobject obj, - jlong lwm) -{ - void *s = (void*) env->GetLongField (obj, socket_handle_fid); - assert (s); - - int rc = zmq_setsockopt (s, ZMQ_LWM, &lwm, sizeof lwm); - if (rc == -1) - raise_exception (env, errno); -} - -JNIEXPORT void JNICALL Java_org_zmq_Socket_setSwap (JNIEnv *env, jobject obj, - jlong swap_size) -{ - void *s = (void*) env->GetLongField (obj, socket_handle_fid); - assert (s); - - int rc = zmq_setsockopt (s, ZMQ_SWAP, &swap_size, sizeof swap_size); - if (rc == -1) - raise_exception (env, errno); -} - -JNIEXPORT void JNICALL Java_org_zmq_Socket_setMask (JNIEnv *env, jobject obj, - jlong mask) -{ - void *s = (void*) env->GetLongField (obj, socket_handle_fid); - assert (s); - - int rc = zmq_setsockopt (s, ZMQ_MASK, &mask, sizeof mask); - if (rc == -1) - raise_exception (env, errno); -} - -JNIEXPORT void JNICALL Java_org_zmq_Socket_setAffinity (JNIEnv *env, - jobject obj, jlong affinity) -{ - void *s = (void*) env->GetLongField (obj, socket_handle_fid); - assert (s); - - int rc = zmq_setsockopt (s, ZMQ_AFFINITY, &affinity, sizeof affinity); - if (rc == -1) - raise_exception (env, errno); + switch (option) { + case ZMQ_HWM: + case ZMQ_LWM: + case ZMQ_SWAP: + case ZMQ_AFFINITY: + case ZMQ_RATE: + case ZMQ_RECOVERY_IVL: + { + void *s = (void*) env->GetLongField (obj, socket_handle_fid); + assert (s); + + int64_t value = optval; + int rc = zmq_setsockopt (s, option, &value, sizeof (value)); + if (rc != 0) + raise_exception (env, errno); + return; + } + default: + raise_exception (env, EINVAL); + return; + } } -JNIEXPORT void JNICALL Java_org_zmq_Socket_setIdentity (JNIEnv *env, - jobject obj, jstring identity) +JNIEXPORT void JNICALL Java_org_zmq_Socket_setsockopt__ILjava_lang_String_2 ( + JNIEnv *env, jobject obj, jint option, jstring optval) { - void *s = (void*) env->GetLongField (obj, socket_handle_fid); - assert (s); - - if (identity == NULL) { + switch (option) { + case ZMQ_IDENTITY: + case ZMQ_SUBSCRIBE: + case ZMQ_UNSUBSCRIBE: + { + if (optval == NULL) { + raise_exception (env, EINVAL); + return; + } + + void *s = (void*) env->GetLongField (obj, socket_handle_fid); + assert (s); + + const char *value = env->GetStringUTFChars (optval, NULL); + assert (value); + int rc = zmq_setsockopt (s, option, value, strlen (value)); + env->ReleaseStringUTFChars (optval, value); + if (rc != 0) + raise_exception (env, errno); + return; + } + default: raise_exception (env, EINVAL); return; } - - const char *c_identity = env->GetStringUTFChars (identity, NULL); - if (c_identity == NULL) - return; - - int rc = zmq_setsockopt (s, ZMQ_IDENTITY, c_identity, sizeof c_identity); - env->ReleaseStringUTFChars (identity, c_identity); - - if (rc == -1) - raise_exception (env, errno); } JNIEXPORT void JNICALL Java_org_zmq_Socket_bind (JNIEnv *env, jobject obj, diff --git a/java/org/zmq/Socket.java b/java/org/zmq/Socket.java index 4c6a3d3..0d96c71 100644 --- a/java/org/zmq/Socket.java +++ b/java/org/zmq/Socket.java @@ -27,19 +27,24 @@ public class Socket } public static final int NOBLOCK = 1; - public static final int NOFLUSH = 2; public static final int P2P = 0; - public static final int PUB = 1; - public static final int SUB = 2; - public static final int REQ = 3; - public static final int REP = 4; + public static final int HWM = 1; + public static final int LWM = 2; + public static final int SWAP = 3; + public static final int AFFINITY = 4; + public static final int IDENTITY = 5; + public static final int SUBSCRIBE = 6; + public static final int UNSUBSCRIBE = 7; + public static final int RATE = 8; + public static final int RECOVERY_IVL = 9; + /** * Class constructor. * @@ -51,46 +56,13 @@ public class Socket } /** - * Set the high watermark on the socket. - * - * @param hwm high watermark. - */ - public native void setHwm (long hwm); - - /** - * Set the low watermark on the socket. - * - * @param lwm low watermark. - */ - public native void setLwm (long lwm); - - /** - * Set swap size. - * - * @param swap_size swap size. - */ - public native void setSwap (long swap_size); - - /** - * Set reception mask. - * - * @param mask mask. - */ - public native void setMask (long mask); - - /** - * Set affinity. - * - * @param affinity - */ - public native void setAffinity (long affinity); - - /** - * Set identity. + * Set the socket option value. * - * @param identity + * @param option ID of the option to set + * @param optval value to set the option to */ - public native void setIdentity (String identity); + public native void setsockopt (int option, long optval); + public native void setsockopt (int option, String optval); /** * Bind to network interface. Start listening for new connections. -- cgit v1.2.3 From 37cacc5700eaaaddbe2df6e3affeca4a335b023a Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Mon, 14 Sep 2009 12:28:13 +0200 Subject: ZMQII-1: Win32 - failure on shutdown --- java/Socket.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'java') diff --git a/java/Socket.cpp b/java/Socket.cpp index a7b2fe5..2a2f420 100644 --- a/java/Socket.cpp +++ b/java/Socket.cpp @@ -22,6 +22,8 @@ #include #include +#include "../src/stdint.hpp" + #include "zmq.h" #include "org_zmq_Socket.h" -- cgit v1.2.3