当前位置: 首页>>代码示例>>Java>>正文


Java VMThread类代码示例

本文整理汇总了Java中com.sun.squawk.VMThread的典型用法代码示例。如果您正苦于以下问题:Java VMThread类的具体用法?Java VMThread怎么用?Java VMThread使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


VMThread类属于com.sun.squawk包,在下文中一共展示了VMThread类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import com.sun.squawk.VMThread; //导入依赖的package包/类
/**
 * IOHandler run loop. Wait on select until IO occurs.
 */
public void run() {
    //VM.println("in SystemEvents.run()");
    //VM.println("in SystemEvents.run()");
    while (!cancelRunLoop) {
        waitForEvents(Long.MAX_VALUE);
        VMThread.yield();
        //VM.println("in SystemEvents.run() - woke up and try again");
        //VM.println("in SystemEvents.run() - woke up and try again");
    }
    //VM.println("in SystemEvents.run() - cancelling");
    //VM.println("in SystemEvents.run() - cancelling");
    //VM.println("in SystemEvents.run() - cancelling");
    //VM.println("in SystemEvents.run() - cancelling");
    selectRunner.cancelTaskExecutor(); /* cancel the native thread that we use for blocking calls...*/ /* cancel the native thread that we use for blocking calls...*/
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:19,代码来源:SystemEventsImpl.java

示例2: accept

import com.sun.squawk.VMThread; //导入依赖的package包/类
/**
 * Accept client connections on server socket fd.
 * Blocks until a client connects.
 *
 * @param fd open server socket. See {@link #openServer}.
 *
 * @return a native handle to the network connection.
 * @throws IOException
 */
public int accept(int fd) throws IOException {
    VMThread.getSystemEvents().waitForReadEvent(fd);

    Socket.sockaddr_in remote_sin = new Socket.sockaddr_in();
    IntByReference address_len = new IntByReference(4);
    int newSocket = sockets.accept(fd, remote_sin, address_len);
    if (newSocket < 0) {
        throw newError(fd, "accept");
    }
    address_len.free();
    set_blocking_flags(newSocket, /*is_blocking*/ false);
    // we could read info about client from remote_sin, but don't need to.

    return newSocket;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:25,代码来源:GCFSocketsImpl.java

示例3: writeBuf

import com.sun.squawk.VMThread; //导入依赖的package包/类
/**
 * @inheritDoc
 */
public int writeBuf(int fd, byte buffer[], int off, int len) throws IOException {
    int result = 0;
            byte[] buf = buffer;
    if (off != 0) {
        buf = new byte[len];
        System.arraycopy(buffer, off, buf, 0, len);
    }

    if (DEBUG) {    System.err.println("writeBuf(" + fd + ") before write."); }

    result = libc.write(fd, buf, len);// We rely on open0() for setting the socket to non-blocking

    if (result < 0) {
        int err_code = LibCUtil.errno();
        if (err_code == LibC.EWOULDBLOCK) {
            VMThread.getSystemEvents().waitForWriteEvent(fd);
            if (DEBUG) {    System.err.println("writeBuf(" + fd + ") returned from select. retry."); }
            result = libc.write(fd, buf, len); // We rely on open0() for setting the socket to non-blocking
        }
        if (DEBUG) {    System.err.println("writeBuf(" + fd + ") error:"); }
        LibCUtil.errCheckNeg(result);
    }

    return result;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:29,代码来源:GCFSocketsImpl.java

示例4: handleEvents

import com.sun.squawk.VMThread; //导入依赖的package包/类
/**
 * If any any events have occurred in the waiting set, tell the
 * thread scheduler to make the waiting java thread runnable.
 *
 * @param num number of events to be processed
 * @param waitingSet waiting set as an IntSet
 * @param eventFDSet waiting set as a FD_SET
 * @return remaining number of events to be processed
 */
private int handleEvents(int num, IntSet waitingSet, Pointer eventFDSet) {
    if (num > 0) {
        for (int i = 0; i < waitingSet.size(); i++) {
            int fd = waitingSet.getElements()[i];
            if (select.FD_ISSET(fd, eventFDSet)) {
                //if (DEBUG) { VM.println("handleEvents: event on fd: " + fd + " num: " + (num-1)); }
                waitingSet.remove(fd);        // shrink waitingSet
                VMThread.signalOSEvent(fd);
                num--;
                if (num == 0) {
                    break; // no more events
                }
                i--; // recheck location i
            }
        }
    }
    return num;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:28,代码来源:SystemEventsImpl.java

示例5: writeBuf

import com.sun.squawk.VMThread; //导入依赖的package包/类
/**
 * @inheritDoc
 */
public int writeBuf(int fd, byte buffer[], int off, int len) throws IOException {
    int result = 0;
    byte[] buf = buffer;
    if (off != 0) {
        buf = new byte[len];
        System.arraycopy(buffer, off, buf, 0, len);
    }

    if (DEBUG) {    System.err.println("writeBuf(" + fd + ") before write."); }

    result = libc.write(fd, buf, len);// We rely on open0() for setting the socket to non-blocking

    if (result < 0) {
        int err_code = LibCUtil.errno();
        if (err_code == LibC.EWOULDBLOCK) {
            VMThread.getSystemEvents().waitForWriteEvent(fd);
            if (DEBUG) {    System.err.println("writeBuf(" + fd + ") returned from select. retry."); }
            result = libc.write(fd, buf, len); // We rely on open0() for setting the socket to non-blocking
        }
        if (DEBUG) {    System.err.println("writeBuf(" + fd + ") error:"); }
        LibCUtil.errCheckNeg(result);
    }

    return result;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:29,代码来源:GCFSocketsImpl.java

示例6: readBuf

import com.sun.squawk.VMThread; //导入依赖的package包/类
/**
 * @inheritDoc
 */
public int readBuf(int fd, byte b[], int offset, int length) throws IOException {
    byte[] buf = b;
    if (offset != 0) {
        buf = new byte[length];
    }
    int result = libc.read(fd, buf, length); // We rely on open0() for setting the socket to non-blocking

    if (result < 0) {
        int err_code = LibCUtil.errno();
        if (err_code == LibC.EWOULDBLOCK) {
            VMThread.getSystemEvents().waitForReadEvent(fd);
            result = libc.read(fd, buf, length); // We rely on open0() for setting the socket to non-blocking
        }
        LibCUtil.errCheckNeg(result);
    }
    
    if (result == 0) {
        // If remote side has shut down the connection gracefully, and all
        // data has been received, recv() will complete immediately with
        // zero bytes received.
        //
        // This is true for Win32/CE and Linux
        result = -1;
    }

    return result;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:31,代码来源:GCFSocketsImpl.java

示例7: waitForReadEvent

import com.sun.squawk.VMThread; //导入依赖的package包/类
public void waitForReadEvent(int fd) {
    if (DEBUG) { VM.println("waitForReadEvent fd: " + fd); }
    Assert.that(fd >= 0 && fd < Select.FD_SETSIZE);
    readSet.add(fd);
    updateSets();
    cancelSelectCall();
    VMThread.waitForOSEvent(fd); // read is ready, select will remove fd from readSet
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:9,代码来源:SystemEventsImpl.java

示例8: waitForWriteEvent

import com.sun.squawk.VMThread; //导入依赖的package包/类
public void waitForWriteEvent(int fd) {
    if (DEBUG) { VM.println("waitForWriteEvent fd: " + fd); }
    Assert.that(fd >= 0 && fd < Select.FD_SETSIZE);
    writeSet.add(fd);
    updateSets();
    cancelSelectCall();
    VMThread.waitForOSEvent(fd);// write is ready, select will remove fd from writeSet
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:9,代码来源:SystemEventsImpl.java

示例9: run

import com.sun.squawk.VMThread; //导入依赖的package包/类
/**
 * IOHandler run loop. Wait on select until IO occurs.
 */
public void run() {
    while (!cancelRunLoop) {
        waitForEvents(Long.MAX_VALUE);
        VMThread.yield();
        //VM.println("in SystemEvents.run() - woke up and try again");
    }
    //VM.println("in SystemEvents.run() - cancelling");
    selectRunner.cancelTaskExecutor(); /* cancel the native thread that we use for blocking calls...*/
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:13,代码来源:SystemEventsImpl.java

示例10: accept

import com.sun.squawk.VMThread; //导入依赖的package包/类
/**
     * Accept client connections on server socket fd.
     * Blocks until a client connects.
     *
     * @param fd open server socket. See {@link #openServer}.
     *
     * @return a native handle to the network connection.
     * @throws IOException 
     */
    public int accept(int fd) throws IOException {
        Socket.sockaddr_in remote_sin = new Socket.sockaddr_in();
        IntByReference address_len = new IntByReference(4);
        int newSocket;

        try {
            if (DEBUG) { System.err.println("Socket.accept(" + fd + ", " + remote_sin + ")..."); }

            newSocket = sockets.accept(fd, remote_sin, address_len);

            if (newSocket < 0) {
                if (DEBUG) { System.err.println("Need to block for accept..."); }

                int err_code = LibCUtil.errno();
                if (err_code == LibC.EAGAIN || err_code == LibC.EWOULDBLOCK) {
                    VMThread.getSystemEvents().waitForReadEvent(fd);
                    newSocket = sockets.accept(fd, remote_sin, address_len);
                    if (newSocket < 0) {
                        throw newError(fd, "accept");
                    }
                } else {
// BUG! 
                    throw newError(fd, "accept");
                }
            }
        } finally {
            address_len.free();
        }

        set_blocking_flags(newSocket, /*is_blocking*/ false);
        // we could read info about client from remote_sin, but don't need to.

        if (DEBUG) { System.err.println("    Socket.accept(...) = " + newSocket); }
        return newSocket;
    }
 
开发者ID:tomatsu,项目名称:squawk,代码行数:45,代码来源:GCFSocketsImpl.java


注:本文中的com.sun.squawk.VMThread类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。