From f31e284ace8df9ec2a32f25cee8719af88fcd1a9 Mon Sep 17 00:00:00 2001 From: Shmuel Kallner Date: Tue, 18 Jul 2017 11:30:40 +0300 Subject: [PATCH] Insure that the IncomingSocketProcessor used by an IncomingSocketHandler has the back link to the IncomingSocketHandler initialized before the ReaderSource is resumed. Also removed an unneeded back link to the InncomingSocketManager. --- Sources/KituraNet/IncomingSocketHandler.swift | 11 +++++------ Sources/KituraNet/IncomingSocketManager.swift | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) 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)