harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r583521 - in /harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix: EpollSelectorImpl.c EpollSelectorImpl.h exports.txt makefile
Date Wed, 10 Oct 2007 15:52:33 GMT
Author: ayza
Date: Wed Oct 10 08:52:32 2007
New Revision: 583521

URL: http://svn.apache.org/viewvc?rev=583521&view=rev
Log:
Committing native part of epoll-based selector provider from HARMONY-4879 ([classlib][nio]
epoll-based Selector). Java part was accidentally committed with my previos commit at r583514.
Sorry for this.

Added:
    harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/EpollSelectorImpl.c
  (with props)
    harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/EpollSelectorImpl.h
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/exports.txt
    harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/makefile

Added: harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/EpollSelectorImpl.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/EpollSelectorImpl.c?rev=583521&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/EpollSelectorImpl.c
(added)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/EpollSelectorImpl.c
Wed Oct 10 08:52:32 2007
@@ -0,0 +1,212 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#include <jni.h>
+#include <sys/epoll.h>
+#include "hysock.h"
+#include "hyport.h"
+#include "EpollSelectorImpl.h"
+/* Header for class org_apache_harmony_nio_internal_EPollSelectorImpl */
+
+//#define EPOLL_DEBUG 
+//#define EPOLL_DEBUG_EXTENSIVE
+
+/*
+ * Class:     org_apache_harmony_nio_internal_EpollSelectorImpl
+ * Method:    resolveFD
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_harmony_nio_internal_EpollSelectorImpl_resolveFD
+  (JNIEnv * env, jclass clazz, jclass cfd, jobject ofd) 
+{
+      jfieldID descriptorFID = (*env)->GetFieldID(env, cfd, "descriptor", "J");
+      return ((hysocket_t) ((IDATA)((*env)->GetLongField (env, ofd, descriptorFID))))->sock;
+} 
+
+/*
+ * Class:     org_apache_harmony_nio_internal_EpollSelectorImpl
+ * Method:    prepare
+ * Signature: ()I
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_harmony_nio_internal_EpollSelectorImpl_prepare
+  (JNIEnv * jniEnv, jclass clazz) 
+{
+    int fd;
+
+#ifdef EPOLL_DEBUG
+    printf("epoll(): initializing epoll\n");
+#endif
+    
+    fd = epoll_create(256);
+
+#ifdef EPOLL_DEBUG
+    printf("epoll(): epoll_create finished with %d\n", fd);
+#endif
+    
+    // let the Java code handle the exceptions
+    return fd;
+} 
+
+
+/*
+ * Class:     org_apache_harmony_nio_internal_EpollSelectorImpl
+ * Method:    addFileDescriptor
+ * Signature: (L)I
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_harmony_nio_internal_EpollSelectorImpl_addFileDescriptor
+  (JNIEnv * env, jclass clazz, jlong epollfd, jint mode, jint fd) 
+{
+    int op;
+    struct epoll_event ev;
+    int result;
+    
+    ev.events = 0;
+    if((mode & SOCKET_READ_OP) != 0) {
+        ev.events = ev.events | EPOLLIN | EPOLLPRI;
+    }
+    
+    if((mode & SOCKET_WRITE_OP) != 0) {
+        ev.events = ev.events | EPOLLOUT;
+    }   
+
+    ev.data.fd = fd;
+
+#ifdef EPOLL_DEBUG   
+    printf("epoll(): fd=%d, adding %d to filedescriptor list with mode %d and event mask
%d\n", epollfd, fd, mode, ev.events);
+#endif
+    
+    result = epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev);
+
+#ifdef EPOLL_DEBUG
+    if(result == -1) {
+        printf("epoll(): result=%d errno=%d EBADF=%d EPERM=%d EINVAL=%d ENOMEM=%d\n", result,
errno, EBADF, EPERM, EINVAL, ENOMEM);
+    }
+#endif
+    
+    // let the java layer handle exceptions
+    return result;
+}    
+
+
+/*
+ * Class:     org_apache_harmony_nio_internal_EpollSelectorImpl
+ * Method:    delFileDescriptor
+ * Signature: (L)I
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_harmony_nio_internal_EpollSelectorImpl_delFileDescriptor
+  (JNIEnv * jniEnv, jclass clazz, jlong epollfd, jlong fd) 
+{
+    int result;
+    struct epoll_event ev;
+
+    ev.data.fd = fd;
+
+#ifdef EPOLL_DEBUG    
+    printf("epoll(): deletin %ld from filedescriptor list\n", fd);
+#endif
+    
+    result = epoll_ctl(epollfd, EPOLL_CTL_DEL, fd, &ev);
+
+#ifdef EPOLL_DEBUG
+    if (result == -1) {
+        printf("epoll(): result=%d errno=%d EBADF=%d EPERM=%d EINVAL=%d ENOMEM=%d\n", result,
errno, EBADF, EPERM, EINVAL, ENOMEM);
+    }    
+#endif    
+     
+    // let the Java layer handle exceptions   
+    return result;
+} 
+
+
+/*
+ * Class:     org_apache_harmony_nio_internal_EpollSelectorImpl
+ * Method:    epoll
+ * Signature: (L)I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_harmony_nio_internal_EpollSelectorImpl_epoll
+  (JNIEnv * env, jclass clazz, jlong epollfd, jint count, jintArray fds, jintArray ops, jlong
timeout) 
+{
+    struct epoll_event * evs;
+    jint * fdsArray;
+    jint * opsArray;
+    int result;
+    int isCopy;
+    int c;
+    int temp;
+    
+    evs = malloc(sizeof(struct epoll_event)*count);
+    if (!evs) {
+        printf("epoll(): error on memory allocation\n");
+        return -1;
+        
+    }
+    
+#ifdef EPOLL_DEBUG
+#ifdef EPOLL_DEBUG_EXTENSIVE    
+   printf("epoll(): waiting on %d channels for %d msecs\n", count, timeout);
+#endif    
+#endif   
+  
+    // wait! 
+    result = epoll_wait(epollfd, evs, count, timeout); 
+
+#ifdef EPOLL_DEBUG
+#ifdef EPOLL_DEBUG_EXTENSIVE
+    printf("epoll(): %d channels up, %d total\n", result, count);
+#endif
+#endif
+    
+#ifdef EPOLL_DEBUG
+#ifdef EPOLL_DEBUG_EXTENSIVE
+    printf("epoll(): Start parsing epoll() results\n");
+#endif
+#endif
+
+    // copying out the results, pinning might help here...
+    isCopy = NULL;
+    fdsArray = (*env)->GetIntArrayElements(env, fds, &isCopy);
+
+    isCopy = NULL;
+    opsArray = (*env)->GetIntArrayElements(env, ops, &isCopy);
+
+    for(c = 0; c < result; c++) {
+        fdsArray[c] = evs[c].data.fd;
+
+        temp = SOCKET_NONE_OP;
+        if (evs[c].events & (EPOLLIN | EPOLLPRI)) {
+            temp = temp + SOCKET_READ_OP;
+        }
+            
+        if (evs[c].events & (EPOLLOUT)) {
+            temp = temp + SOCKET_WRITE_OP;
+        }
+        opsArray[c] = temp;
+    }
+    (*env)->ReleaseIntArrayElements(env, ops, opsArray, 0);
+    (*env)->ReleaseIntArrayElements(env, fds, fdsArray, 0);
+
+#ifdef EPOLL_DEBUG
+#ifdef EPOLL_DEBUG_EXTENSIVE
+    printf("epoll(): End parsing epoll() results\n");
+#endif
+#endif
+    
+    free(evs);    
+   
+    // let the Java code handle the exceptions 
+    return result;
+} 

Propchange: harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/EpollSelectorImpl.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/EpollSelectorImpl.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/EpollSelectorImpl.h?rev=583521&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/EpollSelectorImpl.h
(added)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/EpollSelectorImpl.h
Wed Oct 10 08:52:32 2007
@@ -0,0 +1,64 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#include <jni.h>
+/* Header for class org_apache_harmony_nio_internal_EPollSelectorImpl */
+#define SOCKET_NONE_OP 0
+#define SOCKET_READ_OP 1
+#define SOCKET_WRITE_OP 2
+
+
+/*
+ * Class:     org_apache_harmony_nio_internal_EpollSelectorImpl
+ * Method:    resolveFD
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_harmony_nio_internal_EpollSelectorImpl_resolveFD
+  (JNIEnv *, jclass, jclass, jobject);
+
+/*
+ * Class:     org_apache_harmony_nio_internal_EpollSelectorImpl
+ * Method:    prepare
+ * Signature: ()I
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_harmony_nio_internal_EpollSelectorImpl_prepare
+  (JNIEnv *, jclass);
+
+
+/*
+ * Class:     org_apache_harmony_nio_internal_EpollSelectorImpl
+ * Method:    addFileDescriptor
+ * Signature: (L)I
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_harmony_nio_internal_EpollSelectorImpl_addFileDescriptor
+  (JNIEnv *, jclass, jlong, jint, jint);
+
+/*
+ * Class:     org_apache_harmony_nio_internal_EpollSelectorImpl
+ * Method:    delFileDescriptor
+ * Signature: (L)I
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_harmony_nio_internal_EpollSelectorImpl_delFileDescriptor
+  (JNIEnv *, jclass, jlong, jlong);
+
+/*
+ * Class:     org_apache_harmony_nio_internal_EpollSelectorImpl
+ * Method:    epoll
+ * Signature: (L)I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_harmony_nio_internal_EpollSelectorImpl_epoll
+  (JNIEnv *, jclass, jlong, jint, jlongArray, jintArray, jlong);

Propchange: harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/EpollSelectorImpl.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/exports.txt
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/exports.txt?rev=583521&r1=583520&r2=583521&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/exports.txt (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/exports.txt Wed Oct
10 08:52:32 2007
@@ -2,3 +2,8 @@
 GetDirectBufferAddress
 GetDirectBufferCapacity
 Java_org_apache_harmony_nio_AddressUtil_getFDAddress
+Java_org_apache_harmony_nio_internal_EpollSelectorImpl_resolveFD
+Java_org_apache_harmony_nio_internal_EpollSelectorImpl_prepare
+Java_org_apache_harmony_nio_internal_EpollSelectorImpl_addFileDescriptor
+Java_org_apache_harmony_nio_internal_EpollSelectorImpl_delFileDescriptor
+Java_org_apache_harmony_nio_internal_EpollSelectorImpl_epoll

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/makefile
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/makefile?rev=583521&r1=583520&r2=583521&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/makefile (original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/native/nio/unix/makefile Wed Oct
10 08:52:32 2007
@@ -22,7 +22,7 @@
 CFLAGS += -fpic
 
 BUILDFILES = \
-	../shared/DirectBufferUtil.o ../shared/AddressUtil.o 
+	../shared/DirectBufferUtil.o ../shared/AddressUtil.o ../unix/EpollSelectorImpl.o
 
 ifneq ($(HY_ZIP_API),true)
 MDLLIBFILES += $(LIBPATH)libhyzip.a 



Mime
View raw message