diff --git a/Sources/KituraNet/IncomingSocketHandler.swift b/Sources/KituraNet/IncomingSocketHandler.swift index 65f20c2..5f576a0 100644 --- a/Sources/KituraNet/IncomingSocketHandler.swift +++ b/Sources/KituraNet/IncomingSocketHandler.swift @@ -53,8 +53,6 @@ public class IncomingSocketHandler { /// The `IncomingSocketProcessor` instance that processes data read from the underlying socket. public var processor: IncomingSocketProcessor? - private weak var manager: IncomingSocketManager? - private let readBuffer = NSMutableData() private let writeBuffer = NSMutableData() private var writeBufferPosition = 0 @@ -84,25 +82,26 @@ public class IncomingSocketHandler { /// The file descriptor of the incoming socket var fileDescriptor: Int32 { return socket.socketfd } - init(socket: Socket, using: IncomingSocketProcessor, managedBy: IncomingSocketManager) { + init(socket: Socket, using: IncomingSocketProcessor) { self.socket = socket processor = using - manager = managedBy #if os(OSX) || os(iOS) || os(tvOS) || os(watchOS) || GCD_ASYNCH socketReaderQueue = IncomingSocketHandler.socketReaderQueues[Int(socket.socketfd) % numberOfSocketReaderQueues] readerSource = DispatchSource.makeReadSource(fileDescriptor: socket.socketfd, queue: socketReaderQueue) + #endif + + processor?.handler = self + #if os(OSX) || os(iOS) || os(tvOS) || os(watchOS) || GCD_ASYNCH readerSource.setEventHandler() { _ = self.handleRead() } readerSource.setCancelHandler(handler: self.handleCancel) readerSource.resume() #endif - - processor?.handler = self } /// Read in the available data and hand off to common processing code diff --git a/Sources/KituraNet/IncomingSocketManager.swift b/Sources/KituraNet/IncomingSocketManager.swift index 21f9466..bec3855 100644 --- a/Sources/KituraNet/IncomingSocketManager.swift +++ b/Sources/KituraNet/IncomingSocketManager.swift @@ -1,5 +1,5 @@ /* - * Copyright IBM Corporation 2016 + * Copyright IBM Corporation 2016, 2017 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -117,7 +117,7 @@ public class IncomingSocketManager { do { try socket.setBlocking(mode: false) - let handler = IncomingSocketHandler(socket: socket, using: processor, managedBy: self) + let handler = IncomingSocketHandler(socket: socket, using: processor) socketHandlers[socket.socketfd] = handler #if !GCD_ASYNCH && os(Linux)