2004-11-24 Michael Koch <konqueror@gmx.de>
+ * gnu/java/nio/NIOServerSocket.java: Added email to @author tag.
+ * java/nio/DirectByteBufferImpl.java:
+ Moved native methods to java.nio.VMDirectByteBuffer class.
+ * java/nio/MappedByteBufferImpl.java:
+ Use native methods from java.nio.VMDirectByteBuffer class.
+ * java/nio/VMDirectByteBuffer.java: New file,
+ * java/nio/natDirectByteBufferImpl.cc:
+ Moved all methods into java.nio.VMDirectByteBuffer class.
+ * java/nio/channels/spi/AbstractSelectableChannel.java
+ (register): Only re-use valid keys.
+ * Makefile.am: Added java/nio/VMDirectByteBuffer.java.
+ * Makefile.in: Regenerated.
+
+2004-11-24 Michael Koch <konqueror@gmx.de>
+
* java/nio/DirectByteBufferImpl.java,
java/nio/MappedByteBufferImpl.java:
Reformatted.
java/nio/ShortBuffer.java \
java/nio/ShortBufferImpl.java \
java/nio/ShortViewBufferImpl.java \
+java/nio/VMDirectByteBuffer.java \
java/nio/channels/AlreadyConnectedException.java \
java/nio/channels/AsynchronousCloseException.java \
java/nio/channels/ByteChannel.java \
java/nio/ReadOnlyBufferException.java \
java/nio/ShortBuffer.java java/nio/ShortBufferImpl.java \
java/nio/ShortViewBufferImpl.java \
+ java/nio/VMDirectByteBuffer.java \
java/nio/channels/AlreadyConnectedException.java \
java/nio/channels/AsynchronousCloseException.java \
java/nio/channels/ByteChannel.java \
java/nio/MappedByteBuffer.lo java/nio/MappedByteBufferImpl.lo \
java/nio/ReadOnlyBufferException.lo java/nio/ShortBuffer.lo \
java/nio/ShortBufferImpl.lo java/nio/ShortViewBufferImpl.lo \
+ java/nio/VMDirectByteBuffer.lo \
java/nio/channels/AlreadyConnectedException.lo \
java/nio/channels/AsynchronousCloseException.lo \
java/nio/channels/ByteChannel.lo \
java/nio/ShortBuffer.java \
java/nio/ShortBufferImpl.java \
java/nio/ShortViewBufferImpl.java \
+java/nio/VMDirectByteBuffer.java \
java/nio/channels/AlreadyConnectedException.java \
java/nio/channels/AsynchronousCloseException.java \
java/nio/channels/ByteChannel.java \
java/nio/$(DEPDIR)/$(am__dirstamp)
java/nio/ShortViewBufferImpl.lo: java/nio/$(am__dirstamp) \
java/nio/$(DEPDIR)/$(am__dirstamp)
+java/nio/VMDirectByteBuffer.lo: java/nio/$(am__dirstamp) \
+ java/nio/$(DEPDIR)/$(am__dirstamp)
java/nio/channels/AlreadyConnectedException.lo: \
java/nio/channels/$(am__dirstamp) \
java/nio/channels/$(DEPDIR)/$(am__dirstamp)
-rm -f java/nio/ShortBufferImpl.lo
-rm -f java/nio/ShortViewBufferImpl.$(OBJEXT)
-rm -f java/nio/ShortViewBufferImpl.lo
+ -rm -f java/nio/VMDirectByteBuffer.$(OBJEXT)
+ -rm -f java/nio/VMDirectByteBuffer.lo
-rm -f java/nio/channels/AlreadyConnectedException.$(OBJEXT)
-rm -f java/nio/channels/AlreadyConnectedException.lo
-rm -f java/nio/channels/AsynchronousCloseException.$(OBJEXT)
@AMDEP_TRUE@@am__include@ @am__quote@java/nio/$(DEPDIR)/ShortBuffer.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@java/nio/$(DEPDIR)/ShortBufferImpl.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@java/nio/$(DEPDIR)/ShortViewBufferImpl.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@java/nio/$(DEPDIR)/VMDirectByteBuffer.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@java/nio/$(DEPDIR)/natDirectByteBufferImpl.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@java/nio/channels/$(DEPDIR)/AlreadyConnectedException.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@java/nio/channels/$(DEPDIR)/AsynchronousCloseException.Plo@am__quote@
package gnu.java.nio;
import gnu.java.net.PlainSocketImpl;
+
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.channels.SocketChannel;
/**
- * @author Michael Koch
+ * @author Michael Koch (konqueror@gmx.de)
*/
public final class NIOServerSocket extends ServerSocket
{
package java.nio;
-import gnu.classpath.Configuration;
import gnu.gcj.RawData;
final class DirectByteBufferImpl extends ByteBuffer
{
- static
- {
- // load the shared library needed for native methods.
- if (Configuration.INIT_LOAD_LIBRARY)
- {
- System.loadLibrary ("javanio");
- }
- }
-
/** Used by MappedByteBufferImpl and when slicing to prevent premature GC. */
protected Object owner;
*/
public static ByteBuffer allocate(int capacity)
{
- return new DirectByteBufferImpl(allocateImpl(capacity), capacity);
+ return new DirectByteBufferImpl(VMDirectByteBuffer.allocate(capacity),
+ capacity);
}
- private static native RawData allocateImpl (int capacity);
- private static native void freeImpl (RawData address);
-
protected void finalize() throws Throwable
{
- freeImpl (address);
+ VMDirectByteBuffer.free(address);
}
- static native byte getImpl (RawData address, int index);
- static native void putImpl (RawData address, int index, byte value);
-
public byte get()
{
checkForUnderflow();
int pos = position();
- byte result = getImpl (address, pos);
+ byte result = VMDirectByteBuffer.get(address, pos);
position(pos + 1);
return result;
}
{
checkIndex(index);
- return getImpl (address, index);
+ return VMDirectByteBuffer.get(address, index);
}
- static native void getImpl (RawData address, int index,
- byte[] dst, int offset, int length);
-
public ByteBuffer get(byte[] dst, int offset, int length)
{
checkArraySize(dst.length, offset, length);
checkForUnderflow(length);
int index = position();
- getImpl(address, index, dst, offset, length);
+ VMDirectByteBuffer.get(address, index, dst, offset, length);
position(index+length);
return this;
checkForOverflow();
int pos = position();
- putImpl (address, pos, value);
+ VMDirectByteBuffer.put(address, pos, value);
position(pos + 1);
return this;
}
checkIfReadOnly();
checkIndex(index);
- putImpl (address, index, value);
+ VMDirectByteBuffer.put(address, index, value);
return this;
}
- static native void shiftDown(RawData address, int dst_offset, int src_offset, int count);
-
void shiftDown(int dst_offset, int src_offset, int count)
{
- shiftDown(address, dst_offset, src_offset, count);
+ VMDirectByteBuffer.shiftDown(address, dst_offset, src_offset, count);
}
public ByteBuffer compact()
if (pos > 0)
{
int count = remaining();
- shiftDown(address, 0, pos, count);
+ VMDirectByteBuffer.shiftDown(address, 0, pos, count);
position(count);
limit(capacity());
}
return this;
}
- public static native RawData adjustAddress(RawData address, int offset);
-
public ByteBuffer slice()
{
int rem = remaining();
- return new DirectByteBufferImpl (owner,
- adjustAddress(address, position()),
- rem, rem, 0, isReadOnly ());
+ return new DirectByteBufferImpl
+ (owner, VMDirectByteBuffer.adjustAddress(address, position()),
+ rem, rem, 0, isReadOnly());
}
private ByteBuffer duplicate(boolean readOnly)
checkForUnderflow();
int pos = position();
- byte result = DirectByteBufferImpl.getImpl(address, pos);
- position (pos + 1);
+ byte result = VMDirectByteBuffer.get(address, pos);
+ position(pos + 1);
return result;
}
checkForOverflow();
int pos = position();
- DirectByteBufferImpl.putImpl(address, pos, value);
+ VMDirectByteBuffer.put(address, pos, value);
position(pos + 1);
return this;
}
{
checkIndex(index);
- return DirectByteBufferImpl.getImpl(address, index);
+ return VMDirectByteBuffer.get(address, index);
}
public ByteBuffer get(byte[] dst, int offset, int length)
checkForUnderflow(length);
int index = position();
- DirectByteBufferImpl.getImpl(address, index, dst, offset, length);
+ VMDirectByteBuffer.get(address, index, dst, offset, length);
position(index+length);
return this;
checkIfReadOnly();
checkIndex(index);
- DirectByteBufferImpl.putImpl(address, index, value);
+ VMDirectByteBuffer.put(address, index, value);
return this;
}
{
int count = remaining();
// Call shiftDown method optimized for direct buffers.
- DirectByteBufferImpl.shiftDown(address, 0, pos, count);
+ VMDirectByteBuffer.shiftDown(address, 0, pos, count);
position(count);
limit(capacity());
}
public ByteBuffer slice()
{
int rem = remaining();
- return new DirectByteBufferImpl (this,
- DirectByteBufferImpl
- .adjustAddress(address, position()),
- rem, rem, 0, isReadOnly ());
+ return new DirectByteBufferImpl
+ (this, VMDirectByteBuffer.adjustAddress(address, position()),
+ rem, rem, 0, isReadOnly());
}
private ByteBuffer duplicate(boolean readOnly)
--- /dev/null
+/* VMDirectByteBuffer.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.nio;
+
+import gnu.classpath.Configuration;
+import gnu.gcj.RawData;
+
+final class VMDirectByteBuffer
+{
+ static native RawData allocate (int capacity);
+ static native void free(RawData address);
+ static native byte get(RawData address, int index);
+ static native void get(RawData address, int index, byte[] dst, int offset, int length);
+ static native void put(RawData address, int index, byte value);
+ static native RawData adjustAddress(RawData address, int offset);
+ static native void shiftDown(RawData address, int dst_offset, int src_offset, int count);
+}
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
+
package java.nio.channels.spi;
import java.io.IOException;
import java.util.LinkedList;
import java.util.ListIterator;
-
public abstract class AbstractSelectableChannel extends SelectableChannel
{
private boolean blocking = true;
{
key = locate(selector);
- if (key != null)
+ if (key != null && key.isValid())
{
if (att != null)
key.attach(att);
#include <stdlib.h>
#include <gnu/gcj/RawData.h>
-#include <java/nio/DirectByteBufferImpl.h>
+#include <java/nio/VMDirectByteBuffer.h>
using gnu::gcj::RawData;
-using java::nio::DirectByteBufferImpl;
RawData*
-java::nio::DirectByteBufferImpl::allocateImpl (jint capacity)
+java::nio::VMDirectByteBuffer::allocate (jint capacity)
{
return reinterpret_cast<gnu::gcj::RawData*> (::malloc (capacity));
}
void
-java::nio::DirectByteBufferImpl::freeImpl (gnu::gcj::RawData* address)
+java::nio::VMDirectByteBuffer::free (gnu::gcj::RawData* address)
{
::free (reinterpret_cast<void*> (address));
}
jbyte
-DirectByteBufferImpl::getImpl (RawData* address, jint index)
+java::nio::VMDirectByteBuffer::get (RawData* address, jint index)
{
jbyte* pointer = reinterpret_cast<jbyte*> (address) + index;
return *pointer;
}
void
-DirectByteBufferImpl::getImpl (RawData* address, jint index,
- jbyteArray dst, jint offset, jint length)
+java::nio::VMDirectByteBuffer::get (RawData* address, jint index,
+ jbyteArray dst, jint offset, jint length)
{
jbyte* src = reinterpret_cast<jbyte*> (address) + index;
memcpy (elements (dst) + offset, src, length);
}
void
-java::nio::DirectByteBufferImpl::putImpl (gnu::gcj::RawData* address,
- jint index, jbyte value)
+java::nio::VMDirectByteBuffer::put (gnu::gcj::RawData* address,
+ jint index, jbyte value)
{
jbyte* pointer = reinterpret_cast<jbyte*> (address) + index;
*pointer = value;
}
RawData*
-java::nio::DirectByteBufferImpl::adjustAddress (RawData* address, jint offset)
+java::nio::VMDirectByteBuffer::adjustAddress (RawData* address, jint offset)
{
jbyte* start = reinterpret_cast<jbyte*> (address) + offset;
return reinterpret_cast<RawData*>(start);
}
void
-java::nio::DirectByteBufferImpl::shiftDown
-(RawData* address, jint dst_offset, jint src_offset, jint count)
+java::nio::VMDirectByteBuffer::shiftDown (RawData* address, jint dst_offset,
+ jint src_offset, jint count)
{
jbyte* dst = reinterpret_cast<jbyte*> (address) + dst_offset;
jbyte* src = reinterpret_cast<jbyte*> (address) + src_offset;