Skip to content

Commit

Permalink
Kitura/Kitura#1034 Select which queue to use at initialization time i…
Browse files Browse the repository at this point in the history
… IncomingSocketHandler
  • Loading branch information
shmuelk authored and youming-lin committed Jul 6, 2017
1 parent 4e04498 commit dc135bc
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions Sources/KituraNet/IncomingSocketHandler.swift
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -45,9 +45,7 @@ public class IncomingSocketHandler {

private let numberOfSocketReaderQueues = IncomingSocketHandler.socketReaderQueues.count

private func socketReaderQueue(fd: Int32) -> DispatchQueue {
return IncomingSocketHandler.socketReaderQueues[Int(fd) % numberOfSocketReaderQueues];
}
private let socketReaderQueue: DispatchQueue
#endif

let socket: Socket
Expand Down Expand Up @@ -90,18 +88,21 @@ public class IncomingSocketHandler {
self.socket = socket
processor = using
manager = managedBy
processor?.handler = self

#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(fd: socket.socketfd))
queue: socketReaderQueue)

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
Expand Down Expand Up @@ -187,7 +188,7 @@ public class IncomingSocketHandler {
public func handleBufferedReadData() {
#if os(OSX) || os(iOS) || os(tvOS) || os(watchOS) || GCD_ASYNCH
if socket.socketfd != Socket.SOCKET_INVALID_DESCRIPTOR {
socketReaderQueue(fd: socket.socketfd).sync() { [unowned self] in
socketReaderQueue.sync() { [unowned self] in
_ = self.handleBufferedReadDataHelper()
}
}
Expand Down

0 comments on commit dc135bc

Please sign in to comment.