@@ -39,11 +39,7 @@ extension URLSession {
39
39
let group = DispatchGroup ( )
40
40
fileprivate var easyHandles : [ _EasyHandle ] = [ ]
41
41
fileprivate var timeoutSource : _TimeoutSource ? = nil
42
-
43
- //SR-4567: we need to synchronize the register/unregister commands to the epoll machinery in libdispatch
44
- fileprivate let commandQueue : DispatchQueue = DispatchQueue ( label: " Register-unregister synchronization " )
45
- fileprivate var cancelInProgress : DispatchSemaphore ? = nil
46
-
42
+
47
43
init ( configuration: URLSession . _Configuration , workQueue: DispatchQueue ) {
48
44
queue = DispatchQueue ( label: " MultiHandle.isolation " , target: workQueue)
49
45
setupCallbacks ( )
@@ -103,33 +99,25 @@ fileprivate extension URLSession._MultiHandle {
103
99
// through libdispatch (DispatchSource) and store the source(s) inside
104
100
// a `SocketSources` which we in turn store inside libcurl's multi handle
105
101
// by means of curl_multi_assign() -- we retain the object fist.
106
- commandQueue. async {
107
- self . cancelInProgress? . wait ( )
108
- self . cancelInProgress = nil
109
-
110
- let action = _SocketRegisterAction ( rawValue: CFURLSessionPoll ( value: what) )
111
- var socketSources = _SocketSources. from ( socketSourcePtr: socketSourcePtr)
112
- if socketSources == nil && action. needsSource {
113
- let s = _SocketSources ( )
114
- let p = Unmanaged . passRetained ( s) . toOpaque ( )
115
- CFURLSessionMultiHandleAssign ( self . rawHandle, socket, UnsafeMutableRawPointer ( p) )
116
- socketSources = s
117
- } else if socketSources != nil && action == . unregister {
118
- //the beginning of an unregister operation
119
- self . cancelInProgress = DispatchSemaphore ( value: 0 )
120
- // We need to release the stored pointer:
121
- if let opaque = socketSourcePtr {
122
- Unmanaged < _SocketSources > . fromOpaque ( opaque) . release ( )
123
- }
124
- socketSources? . tearDown ( self . cancelInProgress)
125
- socketSources = nil
102
+ let action = _SocketRegisterAction ( rawValue: CFURLSessionPoll ( value: what) )
103
+ var socketSources = _SocketSources. from ( socketSourcePtr: socketSourcePtr)
104
+ if socketSources == nil && action. needsSource {
105
+ let s = _SocketSources ( )
106
+ let p = Unmanaged . passRetained ( s) . toOpaque ( )
107
+ CFURLSessionMultiHandleAssign ( rawHandle, socket, UnsafeMutableRawPointer ( p) )
108
+ socketSources = s
109
+ } else if socketSources != nil && action == . unregister {
110
+ // We need to release the stored pointer:
111
+ if let opaque = socketSourcePtr {
112
+ Unmanaged < _SocketSources > . fromOpaque ( opaque) . release ( )
126
113
}
127
- if let ss = socketSources {
128
- let handler = DispatchWorkItem { [ weak self ] in
129
- self ? . performAction ( for : socket )
130
- }
131
- ss . createSources ( with : action , fileDescriptor : Int ( socket) , queue : self . queue , handler : handler )
114
+ socketSources = nil
115
+ }
116
+ if let ss = socketSources {
117
+ let handler = DispatchWorkItem { [ weak self ] in
118
+ self ? . performAction ( for : socket)
132
119
}
120
+ ss. createSources ( with: action, fileDescriptor: Int ( socket) , queue: queue, handler: handler)
133
121
}
134
122
return 0
135
123
}
@@ -411,18 +399,12 @@ fileprivate class _SocketSources {
411
399
s. resume ( )
412
400
}
413
401
414
- func tearDown( _ cancelInProgress: DispatchSemaphore ? ) {
415
- let cancelHandler = DispatchWorkItem {
416
- //the real end of an unregister operation!
417
- cancelInProgress? . signal ( )
418
- }
402
+ func tearDown( ) {
419
403
if let s = readSource {
420
- s. setCancelHandler ( handler: cancelHandler)
421
404
s. cancel ( )
422
405
}
423
406
readSource = nil
424
407
if let s = writeSource {
425
- s. setCancelHandler ( handler: cancelHandler)
426
408
s. cancel ( )
427
409
}
428
410
writeSource = nil
0 commit comments