Skip to content

Commit

Permalink
updates for swift 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiftrien committed Apr 26, 2019
1 parent 5451568 commit 7b0d89b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
20 changes: 7 additions & 13 deletions Sources/SwifterSockets/SwifterSockets.Connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
// File: SwifterSockets.Connection.swift
// Project: SwifterSockets
//
// Version: 0.10.11
// Version: 0.12.0
//
// Author: Marinus van der Lugt
// Company: http://balancingrock.nl
// Website: http://swiftfire.nl/pages/projects/swiftersockets/
// Blog: http://swiftrien.blogspot.com
// Git: https://github.com/Swiftrien/SwifterSockets
//
// Copyright: (c) 2016-2017 Marinus van der Lugt, All rights reserved.
// Copyright: (c) 2016-2019 Marinus van der Lugt, All rights reserved.
//
// License: Use or redistribute this code any way you like with the following two provision:
//
Expand All @@ -35,11 +35,6 @@
//
// (It is always a good idea to visit the website/blog/google to ensure that you actually pay me and not some imposter)
//
// For private and non-profit use the suggested price is the price of 1 good cup of coffee, say $4.
// For commercial use the suggested price is the price of 1 good meal, say $20.
//
// You are however encouraged to pay more ;-)
//
// Prices/Quotes for support, modifications or enhancements can be obtained from: [email protected]
//
// =====================================================================================================================
Expand All @@ -48,6 +43,7 @@
//
// History
//
// 0.12.0 - Replaced depreciated call in Swift 5
// 0.10.11 - Migration to Swift 4, minor adjustments.
// 0.10.8 - Made incrementUsageCount and decrementUsageCount public.
// 0.10.7 - Bugfix: partial reimplementation to prevent crashes due to clashes of receiver events and close events.
Expand Down Expand Up @@ -801,9 +797,8 @@ open class Connection: ReceiverProtocol, TransmitterProtocol {
callback: TransmitterProtocol? = nil,
progress: TransmitterProgressMonitor? = nil) -> TransferResult {

return data.withUnsafeBytes { (ptr: UnsafePointer<UInt8>) -> TransferResult in
let buffer = UnsafeBufferPointer<UInt8>.init(start: ptr, count: data.count)
return self.transfer(buffer, timeout: timeout, affectInactivityDetection: affectInactivityDetection, callback: callback, progress: progress)
return data.withUnsafeBytes { (buffer: UnsafeRawBufferPointer) -> TransferResult in
return self.transfer(buffer.bindMemory(to: UInt8.self), timeout: timeout, affectInactivityDetection: affectInactivityDetection, callback: callback, progress: progress)
}
}

Expand Down Expand Up @@ -949,9 +944,8 @@ open class Connection: ReceiverProtocol, TransmitterProtocol {
callback: TransmitterProtocol? = nil,
progress: TransmitterProgressMonitor? = nil) -> TransferResult {

return data.withUnsafeBytes { (ptr: UnsafePointer<UInt8>) -> TransferResult in
let buffer = UnsafeBufferPointer<UInt8>.init(start: ptr, count: data.count)
return self.bufferedTransfer(buffer, timeout: timeout, affectInactivityDetection: affectInactivityDetection, callback: callback, progress: progress)
return data.withUnsafeBytes { (buffer: UnsafeRawBufferPointer) -> TransferResult in
return self.bufferedTransfer(buffer.bindMemory(to: UInt8.self), timeout: timeout, affectInactivityDetection: affectInactivityDetection, callback: callback, progress: progress)
}
}

Expand Down
15 changes: 5 additions & 10 deletions Sources/SwifterSockets/SwifterSockets.Transmit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
// File: SwifterSockets.Transmit.swift
// Project: SwifterSockets
//
// Version: 0.10.6
// Version: 0.12.0
//
// Author: Marinus van der Lugt
// Company: http://balancingrock.nl
// Website: http://swiftfire.nl/pages/projects/swiftersockets/
// Blog: http://swiftrien.blogspot.com
// Git: https://github.com/Balancingrock/SwifterSockets
//
// Copyright: (c) 2014-2017 Marinus van der Lugt, All rights reserved.
// Copyright: (c) 2014-2019 Marinus van der Lugt, All rights reserved.
//
// License: Use or redistribute this code any way you like with the following two provision:
//
Expand All @@ -35,11 +35,6 @@
//
// (It is always a good idea to visit the website/blog/google to ensure that you actually pay me and not some imposter)
//
// For private and non-profit use the suggested price is the price of 1 good cup of coffee, say $4.
// For commercial use the suggested price is the price of 1 good meal, say $20.
//
// You are however encouraged to pay more ;-)
//
// Prices/Quotes for support, modifications or enhancements can be obtained from: [email protected]
//
// =====================================================================================================================
Expand All @@ -48,6 +43,7 @@
//
// History
//
// 0.12.0 - Replaced depreciated call in Swift 5
// 0.10.6 - Added closing of the socket on transmitterClosed.
// 0.9.14 - Moved transmitter protocol to this file
// - Moved progress signature to this file
Expand Down Expand Up @@ -332,9 +328,8 @@ public func tipTransfer(
callback: TransmitterProtocol? = nil,
progress: TransmitterProgressMonitor? = nil) -> TransferResult {

return data.withUnsafeBytes { (ptr: UnsafePointer<UInt8>) -> TransferResult in
let ubptr = UnsafeBufferPointer<UInt8>.init(start: ptr, count: data.count)
return tipTransfer(socket: socket, buffer: ubptr, timeout: timeout, callback: callback, progress: progress)
return data.withUnsafeBytes { (urbp: UnsafeRawBufferPointer) -> TransferResult in
return tipTransfer(socket: socket, buffer: urbp.bindMemory(to: UInt8.self), timeout: timeout, callback: callback, progress: progress)
}
}

Expand Down

0 comments on commit 7b0d89b

Please sign in to comment.