kinoroy commented on code in PR #2670:
URL: https://github.com/apache/thrift/pull/2670#discussion_r979541699
##########
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:
I don't think this should be exposed. We have to do it this way rn because
NotificationCenter doesn't seem to be delivering notifications on Linux
targets. We'd probably prefer to use the system implementation of `FileHandle.
acceptConnectionInBackgroundAndNotify` and so in the future if this is fixed on
Linux in the CoreFoundation implementation then we might want to move back to
that and having this queue exposed as public API would be a breaking change.
--
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]