Skip to content

Commit

Permalink
Better read semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr. Brandon Wiley committed Oct 1, 2020
1 parent f3a7065 commit 12d1095
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Sources/TransmissionLinux/Connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Connection
var writeLock = DispatchGroup()

let socket: Socket
var buffer: Data = Data()

public init?(host: String, port: Int)
{
Expand Down Expand Up @@ -38,7 +39,7 @@ public class Connection
return nil
}

var data = Data(count: size)
var data = Data()

do
{
Expand All @@ -48,8 +49,18 @@ public class Connection
{
return nil
}

buffer.append(data)

if size > buffer.count
{
return nil
}

let result = buffer[0..<size]
buffer = buffer[size..<buffer.count]

return data
return result
}

public func write(string: String) -> Bool
Expand Down

0 comments on commit 12d1095

Please sign in to comment.