Skip to content

Commit 49440e5

Browse files
committed
simplify previous commit
use read(bytes:) instead of read(atMost:) to handle partial reads Fixes: #10
1 parent 6aa80af commit 49440e5

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

Sources/SwiftOCA/OCP.1/Backend/Ocp1FlyingSocksConnection.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,9 @@ public final class Ocp1FlyingSocksStreamConnection: Ocp1FlyingSocksConnection {
190190
override var socketType: SocketType { .stream }
191191

192192
override public func read(_ length: Int) async throws -> Data {
193-
var data = Data()
194-
195193
try await withMappedError { socket in
196-
while data.count < length {
197-
let receivedData = try await Data(socket.read(atMost: length - data.count))
198-
data += receivedData
199-
}
194+
try await Data(socket.read(bytes: length))
200195
}
201-
202-
return data
203196
}
204197

205198
override func setSocketOptions(_ socket: Socket) throws {

0 commit comments

Comments
 (0)