 		delegateQueue?.async {
 			self.delegate?.socket(self, didFailWithError: error)
 		}
-		disconnect()
+		disconnect(withError: error)
 	}
 	
 	private func setupSocketsSecurity() {

import Foundation

public protocol TCPSocketDelegate {
	
	func socketDidConnect (_ socket: TCPSocket)
	func socketDidDisconnect (_ socket: TCPSocket)
	
	func socket (_ socket: TCPSocket, didReceiveData data: Data)
	func socket (_ socket: TCPSocket, didFailWithError error: Error)
	
}

public class TCPSocket {

			self.disposeStreams()
			self.status = .closed(nil)
			self.delegateQueue?.async {
				self.delegate?.socketDidDisconnect(self, withError: nil)
			}
		}
	}
	
	private func disconnect(withError error: Error) {
		TCPSocket.workingThread.perform {
			self.disposeStreams()
			self.status = .closed(error)
			self.delegateQueue?.async {
				self.delegate?.socketDidDisconnect(self, withError: error)
			}
		}
	}
