Commit a6c607de authored by Daniel Wolf's avatar Daniel Wolf

Drop socket from ReceivedAnswer

parent 96f138ef
......@@ -193,13 +193,13 @@ open class SocketBasedFutureAnswer<T>(token: DeviceWriteToken,
val inStream = DataInputStream(it.getInputStream())
val data = ByteArray(inStream.readUnsignedShort())
val actualRead = inStream.read(data)
ReceivedAnswer(data.copyOf(actualRead), socket, actualRead)
ReceivedAnswer(data.copyOf(actualRead), actualRead)
}
is DatagramSocket -> {
val datagramData = ByteArray(udpPacketSize)
val replyPacket = DatagramPacket(datagramData, datagramData.size)
it.receive(replyPacket)
ReceivedAnswer(datagramData.copyOf(replyPacket.length), socket)
ReceivedAnswer(datagramData.copyOf(replyPacket.length))
}
else -> throw IllegalStateException()
}
......@@ -248,13 +248,13 @@ abstract class SocketBasedNonPollableFutureAnswer<T>(token: DeviceWriteToken,
val inStream = DataInputStream(it.getInputStream())
val data = ByteArray(inStream.readUnsignedShort())
val actualRead = inStream.read(data)
ReceivedAnswer(data.copyOf(actualRead), socket, actualRead)
ReceivedAnswer(data.copyOf(actualRead), actualRead)
}
is DatagramSocket -> {
val datagramData = ByteArray(udpPacketSize)
val replyPacket = DatagramPacket(datagramData, datagramData.size)
it.receive(replyPacket)
ReceivedAnswer(datagramData.copyOf(replyPacket.length), socket)
ReceivedAnswer(datagramData.copyOf(replyPacket.length))
}
else -> throw IllegalStateException()
}
......@@ -284,14 +284,13 @@ abstract class SocketBasedNonPollableFutureAnswer<T>(token: DeviceWriteToken,
open class Answer internal constructor(open val bytesTransferred: Int)
data class FailedAnswer(val exception: Exception):Answer(0)
data class ReceivedAnswer(val rawResponse: ByteArray, val socket: Closeable, override val bytesTransferred: Int = rawResponse.size):Answer(bytesTransferred) {
data class ReceivedAnswer(val rawResponse: ByteArray, override val bytesTransferred: Int = rawResponse.size):Answer(bytesTransferred) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is ReceivedAnswer) return false
if (!rawResponse.contentEquals(other.rawResponse)) return false
if (socket != other.socket) return false
if (bytesTransferred != other.bytesTransferred) return false
return true
......@@ -299,8 +298,7 @@ data class ReceivedAnswer(val rawResponse: ByteArray, val socket: Closeable, ove
override fun hashCode(): Int {
var result = rawResponse.contentHashCode()
result = 31 * result + socket.hashCode()
result = 31 * result + bytesTransferred
result = 21 * result + bytesTransferred
return result
}
}
\ No newline at end of file
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