From 56bf08427b1d3768556f4600075e79a8d03c26d2 Mon Sep 17 00:00:00 2001 From: Nick Hudson Date: Tue, 13 Mar 2012 11:10:03 +0000 Subject: Fix up mistakes in previous patch I broke the "getLocalAddress()" method. This fixes it. Test-information: By debugging and looking at "JavaConnection.toString()" output diff --git a/src/com/isode/stroke/network/JavaConnection.java b/src/com/isode/stroke/network/JavaConnection.java index ade52f0..e5369bf 100644 --- a/src/com/isode/stroke/network/JavaConnection.java +++ b/src/com/isode/stroke/network/JavaConnection.java @@ -10,6 +10,7 @@ package com.isode.stroke.network; import java.io.IOException; import java.net.InetSocketAddress; +import java.net.Socket; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; import java.util.ArrayList; @@ -34,8 +35,8 @@ public class JavaConnection extends Connection implements EventOwner { public void run() { try { - InetSocketAddress isa = new InetSocketAddress(address_.getAddress().getInetAddress(),address_.getPort()); - socketChannel_ = SocketChannel.open(isa); + socketChannel_ = SocketChannel.open( + new InetSocketAddress(address_.getAddress().getInetAddress(),address_.getPort())); /* By default, SocketChannels start off in blocking mode, which * isn't what we want @@ -49,7 +50,7 @@ public class JavaConnection extends Connection implements EventOwner { while (!disconnecting_) { while (!writeBuffer_.isEmpty()) { ByteArray data = writeBuffer_.get(0); - ByteBuffer bb = ByteBuffer.wrap(data.getData()); + ByteBuffer byteBuffer = ByteBuffer.wrap(data.getData()); try { /* Because the SocketChannel is non-blocking, we have to * be prepared to cope with the write operation not @@ -57,8 +58,8 @@ public class JavaConnection extends Connection implements EventOwner { */ boolean finishedWriting = false; while (!finishedWriting && !disconnecting_) { - socketChannel_.write(bb); - finishedWriting = (bb.remaining() == 0); + socketChannel_.write(byteBuffer); + finishedWriting = (byteBuffer.remaining() == 0); if (!finishedWriting) { try { /* Give the output buffer a chance to empty */ @@ -78,18 +79,18 @@ public class JavaConnection extends Connection implements EventOwner { ByteArray data = new ByteArray(); try { - ByteBuffer bb = ByteBuffer.allocate(1024); + ByteBuffer byteBuffer = ByteBuffer.allocate(1024); - int count = socketChannel_.read(bb); + int count = socketChannel_.read(byteBuffer); while (count > 0) { - bb.flip(); - byte[] result = new byte[bb.remaining()]; - bb.get(result); - bb.compact(); + byteBuffer.flip(); + byte[] result = new byte[byteBuffer.remaining()]; + byteBuffer.get(result); + byteBuffer.compact(); for (int i=0; i