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

📄 socketprotocol.c

📁 Nucleus_2_kvm_Hello 是kvm移植到Nucleus系统的源代码。。。好东西啊
💻 C
📖 第 1 页 / 共 2 页
字号:
 *   parameters:  this, buffer, offset, length *   returns:     the length written *=======================================================================*/ASYNC_FUNCTION_START(Java_com_sun_cldc_io_j2me_socket_Protocol_write0){    long       length = ASYNC_popStack();    long       offset = ASYNC_popStack();    BYTEARRAY   array = ASYNC_popStackAsType(BYTEARRAY);    INSTANCE instance = ASYNC_popStackAsType(INSTANCE);    long fd;    int  res;    aiocb->instance = instance;    fd = getSocketHandle(aiocb);    NDEBUG4("socket::write0 b=%lx o=%ld l=%ld fd=%ld\n",                   (long)array, (long)offset, (long)length, fd);    if (array == 0) {        ASYNC_raiseException("java/lang/NullPointerException");        res = 0;        goto done;    }    if ((offset < 0) || (offset > (long)array->length) || (length < 0) ||       ((offset + length) > (long)array->length) || ((offset + length) < 0)) {        ASYNC_raiseException("java/lang/IndexOutOfBoundsException");        res = 0;        goto done;    }    {#if ASYNCHRONOUS_NATIVE_FUNCTIONS        char buffer[ASYNC_BUFFER_SIZE];       /*        * If necessary reduce the length to that of the buffer. The        * Java code will call back with more I/O operations if needed.        */        if (length > ASYNC_BUFFER_SIZE) {            length = ASYNC_BUFFER_SIZE;        }        memcpy(buffer, (char *)array->bdata + offset, length);        ASYNC_enableGarbageCollection();        res = prim_com_sun_cldc_io_j2me_socket_Protocol_write0(fd,                  buffer, length);        ASYNC_disableGarbageCollection();#else        res = prim_com_sun_cldc_io_j2me_socket_Protocol_write0(fd,                  (char *)array->bdata + offset, length);#endif /* ASYNCHRONOUS_NATIVE_FUNCTIONS */    }    NDEBUG3("socket::write0 res=%ld l=%ld ne=%ld\n",       (long)res, (long)length, (long)netError());    if (res < 0) {        if (res == -3) {            ASYNC_raiseException("java/io/InterruptedIOException");        } else {            ASYNC_raiseException("java/io/IOException");        }    }done:    ASYNC_pushStack(res);}ASYNC_FUNCTION_END/*========================================================================= * FUNCTION:      available0() * CLASS:         com.sun.cldc.io.j2me.socket.Protocol * TYPE:          virtual native function * OVERVIEW:      Return available length * INTERFACE (operand stack manipulation): *   parameters:  this *   returns:     length *=======================================================================*/ASYNC_FUNCTION_START(Java_com_sun_cldc_io_j2me_socket_Protocol_available0){    INSTANCE instance = ASYNC_popStackAsType(INSTANCE);    long fd;    int  res;    aiocb->instance = instance;    fd = getSocketHandle(aiocb);    ASYNC_enableGarbageCollection();    res = prim_com_sun_cldc_io_j2me_socket_Protocol_available0(fd);    ASYNC_disableGarbageCollection();    NDEBUG1("socket::available0 len=%ld\n", (long)res);    ASYNC_pushStack(res);}ASYNC_FUNCTION_END/*========================================================================= * FUNCTION:      close0() * CLASS:         com.sun.cldc.io.j2me.socket.Protocol * TYPE:          virtual native function * OVERVIEW:      Close a TCP socket * INTERFACE (operand stack manipulation): *   parameters:  this *   returns:     none *=======================================================================*/ASYNC_FUNCTION_START(Java_com_sun_cldc_io_j2me_socket_Protocol_close0){    INSTANCE instance = ASYNC_popStackAsType(INSTANCE);    long fd;    int  res = 0;    aiocb->instance = instance;    fd = getSocketHandle(aiocb);    if (fd != -1L) {        setSocketHandle(aiocb, -1);        ASYNC_enableGarbageCollection();        res = prim_com_sun_cldc_io_j2me_socket_Protocol_close0(fd);        ASYNC_disableGarbageCollection();    }    NDEBUG3("socket::close res=%ld fd=%ld ne=%ld\n",            (long)res, fd, (long)netError());    if (res < 0) {        ASYNC_raiseException("java/io/IOException");    }}ASYNC_FUNCTION_END/*========================================================================= * FUNCTION:      registerCleanup * CLASS:         com.sun.cldc.io.j2me.socket.Protocol * TYPE:          virtual native function * OVERVIEW:      Close a TCP socket * INTERFACE (operand stack manipulation): *   parameters:  this *   returns:     none *=======================================================================*/static voidsocketCleanup(INSTANCE_HANDLE instanceHandle){    INSTANCE instance = unhand(instanceHandle);    long fd = instance->data[0].cell;    if (fd != -1L) {        prim_com_sun_cldc_io_j2me_socket_Protocol_close0(fd);    }}void Java_com_sun_cldc_io_j2me_socket_Protocol_registerCleanup(){    START_TEMPORARY_ROOTS        DECLARE_TEMPORARY_ROOT(INSTANCE, instance, popStackAsType(INSTANCE));        registerCleanup(&instance, socketCleanup);    END_TEMPORARY_ROOTS}/*========================================================================= * FUNCTION:      open() * CLASS:         com.sun.cldc.io.j2me.serversocket.Protocol * TYPE:          virtual native function * OVERVIEW:      Open a listening TCP socket * INTERFACE (operand stack manipulation): *   parameters:  this, name, mode, append *   returns:     none *=======================================================================*/ASYNC_FUNCTION_START(Java_com_sun_cldc_io_j2me_serversocket_Protocol_open0){#if NO_SERVER_SOCKETS    ASYNC_raiseException("java/lang/ClassNotFoundException");#else    long stringlen;    long            append    = ASYNC_popStack();    long            mode      = ASYNC_popStack();    STRING_INSTANCE string    = ASYNC_popStackAsType(STRING_INSTANCE);    INSTANCE        instance  = ASYNC_popStackAsType(INSTANCE);    char           *exception = NULL;    int             fd        = -1;    char            name[MAX_HOST_LENGTH];    char           *host;    int             port;    (void)mode;    (void)append;    aiocb->instance = instance;    /*     * The name string has the following format: "//<host>:<port>"     */    stringlen = string->length + 1;    (void)getStringContentsSafely(string, name, stringlen);    /* Must be called before getHostName() */    port = getPortNumber(name);    if (port < 0 || port > 0xFFFF) {        NDEBUG2("serversocket::open name='%s' port=%ld (ERROR)\n",                name, (long)port);        goto illarg;    }    /* Must be the last parsing function */    host = getHostName(name);    if (host == NULL || *host != '\0') {        NDEBUG2("serversocket::open name='%s' host='%s' (ERROR)\n",                name, (host==NULL) ? "null" : host);        goto illarg; /* must start "serversocket://:" */    }    NDEBUG3("serversocket::open name='%s' host='%s' port=%ld\n",            name, host, (long)port);    ASYNC_enableGarbageCollection();    fd = prim_com_sun_cldc_io_j2me_serversocket_Protocol_open0(port,                                                               &exception);    ASYNC_disableGarbageCollection();    NDEBUG6("serversocket::open name='%s' host='%s' port=%ld fd = %ld exception = '%s' ne=%ld\n",            name, host, (long)port, (long)fd,            (exception == NULL) ? "null" : exception, (long)netError());    if (exception == NULL) {        /* For non-blocking systems only */        prim_com_sun_cldc_io_j2me_socket_Protocol_setNonBlocking(fd);        goto done;    }    ASYNC_raiseException(exception);    goto fail;illarg:    ASYNC_raiseException("java/lang/IllegalArgumentException");fail:    fd = -1;done:    setSocketHandle(aiocb, fd);#endif /* NO_SERVER_SOCKETS */}ASYNC_FUNCTION_END/*========================================================================= * FUNCTION:      accept() * CLASS:         com.sun.cldc.io.j2me.serversocket.Protocol * TYPE:          virtual native function * OVERVIEW:      Accept and open a connection * INTERFACE (operand stack manipulation): *   parameters:  this *   returns:     socket handle *=======================================================================*/ASYNC_FUNCTION_START(Java_com_sun_cldc_io_j2me_serversocket_Protocol_accept){#if NO_SERVER_SOCKETS    ASYNC_raiseException("java/lang/ClassNotFoundException");#else    INSTANCE instance = ASYNC_popStackAsType(INSTANCE);    long fd;    int  res = 0;    aiocb->instance = instance;    fd = getSocketHandle(aiocb);    NDEBUG1("serversocket::accept fd=%ld\n", fd);    ASYNC_enableGarbageCollection();    res = prim_com_sun_cldc_io_j2me_serversocket_Protocol_accept(fd);    ASYNC_disableGarbageCollection();    NDEBUG3("serversocket::accept res=%ld fd=%ld ne=%ld\n",            (long)res, fd, (long)netError());    if (res < 0 && res != -2) {        ASYNC_raiseException("java/io/IOException");    }    ASYNC_pushStack(res);#endif /* NO_SERVER_SOCKETS */}ASYNC_FUNCTION_END/*========================================================================= * FUNCTION:      close() * CLASS:         com.sun.cldc.io.j2me.serversocket.Protocol * TYPE:          virtual native function * OVERVIEW:      Close a listening TCP socket * INTERFACE (operand stack manipulation): *   parameters:  this *   returns:     none *=======================================================================*/ASYNC_FUNCTION_START(Java_com_sun_cldc_io_j2me_serversocket_Protocol_close){#if NO_SERVER_SOCKETS    ASYNC_raiseException("java/lang/ClassNotFoundException");#else    INSTANCE instance = ASYNC_popStackAsType(INSTANCE);    long fd;    int  res = 0;    aiocb->instance = instance;    fd = getSocketHandle(aiocb);    if (fd != -1L) {        setSocketHandle(aiocb, -1);        ASYNC_enableGarbageCollection();        res = prim_com_sun_cldc_io_j2me_serversocket_Protocol_close(fd);        ASYNC_disableGarbageCollection();    }    NDEBUG3("serversocket::close res=%ld fd=%ld ne=%ld\n",               (long)res, fd, (long)netError());    if (res < 0) {        ASYNC_raiseException("java/io/IOException");    }#endif /* NO_SERVER_SOCKETS */}ASYNC_FUNCTION_END/*========================================================================= * FUNCTION:      registerCleanup * CLASS:         com.sun.cldc.io.j2me.serversocket.Protocol * TYPE:          virtual native function * OVERVIEW:      Close a TCP socket * INTERFACE (operand stack manipulation): *   parameters:  this *   returns:     none *=======================================================================*/static voidserversocketCleanup(INSTANCE_HANDLE instanceHandle){    INSTANCE instance = unhand(instanceHandle);    long fd = instance->data[0].cell;    if (fd != -1L) {        prim_com_sun_cldc_io_j2me_serversocket_Protocol_close(fd);    }}void Java_com_sun_cldc_io_j2me_serversocket_Protocol_registerCleanup(){    START_TEMPORARY_ROOTS        DECLARE_TEMPORARY_ROOT(INSTANCE, instance, popStackAsType(INSTANCE));        registerCleanup(&instance, serversocketCleanup);    END_TEMPORARY_ROOTS}/*========================================================================= * FUNCTION:      initalizeInternal(); * CLASS:         com.sun.cldc.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. *=======================================================================*/voidJava_com_sun_cldc_io_NetworkConnectionBase_initializeInternal(){    networkInit();}

⌨️ 快捷键说明

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