summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@fastmq.com>2009-09-08 13:55:13 +0200
committerMartin Sustrik <sustrik@fastmq.com>2009-09-08 13:55:13 +0200
commit3069b6bd54486346f7bfcce58d6a5e34d129965c (patch)
treecdef109605b657baa1abc28cada66425dda438c5 /java
parentec6822a477b89ac77afc90425bf36c4829dbef3d (diff)
win port of java binding + java perf tests
Diffstat (limited to 'java')
-rw-r--r--java/Context.cpp7
-rw-r--r--java/Message.cpp138
-rw-r--r--java/Socket.cpp7
-rw-r--r--java/org/zmq/Socket.java2
4 files changed, 15 insertions, 139 deletions
diff --git a/java/Context.cpp b/java/Context.cpp
index 3fc66bd..67094e8 100644
--- a/java/Context.cpp
+++ b/java/Context.cpp
@@ -34,7 +34,14 @@ static void raise_exception (JNIEnv *env, int err)
assert (exception_class);
// Get text description of the exception.
+#if defined _MSC_VER
+#pragma warning (push)
+#pragma warning (disable:4996)
+#endif
const char *err_msg = strerror (err);
+#if defined _MSC_VER
+#pragma warning (pop)
+#endif
// Raise the exception.
int rc = env->ThrowNew (exception_class, err_msg);
diff --git a/java/Message.cpp b/java/Message.cpp
deleted file mode 100644
index 2105216..0000000
--- a/java/Message.cpp
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- Copyright (c) 2007-2009 FastMQ Inc.
-
- This file is part of 0MQ.
-
- 0MQ is free software; you can redistribute it and/or modify it under
- the terms of the Lesser GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- 0MQ is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- Lesser GNU General Public License for more details.
-
- You should have received a copy of the Lesser GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <errno.h>
-
-#include "zmq.h"
-#include "org_zmq_Message.h"
-
-static jfieldID msg_handle_fid = NULL;
-
-static void
-raise_exception (JNIEnv *env, int err)
-{
- // Get exception class.
- jclass exception_class = env->FindClass ("java/lang/Exception");
- assert (exception_class);
-
- // Get text description of the exception.
- const char *err_msg = strerror (err);
-
- // Raise the exception.
- int rc = env->ThrowNew (exception_class, err_msg);
- assert (rc == 0);
-
- // Free the local ref.
- env->DeleteLocalRef (exception_class);
-}
-
-JNIEXPORT void JNICALL
-Java_org_zmq_Message_construct (JNIEnv *env, jobject obj)
-{
- if (msg_handle_fid == NULL) {
- jclass cls = env->GetObjectClass (obj);
- assert (cls != NULL);
- msg_handle_fid = env->GetFieldID (cls, "msgHandle", "J");
- assert (msg_handle_fid != NULL);
- env->DeleteLocalRef (cls);
- }
-
- zmq_msg_t *msg = (zmq_msg_t*) malloc (sizeof (zmq_msg_t));
- if (msg == NULL) {
- raise_exception (env, ENOMEM);
- return;
- }
-
- int rc = zmq_msg_init (msg);
- assert (rc == 0);
- env->SetLongField (obj, msg_handle_fid, (jlong) msg);
-}
-
-JNIEXPORT void JNICALL
-Java_org_zmq_Message_constructWithData (JNIEnv *env, jobject obj,
- jbyteArray payload)
-{
- if (msg_handle_fid == NULL) {
- jclass cls = env->GetObjectClass (obj);
- assert (cls != NULL);
- msg_handle_fid = env->GetFieldID (cls, "msgHandle", "J");
- assert (msg_handle_fid != NULL);
- env->DeleteLocalRef (cls);
- }
-
- zmq_msg_t *msg = (zmq_msg_t*) malloc (sizeof (zmq_msg_t));
- if (msg == NULL) {
- raise_exception (env, ENOMEM);
- return;
- }
-
- jsize array_size = env->GetArrayLength (payload);
- jbyte *array_data = env->GetByteArrayElements (payload, NULL);
-
- int rc = zmq_msg_init_size (msg, array_size);
- assert (rc == 0);
-
- memcpy (zmq_msg_data (msg), array_data, array_size);
- env->ReleaseByteArrayElements (payload, array_data, JNI_ABORT);
-
- env->SetLongField (obj, msg_handle_fid, (jlong) msg);
-}
-
-JNIEXPORT void JNICALL
-Java_org_zmq_Message_finalize (JNIEnv *env, jobject obj)
-{
- zmq_msg_t *msg = (zmq_msg_t*) env->GetLongField (obj, msg_handle_fid);
- assert (msg);
-
- int rc = zmq_msg_close (msg);
- assert (rc == 0);
-
- free (msg);
-}
-
-JNIEXPORT jbyteArray JNICALL
-Java_org_zmq_Message_getMsgPayload (JNIEnv *env, jobject obj)
-{
- zmq_msg_t *msg = (zmq_msg_t*) env->GetLongField (obj, msg_handle_fid);
- assert (msg);
-
- jsize msg_size = zmq_msg_size (msg);
- jbyte *msg_data = (jbyte*) zmq_msg_data (msg);
-
- jbyteArray payload = env->NewByteArray (msg_size);
- if (payload == NULL)
- return NULL;
-
- env->SetByteArrayRegion (payload, 0, msg_size, msg_data);
- assert (!env->ExceptionCheck ());
-
- return payload;
-}
-
-JNIEXPORT jint JNICALL
-Java_org_zmq_Message_getMsgType (JNIEnv *env, jobject obj)
-{
- zmq_msg_t *msg = (zmq_msg_t*) env->GetLongField (obj, msg_handle_fid);
- assert (msg);
-
- return (jint) zmq_msg_type (msg);
-}
diff --git a/java/Socket.cpp b/java/Socket.cpp
index f87c298..51ee816 100644
--- a/java/Socket.cpp
+++ b/java/Socket.cpp
@@ -35,7 +35,14 @@ static void raise_exception (JNIEnv *env, int err)
assert (exception_class);
// Get text description of the exception.
+#if defined _MSC_VER
+#pragma warning (push)
+#pragma warning (disable:4996)
+#endif
const char *err_msg = strerror (err);
+#if defined _MSC_VER
+#pragma warning (pop)
+#endif
// Raise the exception.
int rc = env->ThrowNew (exception_class, err_msg);
diff --git a/java/org/zmq/Socket.java b/java/org/zmq/Socket.java
index 832467f..4c6a3d3 100644
--- a/java/org/zmq/Socket.java
+++ b/java/org/zmq/Socket.java
@@ -1,4 +1,4 @@
-/*
+ /*
Copyright (c) 2007-2009 FastMQ Inc.
This file is part of 0MQ.