Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix data races #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Example/SwiftCentrifuge/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class ViewController: UIViewController {
NotificationCenter.default.addObserver(self, selector: #selector(self.connectClient(_:)), name: UIApplication.didBecomeActiveNotification, object: nil)

let config = CentrifugeClientConfig(
token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0c3VpdGVfand0In0.hPmHsVqvtY88PvK4EmJlcdwNuKFuy3BGaF7dMaKdPlw",
tokenGetter: self,
logger: PrintLogger()
)
Expand Down Expand Up @@ -92,7 +91,8 @@ class ViewController: UIViewController {

extension ViewController: CentrifugeConnectionTokenGetter {
func getConnectionToken(_ event: CentrifugeConnectionTokenEvent, completion: @escaping (Result<String, Error>) -> ()) {
completion(.success(""))
let token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0c3VpdGVfand0In0.hPmHsVqvtY88PvK4EmJlcdwNuKFuy3BGaF7dMaKdPlw"
completion(.success(token))
}
}

Expand Down
7 changes: 6 additions & 1 deletion Sources/SwiftCentrifuge/WebSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -766,15 +766,20 @@ class WebSocket : NSObject, StreamDelegate, WebSocketClient, WSStreamDelegate {
autoreleasepool {
let data = inputQueue[0]
var work = data
mutex.lock()
if let buffer = fragBuffer {
var combine = NSData(data: buffer) as Data
combine.append(data)
work = combine
fragBuffer = nil
}
mutex.unlock()
let buffer = UnsafeRawPointer((work as NSData).bytes).assumingMemoryBound(to: UInt8.self)
let length = work.count
if !connected {
mutex.lock()
let isConnected = connected
mutex.unlock()
if !isConnected {
processTCPHandshake(buffer, bufferLen: length)
} else {
processRawMessagesInBuffer(buffer, bufferLen: length)
Expand Down
Loading