Skip to content

Commit

Permalink
added read(maxSize:)
Browse files Browse the repository at this point in the history
  • Loading branch information
consuelita committed Sep 28, 2021
1 parent afc3abf commit 93c3ffd
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Sources/Transmission/Connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,35 @@ public class Connection
return result
}

public func read(maxSize: Int) -> Data?
{
print("TransmissionLinux read called: \(#file), \(#line)")
var result: Data?

self.readLock.enter()
self.connection.receive(minimumIncompleteLength: 1, maximumLength: maxSize)
{
(maybeData, maybeContext, isComplete, maybeError) in

guard maybeError == nil else
{
self.readLock.leave()
return
}

if let data = maybeData
{
result = data
}

self.readLock.leave()
}

readLock.wait()

return result
}

public func write(string: String) -> Bool
{
print("TransmissionLinux write called: \(#file), \(#line)")
Expand Down

0 comments on commit 93c3ffd

Please sign in to comment.