synchronized public int select(int interestOps, int timeout) throws Exception {
int n;
try {
- n = selector.select(timeout);
+ if (timeout == 0) {
+ n = selector.selectNow();
+ } else {
+ n = selector.select(timeout);
+ }
} catch (java.io.IOException e) {
throw new Exception(e.toString());
}
+ if (n == 0)
+ return -1;
Set keys = selector.selectedKeys();
Iterator iter = keys.iterator();
while (iter.hasNext()) {
protected int readWithTimeoutOrCallback(byte[] buf, int bufPtr, int len, boolean wait) {
long before = 0;
- long timeout;
+ int timeout;
if (timing)
before = System.nanoTime();
if (!wait) {
timeout = 0;
} else if (timeoutms != -1) {
- timeout = (long)timeoutms;
+ timeout = timeoutms;
} else {
timeout = 0;
}
try {
- n = fd.select(SelectionKey.OP_READ, timeoutms);
+ n = fd.select(SelectionKey.OP_READ, timeout);
} catch (Exception e) {
throw new SystemException("select:"+e.toString());
}
public class FdOutStream extends OutStream {
- static final int defaultBufSize = 8192;
+ static final int defaultBufSize = 16384;
static final int minBulkSize = 1024;
public FdOutStream(FileDescriptor fd_, boolean blocking_, int timeoutms_, int bufSize_)
}
// Proper timeout
- //throw TimedOut();
+ throw new TimedOut();
}
sentUpTo += n;
private int writeWithTimeout(byte[] data, int dataPtr, int length, int timeoutms)
{
- long timeout;
+ int timeout;
int n;
do {
if (timeoutms != -1) {
- timeout = (long)timeoutms;
+ timeout = timeoutms;
} else {
timeout = 0;
}
try {
- n = fd.select(SelectionKey.OP_WRITE, timeoutms);
+ n = fd.select(SelectionKey.OP_WRITE, timeout);
} catch (java.lang.Exception e) {
System.out.println(e.toString());
throw new Exception(e.toString());
try {
n = fd.write(data, dataPtr, length);
} catch (java.lang.Exception e) {
- System.out.println("read:"+e.toString());
throw new Exception(e.toString());
}
PixelFormat pf;
cm = tk.getColorModel();
if (cm.getColorSpace().getType() == java.awt.color.ColorSpace.TYPE_RGB) {
- int depth = cm.getPixelSize();
+ int depth = ((cm.getPixelSize() > 24) ? 24 : cm.getPixelSize());
int bpp = (depth > 16 ? 32 : (depth > 8 ? 16 : 8));
ByteOrder byteOrder = ByteOrder.nativeOrder();
boolean bigEndian = (byteOrder == ByteOrder.BIG_ENDIAN ? true : false);