diff options
| -rw-r--r-- | src/com/isode/stroke/network/JavaConnection.java | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/src/com/isode/stroke/network/JavaConnection.java b/src/com/isode/stroke/network/JavaConnection.java index 745655f..c7464ba 100644 --- a/src/com/isode/stroke/network/JavaConnection.java +++ b/src/com/isode/stroke/network/JavaConnection.java | |||
| @@ -7,10 +7,8 @@ package com.isode.stroke.network; | |||
| 7 | import java.io.IOException; | 7 | import java.io.IOException; |
| 8 | import java.net.InetSocketAddress; | 8 | import java.net.InetSocketAddress; |
| 9 | import java.net.Socket; | 9 | import java.net.Socket; |
| 10 | import java.net.SocketAddress; | ||
| 11 | import java.nio.ByteBuffer; | 10 | import java.nio.ByteBuffer; |
| 12 | import java.nio.channels.CancelledKeyException; | 11 | import java.nio.channels.CancelledKeyException; |
| 13 | import java.nio.channels.ClosedChannelException; | ||
| 14 | import java.nio.channels.ClosedSelectorException; | 12 | import java.nio.channels.ClosedSelectorException; |
| 15 | import java.nio.channels.SelectionKey; | 13 | import java.nio.channels.SelectionKey; |
| 16 | import java.nio.channels.Selector; | 14 | import java.nio.channels.Selector; |
| @@ -48,6 +46,10 @@ public class JavaConnection extends Connection implements EventOwner { | |||
| 48 | private boolean isWriteNeeded() { | 46 | private boolean isWriteNeeded() { |
| 49 | return (!writeBuffer_.isEmpty()); | 47 | return (!writeBuffer_.isEmpty()); |
| 50 | } | 48 | } |
| 49 | |||
| 50 | public HostAddressPort getRemoteAddress() { | ||
| 51 | return address_; | ||
| 52 | } | ||
| 51 | 53 | ||
| 52 | public void run() { | 54 | public void run() { |
| 53 | try { | 55 | try { |
| @@ -518,27 +520,7 @@ public class JavaConnection extends Connection implements EventOwner { | |||
| 518 | 520 | ||
| 519 | @Override | 521 | @Override |
| 520 | public HostAddressPort getRemoteAddress() { | 522 | public HostAddressPort getRemoteAddress() { |
| 521 | if (socketChannel_ == null) { | 523 | return worker_.getRemoteAddress(); |
| 522 | return null; | ||
| 523 | } | ||
| 524 | SocketAddress remoteAddress; | ||
| 525 | try { | ||
| 526 | remoteAddress = socketChannel_.getRemoteAddress(); | ||
| 527 | } catch (ClosedChannelException e) { | ||
| 528 | return null; | ||
| 529 | } catch (IOException e) { | ||
| 530 | return null; | ||
| 531 | } | ||
| 532 | if (!(remoteAddress instanceof InetSocketAddress)) { | ||
| 533 | // SocketChannel.getRemoteAddress should return a | ||
| 534 | // InetSocketAddress if it is bound to an IP Socket | ||
| 535 | // Address so return null if it does not | ||
| 536 | return null; | ||
| 537 | } | ||
| 538 | InetSocketAddress remoteInetAddress = (InetSocketAddress) remoteAddress; | ||
| 539 | return new HostAddressPort( | ||
| 540 | new HostAddress(remoteInetAddress.getAddress()), | ||
| 541 | remoteInetAddress.getPort()); | ||
| 542 | } | 524 | } |
| 543 | 525 | ||
| 544 | @Override | 526 | @Override |
Swift