kainjow commented on code in PR #2670:
URL: https://github.com/apache/thrift/pull/2670#discussion_r979538939
##########
lib/swift/Sources/TSocketServer.swift:
##########
@@ -96,34 +96,29 @@ open class TSocketServer<InProtocol: TProtocol,
OutProtocol: TProtocol, Processo
// throw away our socket
CFSocketInvalidate(sock)
-
- // register for notifications of accepted incoming connections
- _ = NotificationCenter.default.addObserver(forName:
.NSFileHandleConnectionAccepted,
- object: nil, queue: nil) {
- [weak self] notification in
- guard let strongSelf = self
else { return }
- guard let clientSocket =
notification.userInfo?[NSFileHandleNotificationFileHandleItem] as? FileHandle
else { return }
-
strongSelf.connectionAccepted(clientSocket)
- }
-
- // tell socket to listen
- socketFileHandle.acceptConnectionInBackgroundAndNotify()
-
+
print("TSocketServer: Listening on TCP port \(port)")
+
+ // tell socket to listen
+ acceptConnectionInBackgroundAndNotify(handle: socketFileHandle)
}
-
- deinit {
- NotificationCenter.default.removeObserver(self)
+
+ open func acceptConnectionInBackgroundAndNotify(handle: FileHandle) {
+ DispatchQueue(label: "ConnectionAcceptQueue").async {
+ let acceptedFD = accept(handle.fileDescriptor, nil, nil)
+ DispatchQueue.main.async {
Review Comment:
maybe instead of hard coding DispatchQueue this could be a public property?
maybe a client would want to use a custom queue?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]