Skip to content

5.1: Revert 02656bf6637d75ead56d628960c02569330b99c8 #2528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions CoreFoundation/URL.subproj/CFURLSessionInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ CFURLSessionEasyCode CFURLSession_easy_setopt_tc(CFURLSessionEasyHandle _Nonnull
return MakeEasyCode(curl_easy_setopt(curl, option.value, a));
}

CFURLSessionEasyCode CFURLSession_easy_setopt_csf(CFURLSessionEasyHandle _Nonnull curl, CFURLSessionOption option, int (*_Nonnull a)(void *_Nullable clientp, CFURLSession_socket_t)) {
return MakeEasyCode(curl_easy_setopt(curl, option.value, a));
}

CFURLSessionEasyCode CFURLSession_easy_getinfo_long(CFURLSessionEasyHandle _Nonnull curl, CFURLSessionInfo info, long *_Nonnull a) {
return MakeEasyCode(curl_easy_getinfo(curl, info.value, a));
}
Expand Down
2 changes: 1 addition & 1 deletion CoreFoundation/URL.subproj/CFURLSessionInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ CF_EXPORT CFURLSessionMultiCode CFURLSession_multi_setopt_ptr(CFURLSessionMultiH
CF_EXPORT CFURLSessionMultiCode CFURLSession_multi_setopt_l(CFURLSessionMultiHandle _Nonnull multi_handle, CFURLSessionMultiOption option, long a);
CF_EXPORT CFURLSessionMultiCode CFURLSession_multi_setopt_sf(CFURLSessionMultiHandle _Nonnull multi_handle, CFURLSessionMultiOption option, int (*_Nonnull a)(CFURLSessionEasyHandle _Nonnull, CFURLSession_socket_t, int, void *_Nullable, void *_Nullable));
CF_EXPORT CFURLSessionMultiCode CFURLSession_multi_setopt_tf(CFURLSessionMultiHandle _Nonnull multi_handle, CFURLSessionMultiOption option, int (*_Nonnull a)(CFURLSessionMultiHandle _Nonnull, long, void *_Nullable));
CF_EXPORT CFURLSessionEasyCode CFURLSession_easy_setopt_csf(CFURLSessionEasyHandle _Nonnull curl, CFURLSessionOption option, int (*_Nonnull a)(void* _Nullable clientp, CFURLSession_socket_t));

CF_EXPORT CFURLSessionEasyCode CFURLSessionInit(void);


Expand Down
8 changes: 0 additions & 8 deletions Foundation/URLSession/libcurl/EasyHandle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,6 @@ fileprivate extension _EasyHandle {
return 1
}
}.asError()

try! CFURLSession_easy_setopt_csf(rawHandle, CFURLSessionOptionCLOSESOCKETFUNCTION) { (clientp: UnsafeMutableRawPointer?, socket: CFURLSession_socket_t) -> Int32 in
// Don't let CURL close the socket here because the
// dispatch sources are associated with it and we need to
// cancel them before closing the file descriptor.
return 0
}.asError()

// seeking in input stream
try! CFURLSession_easy_setopt_ptr(rawHandle, CFURLSessionOptionSEEKDATA, UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque())).asError()
try! CFURLSession_easy_setopt_seek(rawHandle, CFURLSessionOptionSEEKFUNCTION, { (userdata, offset, origin) -> Int32 in
Expand Down
27 changes: 2 additions & 25 deletions Foundation/URLSession/libcurl/MultiHandle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ fileprivate extension URLSession._MultiHandle {
} else if socketSources != nil && action == .unregister {
// We need to release the stored pointer:
if let opaque = socketSourcePtr {
let s: Unmanaged<_SocketSources> = Unmanaged<_SocketSources>.fromOpaque(opaque)
s.takeUnretainedValue().tearDown(socket: socket, queue: queue)
s.release()
Unmanaged<_SocketSources>.fromOpaque(opaque).release()
}
socketSources = nil
}
Expand Down Expand Up @@ -409,7 +407,6 @@ fileprivate extension URLSession._MultiHandle._Timeout {
fileprivate class _SocketSources {
var readSource: DispatchSource?
var writeSource: DispatchSource?
let activeSockets = DispatchGroup()

func createReadSource(socket: CFURLSession_socket_t, queue: DispatchQueue, handler: DispatchWorkItem) {
guard readSource == nil else { return }
Expand All @@ -418,13 +415,7 @@ fileprivate class _SocketSources {
#else
let s = DispatchSource.makeReadSource(fileDescriptor: socket, queue: queue)
#endif
activeSockets.enter()
s.setEventHandler(handler: handler)
s.setCancelHandler(handler: DispatchWorkItem { [weak self] in
guard let self = self else { return }
self.activeSockets.leave()
})

readSource = s as? DispatchSource
s.resume()
}
Expand All @@ -436,26 +427,12 @@ fileprivate class _SocketSources {
#else
let s = DispatchSource.makeWriteSource(fileDescriptor: socket, queue: queue)
#endif
activeSockets.enter()
s.setCancelHandler(handler: DispatchWorkItem { [weak self] in
guard let self = self else { return }
self.activeSockets.leave()
})
s.setEventHandler(handler: handler)
writeSource = s as? DispatchSource
s.resume()
}

func tearDown(socket: CFURLSession_socket_t, queue: DispatchQueue) {
activeSockets.notify(queue: queue) {
withExtendedLifetime(self) {
#if os(Windows)
closesocket(socket)
#else
close(socket)
#endif
}
}
func tearDown() {
if let s = readSource {
s.cancel()
}
Expand Down