远程主机强行关闭连接

时间:2014-06-09 17:01:07

标签: java sockets socketchannel iscsi

我的jSCSI implamantation中有一个java.nio.channels.SocketChannel在我尝试打开大小超过4GB的驱动程序时断开连接。 iscsi RFC表示BasicHeaderSegment.BHS_FIXED_SIZE可能是48,所以在这个位置我可以读取通道上的字节。 java doc说5种类型的错误,但是我的应用程序抛弃了最后一个没有说出特定信息的错误。 1 - NotYetConnectedException 2 - ClosedChannelException 3 - AsynchronousCloseException 4 - ClosedByInterruptException 5 - IOException

public final int read(final SocketChannel sChannel) throws InternetSCSIException, IOException, DigestException {
// read Basic Header Segment first to determine the total length of this
// Protocol Data Unit.
clear();

final ByteBuffer bhs = ByteBuffer.allocate(BasicHeaderSegment.BHS_FIXED_SIZE);
int len = 0;
while (len < BasicHeaderSegment.BHS_FIXED_SIZE) {
    int lens = sChannel.read(bhs);
    if (lens == -1) {
        // The Channel was closed at the Target (e.g. the Target does
        // not support Multiple Connections)
        // throw new ClosedChannelException();
        return lens;
    }
    len += lens;
    LOGGER.trace("Receiving through SocketChannel: " + len + " of maximal " + BasicHeaderSegment.BHS_FIXED_SIZE);

}
bhs.flip();

错误:

java.io.IOException: An existing connection was forcibly closed by the remote host
    at sun.nio.ch.SocketDispatcher.read0(Native Method)
    at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
    at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
    at sun.nio.ch.IOUtil.read(IOUtil.java:197)
    at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:379)
    at org.jscsi.parser.ProtocolDataUnit.read(ProtocolDataUnit.java:417)
    at org.jscsi.target.connection.TargetSenderWorker.receiveFromWire(TargetSenderWorker.java:145)
    at org.jscsi.target.connection.Connection$TargetConnection.receivePdu(Connection.java:217)
    at org.jscsi.target.connection.phase.TargetFullFeaturePhase.execute(TargetFullFeaturePhase.java:96)
    at org.jscsi.target.connection.Connection$TargetConnection.call(Connection.java:264)
    at org.jscsi.target.connection.Connection$TargetConnection.call(Connection.java:79)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
[pool-9-thread-1] INFO org.jscsi.target.connection

提前致谢, 菲利普

2 个答案:

答案 0 :(得分:4)

您的问题描述不正确。 SocketChannel未关闭:连接是;当你试图打开连接时它就不会发生了:当你从中读取它时就会发生这种情况。

这通常是因为在对等方已经关闭连接之后发送了一些内容,这反过来通常意味着您之前已经发送了一些它不理解的东西。

答案 1 :(得分:0)

由于某种问题,看起来对方已经断开了你。假设您正在开发启动器,则应检查目标(服务器)系统日志。

你能解释4GB的评论吗?我的意思是,确切地做了什么&#34;打开一个大小超过4GB的驱动程序&#34;什么驱动程序?