Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for zmq_join/zmq_leave draft methods #490

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,10 @@ javah_stamp
.tags*
*.sublime-project
*.sublime-workspace
jzmq-jni/src/.vs/src/v16/Browse.VC.opendb
jzmq-jni/src/.vs/src/v16/Browse.VC.db-wal
jzmq-jni/src/.vs/src/v16/Browse.VC.db-shm
jzmq-jni/src/.vs/src/v16/Browse.VC.db
jzmq-jni/src/.vs/slnx.sqlite
jzmq-jni/src/.vs/ProjectSettings.json
jzmq-jni/src/.vs/src/v16/.suo
62 changes: 62 additions & 0 deletions jzmq-jni/src/main/c++/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,68 @@ JNIEXPORT void JNICALL Java_org_zeromq_ZMQ_00024Socket_disconnect (JNIEnv *env,
#endif
}

/**
* Called by Java's Socket::join(String group).
*/
JNIEXPORT void JNICALL Java_org_zeromq_ZMQ_00024Socket_join (JNIEnv *env,
jobject obj,
jstring group)
{
void *s = get_socket (env, obj);

if (group == NULL) {
raise_exception (env, EINVAL);
return;
}

const char *c_group = env->GetStringUTFChars (group, NULL);
if (c_group == NULL) {
raise_exception (env, EINVAL);
return;
}

int rc = zmq_join (s, c_group);
int err = zmq_errno();
env->ReleaseStringUTFChars (group, c_group);

if (rc != 0) {
raise_exception (env, err);
return;
}
}


/**
* Called by Java's Socket::leave(String group).
*/
JNIEXPORT void JNICALL Java_org_zeromq_ZMQ_00024Socket_leave (JNIEnv *env,
jobject obj,
jstring group)
{
void *s = get_socket (env, obj);

if (group == NULL) {
raise_exception (env, EINVAL);
return;
}

const char *c_group = env->GetStringUTFChars (group, NULL);
if (c_group == NULL) {
raise_exception (env, EINVAL);
return;
}

int rc = zmq_leave (s, c_group);
int err = zmq_errno();
env->ReleaseStringUTFChars (group, c_group);

if (rc != 0) {
raise_exception (env, err);
return;
}
}


typedef struct _jzmq_zerocopy_t {
JNIEnv *env;
jobject ref_buffer;
Expand Down
22 changes: 22 additions & 0 deletions jzmq-jni/src/main/java/org/zeromq/ZMQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ public class ZMQ {
*/
public static final int SUB = 2;
/**
* Flag to specify the receiving part of the RADIO socket.
*/
public static final int DISH = 15;
/**
* Flag to specify a RADIO socket, receiving side must be a DISH.
*/
public static final int RADIO = 14;
/**
* Flag to specify a REQ socket, receiving side must be a REP.
*/
public static final int REQ = 3;
Expand Down Expand Up @@ -1218,6 +1226,20 @@ public void unsubscribe(byte[] topic) {
setBytesSockopt(UNSUBSCRIBE, topic);
}

/**
* Joins a group.
*
* @param group the name of the group to join. Limited to 16 characters.
*/
public native void join(String group);

/**
* Leaves a group.
*
* @param group the name of the group to leave. Limited to 16 characters.
*/
public native void leave(String group);

/**
* The 'ZMQ_RATE' option shall set the maximum send or receive data rate for multicast transports such as in the
* man page of zmq_pgm[7] using the specified 'socket'.
Expand Down