⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 socketprotocol.c

📁 用于移动设备上的java虚拟机源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
	    connectionHandle =		prim_com_sun_midp_io_j2me_serversocket_Protocol_accept(handle);		    NDEBUG1("serversocket::accept connection handle=%d\n", connectionHandle);	}    }    if (connectionHandle < 0) {        NDEBUG1("serversocket::accept error=%d\n", netError());        if (connectionHandle != IO_WOULDBLOCK) {            KNI_ThrowNew("java/io/IOException", "");        }    }    KNI_ReturnInt((jint)connectionHandle);}/*========================================================================= * FUNCTION:      close0() * CLASS:         com.sun.midp.io.j2me.serversocket.Protocol * TYPE:          virtual native function * OVERVIEW:      Close a listening TCP socket * INTERFACE (operand stack manipulation): *   parameters:  this *   returns:     none *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_io_j2me_serversocket_Socket_close0(){    int handle = getServerSocketHandle();    /* Ensure we don't accidentally close the handle more than once */    setServerSocketHandle(INVALID_HANDLE);        NDEBUG1("serversocket::close handle=%d\n", handle);    if (pushcheckin(handle) == -1){	if (handle != INVALID_HANDLE ) {	    if (prim_com_sun_midp_io_j2me_serversocket_Protocol_close(handle) < 0) {		NDEBUG1("serversocket::close error=%d\n", netError());		KNI_ThrowNew("java/io/IOException", "");	    }	}    }    KNI_ReturnVoid();}static voidserversocketCleanup(jobject serversocket){    int handle;    KNI_StartHandles(1);    KNI_DeclareHandle(clazz);    KNI_GetObjectClass(serversocket, clazz);    /* We need to call KNI_GetFieldID(); serverSocketHandleFieldID may not     * have been set before we cleanup.     */    handle = KNI_GetIntField(serversocket,                              KNI_GetFieldID(clazz, "handle", "I"));    if ((handle != INVALID_HANDLE) && (pushcheckin(handle) == -1)) {        prim_com_sun_midp_io_j2me_serversocket_Protocol_close(handle);        /* Ensure we don't accidentally close the handle more than once */        KNI_SetIntField(serversocket,                         KNI_GetFieldID(clazz, "handle", "I"), INVALID_HANDLE);    }    KNI_EndHandles();}/*========================================================================= * FUNCTION:      registerCleanup * CLASS:         com.sun.midp.io.j2me.serversocket.Protocol * TYPE:          virtual native function * OVERVIEW:      Close a TCP socket * INTERFACE (operand stack manipulation): *   parameters:  this *   returns:     none *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_io_j2me_serversocket_Socket_registerCleanup(){    KNI_StartHandles(1);    KNI_DeclareHandle(instance);    KNI_GetThisPointer(instance);    KNI_registerCleanup(instance, serversocketCleanup);    KNI_EndHandles();    KNI_ReturnVoid();}/*========================================================================= * FUNCTION:      finalize * CLASS:         com.sun.midp.io.j2me.serversocket.Protocol * TYPE:          virtual native function * OVERVIEW:      Close a TCP socket * INTERFACE (operand stack manipulation): *   parameters:  this *   returns:     none *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_io_j2me_serversocket_Socket_finalize(){    KNI_StartHandles(1);    KNI_DeclareHandle(instance);    KNI_GetThisPointer(instance);    serversocketCleanup(instance);    KNI_EndHandles();    KNI_ReturnVoid();}/*========================================================================= * FUNCTION:      initalizeInternal(); * CLASS:         com.sun.midp.io.NetworkConnectionBase() * TYPE:          virtual native function * OVERVIEW:      Initialize the network * INTERFACE (operand stack manipulation): *   parameters:  this *   returns:     none * * This is a static initializer in NetworkConnectionBase, the parent of * all ..../Protocol classes that access the network. *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_VOID    Java_com_sun_midp_io_NetworkConnectionBase_initializeInternal(){    networkInit();    KNI_ReturnVoid();}/* * Wrapper to the system gethostname functionality. * Make sure the network is properly initialized. * Complete the transaction by recording the system * host name in the property values. */char *getLocalHostName() {     char host[MAX_HOST_LENGTH];    networkInit();    if (gethostname(host, MAX_HOST_LENGTH) == 0) {	setSystemProp("microedition.hostname", host);    }    return getSystemProp("microedition.hostname");}/*========================================================================= * FUNCTION:      getHost0(); * CLASS:         com.sun.midp.io.j2me.socket.Protocol * TYPE:          virtual native function * OVERVIEW:      Get the host address for the requested endpoint. * INTERFACE (operand stack manipulation): *   parameters:  this, local *   returns:     IP number as a formatted string * * This routine formats the IP address as a String for either the  * local or remote end point of the connection. *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_OBJECT Java_com_sun_midp_io_j2me_socket_Protocol_getHost0(){    long            local;    long            fd = getSocketHandle();    char *          value;    KNI_StartHandles(1);    KNI_DeclareHandle(result);    local = (int)KNI_GetParameterAsBoolean(1);    value = prim_com_sun_midp_io_j2me_socket_Protocol_getipnumber1(fd, local);    if (value != NULL) {	KNI_NewStringUTF(value, result);    } else {	KNI_ReleaseHandle(result);    }    KNI_EndHandlesAndReturnObject(result); }/*========================================================================= * FUNCTION:      getPort0(); * CLASS:         com.sun.midp.io.j2me.socket.Protocol * TYPE:          virtual native function * OVERVIEW:      Get the port number for the requested endpoint. * INTERFACE (operand stack manipulation): *   parameters:  this, local *   returns:     IP number as a formatted string * * This routine returns the port number for the local or remote  * end point for the current socket connection. *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_INTJava_com_sun_midp_io_j2me_socket_Protocol_getPort0(){    long            local;    long            fd = getSocketHandle();    long            port;    local = (int)KNI_GetParameterAsInt(1);    port = prim_com_sun_midp_io_j2me_socket_Protocol_getport1(fd, local);    KNI_ReturnInt((jint)port);}/*========================================================================= * FUNCTION:      getSocketOpt0(); * CLASS:         com.sun.midp.io.j2me.socket.Protocol * TYPE:          virtual native function * OVERVIEW:      Get the requested socket option value. * INTERFACE (operand stack manipulation): *   parameters:  this, option *   returns:     int value of requested socket option * * This routine returns the requested socket option current value. *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_INTJava_com_sun_midp_io_j2me_socket_Protocol_getSockOpt0(){    long            flag;    long            fd = getSocketHandle();    int             optval;    flag = (int)KNI_GetParameterAsInt(1);    if (prim_com_sun_midp_io_j2me_socket_Protocol_getsockopt0(fd, flag,                                                              &optval) == -1) {	KNI_ThrowNew("java/io/IOException", "");    }    KNI_ReturnInt((jint)optval);}/*========================================================================= * FUNCTION:      setSocketOpt0(); * CLASS:         com.sun.midp.io.j2me.socket.Protocol * TYPE:          virtual native function * OVERVIEW:      set the requested socket option value. * INTERFACE (operand stack manipulation): *   parameters:  this, option, value *   returns:     int value of requested socket option * * This routine returns the requested socket option current value. *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_VOIDJava_com_sun_midp_io_j2me_socket_Protocol_setSockOpt0(){    long            option;    long            value;    long            fd = getSocketHandle();        option = (int)KNI_GetParameterAsInt(1);    value = (int)KNI_GetParameterAsInt(2);    if (prim_com_sun_midp_io_j2me_socket_Protocol_setsockopt0(fd, option, value) == -1){ 	KNI_ThrowNew("java/io/IOException", "");    }    KNI_ReturnVoid();}/*========================================================================= * FUNCTION:      getLocalAddress0(); * CLASS:         com.sun.midp.io.j2me.serversocket.Socket * TYPE:          virtual native function * OVERVIEW:      Get the host address for the local device. * INTERFACE (operand stack manipulation): *   parameters:  this *   returns:     IP number as a formatted string *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_OBJECT Java_com_sun_midp_io_j2me_serversocket_Socket_getLocalAddress0(){    char *          value;    KNI_StartHandles(1);    KNI_DeclareHandle(result);    value = getLocalIPAddressAsString_md();    if (value != NULL) {	KNI_NewStringUTF(value, result);    } else {	KNI_ReleaseHandle(result);    }    if (getServerSocketHandle() == INVALID_HANDLE) {	KNI_ThrowNew("java/io/IOException", "");    }    KNI_EndHandlesAndReturnObject(result); }/*========================================================================= * FUNCTION:      getLocalPort0(); * CLASS:         com.sun.midp.io.j2me.serversocket.Socket * TYPE:          virtual native function * OVERVIEW:      Get the port number for the requested endpoint. * INTERFACE (operand stack manipulation): *   parameters:  this *   returns:     IP number as a formatted string * * This routine returns the port number for the local * end point for the current socket connection. *=======================================================================*/KNIEXPORT KNI_RETURNTYPE_INTJava_com_sun_midp_io_j2me_serversocket_Socket_getLocalPort0(){    long            fd = getServerSocketHandle();    long            port = -1;        if (fd == -1) {	KNI_ThrowNew("java/io/IOException", "");    } else {	port = prim_com_sun_midp_io_j2me_socket_Protocol_getport1(fd, 1);    }    KNI_ReturnInt((jint)port);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -