Skip to content

Commit

Permalink
Fix subscription on Xcode-10.2 (aciidgh#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
kervich committed Jun 28, 2019
1 parent 6667e19 commit 58bef81
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
language: objective-c
osx_image: xcode9.2
language: objective-c
os: osx
osx_image: xcode10.2
xcode_sdk: iphonesimulator10.2

before_install:
- brew update
- brew install mosquitto
Expand Down
18 changes: 14 additions & 4 deletions SwiftMQTT/SwiftMQTT/Models/MQTTStreamable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,42 @@ extension Data: MQTTStreamable {
mutating func read(from read: StreamReader) -> Bool {
let totalLength = self.count
var readLength: Int = 0
self.withUnsafeBytes { (buffer: UnsafePointer<UInt8>) in

let _ = self.withUnsafeMutableBytes { (buffer) -> UInt8 in
repeat {
let b = UnsafeMutablePointer(mutating: buffer) + readLength
let point = buffer.bindMemory(to: UInt8.self)
let unsafePointer = point.baseAddress!
let b = UnsafeMutablePointer(mutating: unsafePointer) + readLength
let bytesRead = read(b, totalLength - readLength)
if bytesRead < 0 {
break
}
readLength += bytesRead
} while readLength < totalLength
return 0
}

return readLength == totalLength
}


func write(to write: StreamWriter) -> Bool {
let totalLength = self.count
guard totalLength <= 128*128*128 else { return false }
var writeLength: Int = 0
self.withUnsafeBytes { (buffer: UnsafePointer<UInt8>) in

let _ = self.withUnsafeBytes { (buffer) -> UInt8 in
repeat {
let b = UnsafeMutablePointer(mutating: buffer) + writeLength
let point = buffer.bindMemory(to: UInt8.self)
let unsafePointer = point.baseAddress!
let b = UnsafeMutablePointer(mutating: unsafePointer) + writeLength
let byteWritten = write(b, totalLength - writeLength)
if byteWritten < 0 {
break
}
writeLength += byteWritten
} while writeLength < totalLength
return 0
}
return writeLength == totalLength
}
Expand Down

0 comments on commit 58bef81

Please sign in to comment.