Skip to content

Commit

Permalink
sockets buffer update
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 committed May 1, 2017
1 parent 46a612f commit 62ff9d1
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions Sources/TLS/ReadableSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ extension ReadableSocket {
/// Receives bytes from the secure socket.
///
/// - parameter max: The maximum amount of bytes to receive.
public func read(max: Int) throws -> Bytes {
let pointer = UnsafeMutablePointer<Byte>
.allocate(capacity: max)
defer {
pointer.deallocate(capacity: max)
}

let bytesRead = SSL_read(cSSL, pointer, Int32(max))
public func read(max: Int, into buffer: inout Bytes) throws -> Int {
let bytesRead = SSL_read(cSSL, &buffer, Int32(max))

if bytesRead <= 0 {
throw makeError(
Expand All @@ -22,10 +16,6 @@ extension ReadableSocket {
)
}

let buffer = UnsafeBufferPointer<Byte>.init(
start: pointer,
count: Int(bytesRead)
)
return Array(buffer)
return Int(bytesRead)
}
}

0 comments on commit 62ff9d1

Please sign in to comment.