         }
     }
     
-    private func closeOutEngine() {
+    private func closeOutEngine(reason: String) {
         sid = ""
         closed = true
         invalidated = true

        
        ws?.disconnect()
        stopPolling()
    }
    
    /// Starts the connection to the server

    }
    
    public func disconnect(reason: String) {
        guard connected else { return closeOutEngine(reason) }
        
        DefaultSocketLogger.Logger.log("Engine is being closed.", type: logType)
        
        if closed {
            return closeOutEngine(reason)
        }
        
        if websocket {
            sendWebSocketMessage("", withType: .Close, withData: [])
            closeOutEngine(reason)
        } else {
            disconnectPolling(reason)
        }
    }
    
    // We need to take special care when we're polling that we send it ASAP
    // Also make sure we're on the emitQueue since we're touching postWait
    private func disconnectPolling(reason: String) {
        dispatch_sync(emitQueue) {
            self.postWait.append(String(SocketEnginePacketType.Close.rawValue))
            let req = self.createRequestForPostWithPostWait()
            self.doRequest(req) {_, _, _ in }
            self.closeOutEngine(reason)
        }
    }

