Commit 98a91a72 by Michael Koch Committed by Michael Koch

2003-06-19 Michael Koch <konqueror@gmx.de>

	* gnu/java/nio/DatagramChannelImpl.java
	(fd): Removed.
	(blocking): New member variable.
	(socket): Likewise.
	(DatagramChannelImpl): Throws IOException, initialize socket.
	(socket):Implemented.
	(implCloseSelectableChannel): Throws IOException, implemented.
	(implConfigureBlocking): Likewise.
	(connect): Likewise.
	(disconnect): Likewise.
	(isConnected): Likewise.
	(write): Likewise.
	(read): Likewise.
	(receive): Throws IOException.
	(send): Likewise.
	* gnu/java/nio/SocketChannelImpl.java
	(read): Implemented.
	(write): Implemented.

From-SVN: r68208
parent 536a695f
2003-06-19 Michael Koch <konqueror@gmx.de> 2003-06-19 Michael Koch <konqueror@gmx.de>
* gnu/java/nio/DatagramChannelImpl.java
(fd): Removed.
(blocking): New member variable.
(socket): Likewise.
(DatagramChannelImpl): Throws IOException, initialize socket.
(socket):Implemented.
(implCloseSelectableChannel): Throws IOException, implemented.
(implConfigureBlocking): Likewise.
(connect): Likewise.
(disconnect): Likewise.
(isConnected): Likewise.
(write): Likewise.
(read): Likewise.
(receive): Throws IOException.
(send): Likewise.
* gnu/java/nio/SocketChannelImpl.java
(read): Implemented.
(write): Implemented.
2003-06-19 Michael Koch <konqueror@gmx.de>
* javax/swing/JComponent.java, * javax/swing/JComponent.java,
javax/swing/JInternalFrame.java, javax/swing/JInternalFrame.java,
javax/swing/MenuSelectionManager.java, javax/swing/MenuSelectionManager.java,
......
...@@ -35,78 +35,120 @@ this exception to your version of the library, but you are not ...@@ -35,78 +35,120 @@ 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 obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package gnu.java.nio; package gnu.java.nio;
import java.io.IOException;
import java.net.DatagramSocket; import java.net.DatagramSocket;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel; import java.nio.channels.DatagramChannel;
import java.nio.channels.NotYetConnectedException;
import java.nio.channels.spi.SelectorProvider; import java.nio.channels.spi.SelectorProvider;
public class DatagramChannelImpl extends DatagramChannel public class DatagramChannelImpl extends DatagramChannel
{ {
int fd; boolean blocking = false;
DatagramSocket socket;
protected DatagramChannelImpl (SelectorProvider provider) protected DatagramChannelImpl (SelectorProvider provider)
throws IOException
{ {
super (provider); super (provider);
socket = new DatagramSocket ();
} }
protected void implCloseSelectableChannel () public DatagramSocket socket ()
{ {
return socket;
} }
protected void implConfigureBlocking (boolean block) protected void implCloseSelectableChannel ()
throws IOException
{ {
socket.close ();
} }
public int write (ByteBuffer src) protected void implConfigureBlocking (boolean blocking)
throws IOException
{ {
return 0; this.blocking = blocking; // FIXME
} }
public long write (ByteBuffer[] srcs, int offset, int length) public DatagramChannel connect (SocketAddress remote)
throws IOException
{ {
return 0; socket.connect (remote);
return this;
} }
public int read (ByteBuffer dst) public DatagramChannel disconnect ()
throws IOException
{ {
return 0; socket.disconnect ();
return this;
} }
public DatagramChannel connect (SocketAddress remote) public boolean isConnected ()
{ {
return null; return socket.isConnected ();
} }
public DatagramChannel disconnect () public int write (ByteBuffer src)
throws IOException
{ {
return null; if (!isConnected ())
} throw new NotYetConnectedException ();
public boolean isConnected () throw new Error ("Not implemented");
}
public long write (ByteBuffer[] srcs, int offset, int length)
throws IOException
{ {
return false; // FIXME: Should we throw an exception if offset and/or length
// have wrong values ?
long result = 0;
for (int i = offset; i < offset + length; i++)
result += write (srcs [i]);
return result;
}
public int read (ByteBuffer dst)
throws IOException
{
if (!isConnected ())
throw new NotYetConnectedException ();
throw new Error ("Not implemented");
} }
public long read (ByteBuffer[] dsts, int offset, int length) public long read (ByteBuffer[] dsts, int offset, int length)
throws IOException
{ {
return 0; // FIXME: Should we throw an exception if offset and/or length
// have wrong values ?
long result = 0;
for (int i = offset; i < offset + length; i++)
result += read (dsts [i]);
return result;
} }
public SocketAddress receive (ByteBuffer dst) public SocketAddress receive (ByteBuffer dst)
throws IOException
{ {
return null; throw new Error ("Not implemented");
} }
public int send (ByteBuffer src, SocketAddress target) public int send (ByteBuffer src, SocketAddress target)
throws IOException
{ {
return 0; throw new Error ("Not implemented");
}
public DatagramSocket socket ()
{
return null;
} }
} }
...@@ -118,22 +118,21 @@ public class SocketChannelImpl extends SocketChannel ...@@ -118,22 +118,21 @@ public class SocketChannelImpl extends SocketChannel
public int read (ByteBuffer dst) throws IOException public int read (ByteBuffer dst) throws IOException
{ {
byte[] data;
int bytes = 0; int bytes = 0;
int len = 1024; int len = dst.remaining ();
byte[]b = new byte[len];
/* if (!dst.hasArray ())
bytes = SocketRead(fd, b, 0, len);
dst.put(b, 0, bytes);
if (bytes == 0)
{ {
// we've hit eof ? data = new byte [len];
return -1; dst.get (data, 0, len);
} }
*/ else
{
return bytes; data = dst.array ();
}
return socket.getInputStream().read (data, 0, len);
} }
public long read (ByteBuffer[] dsts, int offset, int length) public long read (ByteBuffer[] dsts, int offset, int length)
...@@ -152,24 +151,22 @@ public class SocketChannelImpl extends SocketChannel ...@@ -152,24 +151,22 @@ public class SocketChannelImpl extends SocketChannel
public int write (ByteBuffer src) public int write (ByteBuffer src)
throws IOException throws IOException
{ {
byte[] data;
int bytes = 0; int bytes = 0;
int len = src.position(); int len = src.remaining ();
/* if (!src.hasArray ())
if (src.hasArray ())
{ {
byte[] b = src.array (); data = new byte [len];
bytes = SocketWrite (fd, b, 0, len); src.get (data, 0, len);
} }
else else
{ {
byte[] b = new byte [len]; data = src.array ();
src.get (b, 0, len);
bytes = SocketWrite (fd, b, 0, len);
} }
*/
socket.getOutputStream().write (data, 0, len);
return bytes; return len;
} }
public long write (ByteBuffer[] srcs, int offset, int length) public long write (ByteBuffer[] srcs, int offset, int length)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment