     private var didDisconnect = false
     private var readyToWrite = false
     private var headerSecKey = ""
-    private let mutex = NSLock()
+    private let readyToWriteMutex = NSLock()
     private let notificationCenter = NotificationCenter.default
     private var canDispatch: Bool {
-        mutex.lock()
+        readyToWriteMutex.lock()
         let canWork = readyToWrite
-        mutex.unlock()
+        readyToWriteMutex.unlock()
         return canWork
     }
     /// The shared processing queue used for all WebSocket.

        guard !didDisconnect else { return }
        didDisconnect = true
        isConnecting = false
        connected = false
        guard canDispatch else {return}
        callbackQueue.async { [weak self] in
            guard let s = self else { return }

        inStream.open()
        outStream.open()

        self.readyToWriteMutex.lock()
        self.readyToWrite = true
        self.readyToWriteMutex.unlock()
        
        let bytes = UnsafeRawPointer((data as NSData).bytes).assumingMemoryBound(to: UInt8.self)
        var out = timeout * 1_000_000 // wait 5 seconds before giving up
