summaryrefslogtreecommitdiff
path: root/gnu/java/nio/SocketChannelImpl.java
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2002-11-16 15:48:25 +0000
committerMichael Koch <konqueror@gmx.de>2002-11-16 15:48:25 +0000
commita2c24a0bd9eb4b186c5d8d11516b789b514ff828 (patch)
treeaa160d08aa13382b12caf81e800d99a5be94eea5 /gnu/java/nio/SocketChannelImpl.java
parenta9033eae89f91de683e47b93db5d3e307ea4df2e (diff)
downloadclasspath-a2c24a0bd9eb4b186c5d8d11516b789b514ff828.tar.gz
2002-11-16 Michael Koch <konqueror@gmx.de>
* gnu/java/nio/DatagramChannelImpl.java, gnu/java/nio/FileChannelImpl.java, gnu/java/nio/PipeImpl.java, gnu/java/nio/SelectionKeyImpl.java, gnu/java/nio/SelectorImpl.java, gnu/java/nio/SelectorProviderImpl.java, gnu/java/nio/ServerSocketChannelImpl.java, gnu/java/nio/SocketChannelImpl.java: Reindented.
Diffstat (limited to 'gnu/java/nio/SocketChannelImpl.java')
-rw-r--r--gnu/java/nio/SocketChannelImpl.java285
1 files changed, 146 insertions, 139 deletions
diff --git a/gnu/java/nio/SocketChannelImpl.java b/gnu/java/nio/SocketChannelImpl.java
index 970ef559e..dd24b28c8 100644
--- a/gnu/java/nio/SocketChannelImpl.java
+++ b/gnu/java/nio/SocketChannelImpl.java
@@ -37,195 +37,202 @@ exception statement from your version. */
package gnu.java.nio;
-import java.net.*;
-import java.io.*;
-import java.nio.*;
-import java.nio.channels.*;
-import java.nio.channels.spi.*;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.AlreadyConnectedException;
+import java.nio.channels.SocketChannel;
+import java.nio.channels.spi.SelectorProvider;
import gnu.classpath.Configuration;
public class SocketChannelImpl extends SocketChannel
{
- Socket sock_object;
- int fd;
- int local_port;
- boolean blocking = true;
- boolean connected = false;
- InetSocketAddress sa;
-
- static native int SocketCreate();
- static native int SocketConnect(int fd, InetAddress a, int port);
- static native int SocketBind(int fd, InetAddress host, int port);
- static native int SocketListen(int fd, int backlog);
- static native int SocketAvailable(int fd);
- static native int SocketClose(int fd);
- static native int SocketRead(int fd, byte b[], int off, int len);
- static native int SocketWrite(int fd, byte b[], int off, int len);
-
- public SocketChannelImpl(SelectorProvider provider)
- {
- super(provider);
-
- fd = SocketCreate();
+ Socket sock_object;
+ int fd;
+ int local_port;
+ boolean blocking = true;
+ boolean connected = false;
+ InetSocketAddress sa;
+
+/*
+ static native int SocketCreate();
+ static native int SocketConnect(int fd, InetAddress a, int port);
+ static native int SocketBind(int fd, InetAddress host, int port);
+ static native int SocketListen(int fd, int backlog);
+ static native int SocketAvailable(int fd);
+ static native int SocketClose(int fd);
+ static native int SocketRead(int fd, byte b[], int off, int len);
+ static native int SocketWrite(int fd, byte b[], int off, int len);
+*/
+
+ static int SocketCreate() { return 0; };
+ static int SocketConnect(int fd, InetAddress a, int port) { return 0; };
+ static int SocketBind(int fd, InetAddress host, int port) { return 0; };
+ static int SocketListen(int fd, int backlog) { return 0; };
+ static int SocketAvailable(int fd) { return 0; };
+ static int SocketClose(int fd) { return 0; };
+ static int SocketRead(int fd, byte b[], int off, int len) { return 0; };
+ static int SocketWrite(int fd, byte b[], int off, int len) { return 0; };
+
+ public SocketChannelImpl(SelectorProvider provider)
+ {
+ super(provider);
+
+ fd = SocketCreate();
- if (fd == -1)
+ if (fd == -1)
{
- System.err.println("failed to create socket:"+fd);
+ System.err.println("failed to create socket:"+fd);
}
-
- //System.out.println("socket-channel:"+fd);
- }
+ }
- public void finalizer()
- {
- if (connected)
+ public void finalizer()
+ {
+ if (connected)
{
- try {
- close();
- } catch (Exception e) {
- }
+ try
+ {
+ close();
+ }
+ catch (Exception e)
+ {
+ }
}
- }
-
- protected void implCloseSelectableChannel()
- {
- connected = false;
- SocketClose(fd);
- fd = SocketCreate();
- }
-
- protected void implConfigureBlocking(boolean block)
- {
- if (blocking == block)
+ }
+
+ protected void implCloseSelectableChannel()
+ {
+ connected = false;
+ SocketClose(fd);
+ fd = SocketCreate();
+ }
+
+ protected void implConfigureBlocking(boolean block)
+ {
+ if (blocking == block)
return;
- }
+ }
- public boolean connect(SocketAddress remote)
- throws IOException
- {
- if (connected)
+ public boolean connect(SocketAddress remote)
+ throws IOException
+ {
+ if (connected)
{
- throw new AlreadyConnectedException();
+ throw new AlreadyConnectedException();
}
- // ok, lets connect !
+ // ok, lets connect !
- sa = (InetSocketAddress) remote;
-
- InetAddress addr = sa.getAddress();
- int port = sa.getPort();
-
- // System.out.println("CONNECT: " + addr + ","+port);
+ sa = (InetSocketAddress) remote;
- int err = SocketConnect(fd, addr, port);
+ InetAddress addr = sa.getAddress();
+ int port = sa.getPort();
+ int err = SocketConnect(fd, addr, port);
- if (err < 0)
+ if (err < 0)
{
- throw new IOException("Connection refused:"+err + ", connect="+err);
+ throw new IOException("Connection refused:"+err + ", connect="+err);
}
- local_port = err;
+ local_port = err;
- connected = true;
+ connected = true;
- return blocking;
- }
+ return blocking;
+ }
- public boolean finishConnect()
- {
- return false;
- }
-
- public boolean isConnected()
- {
- return connected;
- }
+ public boolean finishConnect()
+ {
+ return false;
+ }
+
+ public boolean isConnected()
+ {
+ return connected;
+ }
- public boolean isConnectionPending()
- {
- if (blocking)
+ public boolean isConnectionPending()
+ {
+ if (blocking)
return false;
- return false;
- }
+
+ return false;
+ }
- public Socket socket()
- {
- if (sock_object != null)
+ public Socket socket()
+ {
+ if (sock_object != null)
{
- //sock_object.ch = this;
+ //sock_object.ch = this;
}
- return sock_object;
- }
+ return sock_object;
+ }
- public int read(ByteBuffer dst)
- {
- int bytes = 0;
-
- int len = 1024;
- byte[]b = new byte[len];
+ public int read(ByteBuffer dst)
+ {
+ int bytes = 0;
+ int len = 1024;
+ byte[]b = new byte[len];
- bytes = SocketRead(fd, b, 0, len);
- //System.out.println("readbytes:"+bytes +",len" +len);
+ bytes = SocketRead(fd, b, 0, len);
- dst.put(b, 0, bytes);
+ dst.put(b, 0, bytes);
- if (bytes == 0)
+ if (bytes == 0)
{
- // we've hit eof ?
- return -1;
+ // we've hit eof ?
+ return -1;
}
- return bytes;
- }
+ return bytes;
+ }
- public long read(ByteBuffer[] dsts, int offset, int length)
- {
- long bytes = 0;
- for (int i=offset; i<length; i++)
+ public long read(ByteBuffer[] dsts, int offset, int length)
+ {
+ long bytes = 0;
+
+ for (int i=offset; i<length; i++)
{
- bytes += read(dsts[i]);
+ bytes += read(dsts[i]);
}
- return bytes;
- }
+
+ return bytes;
+ }
- public int write(ByteBuffer src)
- {
- int bytes = 0;
-
- int len = src.position();
+ public int write(ByteBuffer src)
+ {
+ int bytes = 0;
+ int len = src.position();
- if (src instanceof ByteBufferImpl)
+ if (src instanceof ByteBufferImpl)
{
- ByteBufferImpl bi = (ByteBufferImpl) src;
- byte[]b = bi.array();
- bytes = SocketWrite(fd, b, 0, len);
-
- //System.out.println("reused memory buffer....");
+ ByteBufferImpl bi = (ByteBufferImpl) src;
+ byte[]b = bi.array();
+ bytes = SocketWrite(fd, b, 0, len);
}
- else
+ else
{
- byte[]b = new byte[len];
- src.get(b, 0, len);
- bytes = SocketWrite(fd, b, 0, len);
+ byte[]b = new byte[len];
+ src.get(b, 0, len);
+ bytes = SocketWrite(fd, b, 0, len);
}
-
-
- //System.out.println("WRITEN #bytes="+bytes +",fd=" +fd+","+(char)b[0]+(char)b[1]+(char)b[2]);
-
- return bytes;
- }
+ return bytes;
+ }
- public long write(ByteBuffer[] srcs, int offset, int length)
- {
- long bytes = 0;
- for (int i=offset; i<length; i++)
+ public long write (ByteBuffer[] srcs, int offset, int length)
+ {
+ long bytes = 0;
+ for (int i=offset; i<length; i++)
{
- bytes += write(srcs[i]);
+ bytes += write(srcs[i]);
}
- return bytes;
- }
+ return bytes;
+ }
}