Skip to content

Revert "Implements URLSessionWebSocketTask" #4660

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

Closed
wants to merge 1 commit into from
Closed
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
77 changes: 0 additions & 77 deletions CoreFoundation/URL.subproj/CFURLSessionInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
//===----------------------------------------------------------------------===//

#include "CFURLSessionInterface.h"
#include <CoreFoundation/CFInternal.h>
#include <CoreFoundation/CFString.h>
#include <curl/curl.h>

Expand Down Expand Up @@ -140,61 +139,6 @@ CFURLSessionEasyCode CFURLSessionInit(void) {
return MakeEasyCode(curl_global_init(CURL_GLOBAL_SSL));
}

#if LIBCURL_VERSION_MAJOR > 7 || (LIBCURL_VERSION_MAJOR == 7 && LIBCURL_VERSION_MINOR >= 86)

Boolean CFURLSessionWebSocketsSupported(void) {
curl_version_info_data *info = curl_version_info(CURLVERSION_NOW);
for (int i = 0; ; i++) {
const char * const protocol = info->protocols[i];
if (protocol == NULL) {
break;
}
if ((0 == strncmp(protocol, "ws", 2)) ||
(0 == strncmp(protocol, "wss", 3))) {
return true;
}
}
return false;
}

CFURLSessionEasyCode CFURLSessionEasyHandleWebSocketsReceive(CFURLSessionEasyHandle _Nonnull handle, char *_Nonnull data, size_t dataLen, size_t * _Nonnull receivedDataLen, CFURLSessionWebSocketsFrame * _Nullable receivedFrame) {
CURLcode retVal = curl_ws_recv(handle, data, dataLen, receivedDataLen, (struct curl_ws_frame **)receivedFrame);
return MakeEasyCode(retVal);
}

CFURLSessionEasyCode CFURLSessionEasyHandleWebSocketsSend(CFURLSessionEasyHandle _Nonnull handle, const char *_Nonnull data, size_t dataLen, size_t * _Nonnull writtenDataLen, long long frameSize, CFURLSessionWebSocketsMessageFlag messageFlags) {
CURLcode retVal = curl_ws_send(handle, data, dataLen, writtenDataLen, frameSize, messageFlags);
return MakeEasyCode(retVal);
}

CFURLSessionWebSocketsFrame * _Nonnull CFURLSessionEasyHandleWebSocketsMetadata(CFURLSessionEasyHandle _Nonnull handle) {
return (CFURLSessionWebSocketsFrame *)curl_ws_meta(handle);
}

#else

Boolean CFURLSessionWebSocketsSupported(void) {
return false;
}

CFURLSessionEasyCode CFURLSessionEasyHandleWebSocketsReceive(CFURLSessionEasyHandle _Nonnull handle, char *_Nonnull data, size_t dataLen, size_t * _Nonnull receivedDataLen, CFURLSessionWebSocketsFrame * _Nullable receivedFrame) {
CFAssert(false, __kCFLogAssertion, "Cannot use WebSockets functions without libcurl >= 7.86.0");
return CFURLSessionEasyCodeNOT_BUILT_IN;
}
CFURLSessionEasyCode CFURLSessionEasyHandleWebSocketsSend(CFURLSessionEasyHandle _Nonnull handle, const char *_Nonnull data, size_t dataLen, size_t * _Nonnull writtenDataLen, long long frameSize, CFURLSessionWebSocketsMessageFlag messageFlags) {
CFAssert(false, __kCFLogAssertion, "Cannot use WebSockets functions without libcurl >= 7.86.0");
return CFURLSessionEasyCodeNOT_BUILT_IN;
}

struct CFURLSessionWebSocketsFrame emptyFrame = { 0, 0, 0, 0 };

CFURLSessionWebSocketsFrame * _Nonnull CFURLSessionEasyHandleWebSocketsMetadata(CFURLSessionEasyHandle _Nonnull handle) {
CFAssert(false, __kCFLogAssertion, "Cannot use WebSockets functions without libcurl >= 7.86.0");
return &emptyFrame;
}

#endif

int const CFURLSessionEasyErrorSize = { CURL_ERROR_SIZE + 1 };

CFURLSessionEasyCode const CFURLSessionEasyCodeOK = { CURLE_OK };
Expand Down Expand Up @@ -318,27 +262,6 @@ CFURLSessionProtocol const CFURLSessionProtocolGOPHER = CURLPROTO_GOPHER;
CFURLSessionProtocol const CFURLSessionProtocolALL = CURLPROTO_ALL;


#if LIBCURL_VERSION_MAJOR > 7 || (LIBCURL_VERSION_MAJOR == 7 && LIBCURL_VERSION_MINOR >= 86)
CFURLSessionWebSocketsMessageFlag const CFURLSessionWebSocketsText = CURLWS_TEXT;
CFURLSessionWebSocketsMessageFlag const CFURLSessionWebSocketsBinary = CURLWS_BINARY;
CFURLSessionWebSocketsMessageFlag const CFURLSessionWebSocketsCont = CURLWS_CONT;
CFURLSessionWebSocketsMessageFlag const CFURLSessionWebSocketsClose = CURLWS_CLOSE;
CFURLSessionWebSocketsMessageFlag const CFURLSessionWebSocketsPing = CURLWS_PING;
CFURLSessionWebSocketsMessageFlag const CFURLSessionWebSocketsPong = CURLWS_PONG;

CFURLSessionOption const CFURLSessionWebSocketsRawMode = { CURLWS_RAW_MODE };
#else
CFURLSessionWebSocketsMessageFlag const CFURLSessionWebSocketsText = -1;
CFURLSessionWebSocketsMessageFlag const CFURLSessionWebSocketsBinary = -1;
CFURLSessionWebSocketsMessageFlag const CFURLSessionWebSocketsCont = -1;
CFURLSessionWebSocketsMessageFlag const CFURLSessionWebSocketsClose = -1;
CFURLSessionWebSocketsMessageFlag const CFURLSessionWebSocketsPing = -1;
CFURLSessionWebSocketsMessageFlag const CFURLSessionWebSocketsPong = -1;

CFURLSessionOption const CFURLSessionWebSocketsRawMode = { -1 };
#endif


size_t const CFURLSessionMaxWriteSize = CURL_MAX_WRITE_SIZE;


Expand Down
29 changes: 0 additions & 29 deletions CoreFoundation/URL.subproj/CFURLSessionInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,35 +541,6 @@ CF_EXPORT CFURLSessionProtocol const CFURLSessionProtocolGOPHER; // CURLPROTO_GO
CF_EXPORT CFURLSessionProtocol const CFURLSessionProtocolALL; // CURLPROTO_ALL


// The following WebSockets symbols are -1 on libcurl < 7.86.0, or when WebSockets are disabled

typedef unsigned int CFURLSessionWebSocketsMessageFlag;

CF_EXPORT CFURLSessionWebSocketsMessageFlag const CFURLSessionWebSocketsText; // CURLWS_TEXT
CF_EXPORT CFURLSessionWebSocketsMessageFlag const CFURLSessionWebSocketsBinary; // CURLWS_BINARY
CF_EXPORT CFURLSessionWebSocketsMessageFlag const CFURLSessionWebSocketsCont; // CURLWS_CONT
CF_EXPORT CFURLSessionWebSocketsMessageFlag const CFURLSessionWebSocketsClose; // CURLWS_CLOSE
CF_EXPORT CFURLSessionWebSocketsMessageFlag const CFURLSessionWebSocketsPing; // CURLWS_PING
CF_EXPORT CFURLSessionWebSocketsMessageFlag const CFURLSessionWebSocketsPong; // CURLWS_PONG

CF_EXPORT CFURLSessionOption const CFURLSessionWebSocketsRawMode; // CURLWS_RAW_MODE

// The following WebSockets functions are functional with libcurl 7.86.0 or later, when WebSockets support is enabled. On libcurl versions without WebSockets support, they'll trap on use. Consult CFURLSessionWebSocketsSupported() to get a runtime signal whether they're functional.
CF_EXPORT Boolean CFURLSessionWebSocketsSupported(void);

typedef struct CFURLSessionWebSocketsFrame {
int age; /* always zero */
CFURLSessionWebSocketsMessageFlag flags;
long long offset;
long long bytesLeft;
} CFURLSessionWebSocketsFrame;

CF_EXPORT CFURLSessionEasyCode CFURLSessionEasyHandleWebSocketsReceive(CFURLSessionEasyHandle _Nonnull handle, char *_Nonnull data, size_t dataLen, size_t * _Nonnull receivedDataLen, CFURLSessionWebSocketsFrame * _Nullable receivedFrame);
CF_EXPORT CFURLSessionEasyCode CFURLSessionEasyHandleWebSocketsSend(CFURLSessionEasyHandle _Nonnull handle, const char *_Nonnull data, size_t dataLen, size_t * _Nonnull writtenDataLen, long long frameSize, CFURLSessionWebSocketsMessageFlag messageFlags);

CF_EXPORT CFURLSessionWebSocketsFrame * _Nonnull CFURLSessionEasyHandleWebSocketsMetadata(CFURLSessionEasyHandle _Nonnull handle);


CF_EXPORT size_t const CFURLSessionMaxWriteSize; // CURL_MAX_WRITE_SIZE

CF_EXPORT char * _Nonnull CFURLSessionCurlVersionString(void);
Expand Down
10 changes: 5 additions & 5 deletions Docs/API Surface.tasks
Original file line number Diff line number Diff line change
Expand Up @@ -9901,9 +9901,9 @@ API Surface:
- uploadTask(with:fromFile:) @done
- uploadTask(with:fromFile:completionHandler:) @done
- uploadTask(withStreamedRequest:) @done
- webSocketTask(with:) @done
- webSocketTask(with:) @done
- webSocketTask(with:protocols:) @done
- webSocketTask(with:)
- webSocketTask(with:)
- webSocketTask(with:protocols:)
- URLSessionConfiguration
- allowsCellularAccess @done
- allowsConstrainedNetworkAccess
Expand Down Expand Up @@ -10104,12 +10104,12 @@ API Surface:
- URLSessionUploadTask @done
- init()
- new() @done @unsupported @useSwiftForMemoryManagement
- URLSessionWebSocketDelegate @done
- URLSessionWebSocketDelegate
- urlSession(_:webSocketTask:didCloseWith:reason:)
- Swift.Void
- urlSession(_:webSocketTask:didOpenWithProtocol:)
- Swift.Void
- URLSessionWebSocketTask @done
- URLSessionWebSocketTask
- CloseCode
- RawValue
- abnormalClosure
Expand Down
26 changes: 7 additions & 19 deletions Foundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
159884921DCC877700E3314C /* TestHTTPCookieStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 159884911DCC877700E3314C /* TestHTTPCookieStorage.swift */; };
15A619DC245A2895003C8C62 /* libCFXMLInterface.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1550106A22EA24D10088F082 /* libCFXMLInterface.a */; };
15A619E0245A298C003C8C62 /* CFXMLInterface.c in Sources */ = {isa = PBXBuildFile; fileRef = 15A619DF245A298C003C8C62 /* CFXMLInterface.c */; };
15B80388228F376000B30FF6 /* libcurl.4.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B1FD9E01D6D178E0080E83C /* libcurl.4.dylib */; };
15B80388228F376000B30FF6 /* libcurl.3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B1FD9E01D6D178E0080E83C /* libcurl.3.dylib */; };
15B8039E228F376000B30FF6 /* URLProtectionSpace.swift in Sources */ = {isa = PBXBuildFile; fileRef = EADE0B821BD15DFF00C49C64 /* URLProtectionSpace.swift */; };
15B803B4228F376000B30FF6 /* URLCredential.swift in Sources */ = {isa = PBXBuildFile; fileRef = EADE0B7F1BD15DFF00C49C64 /* URLCredential.swift */; };
15B803CF228F376000B30FF6 /* URLAuthenticationChallenge.swift in Sources */ = {isa = PBXBuildFile; fileRef = EADE0B7D1BD15DFF00C49C64 /* URLAuthenticationChallenge.swift */; };
Expand Down Expand Up @@ -108,7 +108,6 @@
528776191BF27D9500CB0090 /* Test.plist in Resources */ = {isa = PBXBuildFile; fileRef = 528776181BF27D9500CB0090 /* Test.plist */; };
555683BD1C1250E70041D4C6 /* TestUserDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555683BC1C1250E70041D4C6 /* TestUserDefaults.swift */; };
559451EC1F706BFA002807FB /* CFXMLPreferencesDomain.c in Sources */ = {isa = PBXBuildFile; fileRef = 559451EA1F706BF5002807FB /* CFXMLPreferencesDomain.c */; };
5A6AC80C28E7BC8F00A22FA7 /* WebSocketURLProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A6AC80A28E7652D00A22FA7 /* WebSocketURLProtocol.swift */; };
5B0163BB1D024EB7003CCD96 /* DateComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B0163BA1D024EB7003CCD96 /* DateComponents.swift */; };
5B13B3251C582D4700651CE2 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA66F6381BF1619600136161 /* main.swift */; };
5B13B3261C582D4C00651CE2 /* TestAffineTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = C93559281C12C49F009FD6A9 /* TestAffineTransform.swift */; };
Expand Down Expand Up @@ -155,7 +154,7 @@
5B13B3511C582D4C00651CE2 /* TestByteCountFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5A34B551C18C85D00FD972B /* TestByteCountFormatter.swift */; };
5B13B3521C582D4C00651CE2 /* TestNSValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3047AEB1C38BC3300295652 /* TestNSValue.swift */; };
5B1FD9C51D6D16150080E83C /* CFURLSessionInterface.c in Sources */ = {isa = PBXBuildFile; fileRef = 5B1FD9C11D6D160F0080E83C /* CFURLSessionInterface.c */; };
5B1FD9E11D6D178E0080E83C /* libcurl.4.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B1FD9E01D6D178E0080E83C /* libcurl.4.dylib */; };
5B1FD9E11D6D178E0080E83C /* libcurl.3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B1FD9E01D6D178E0080E83C /* libcurl.3.dylib */; };
5B1FD9E31D6D17B80080E83C /* TestURLSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B1FD9E21D6D17B80080E83C /* TestURLSession.swift */; };
5B23AB891CE62D4D000DB898 /* ReferenceConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B23AB881CE62D4D000DB898 /* ReferenceConvertible.swift */; };
5B23AB8B1CE62F9B000DB898 /* PersonNameComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B23AB8A1CE62F9B000DB898 /* PersonNameComponents.swift */; };
Expand Down Expand Up @@ -852,12 +851,11 @@
528776181BF27D9500CB0090 /* Test.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Test.plist; sourceTree = "<group>"; };
555683BC1C1250E70041D4C6 /* TestUserDefaults.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestUserDefaults.swift; sourceTree = "<group>"; usesTabs = 1; };
559451EA1F706BF5002807FB /* CFXMLPreferencesDomain.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = CFXMLPreferencesDomain.c; sourceTree = "<group>"; };
5A6AC80A28E7652D00A22FA7 /* WebSocketURLProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WebSocketURLProtocol.swift; path = URLSession/WebSocket/WebSocketURLProtocol.swift; sourceTree = "<group>"; };
5B0163BA1D024EB7003CCD96 /* DateComponents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateComponents.swift; sourceTree = "<group>"; };
5B0C6C211C1E07E600705A0E /* TestNSRegularExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSRegularExpression.swift; sourceTree = "<group>"; };
5B1FD9C11D6D160F0080E83C /* CFURLSessionInterface.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = CFURLSessionInterface.c; sourceTree = "<group>"; };
5B1FD9C21D6D160F0080E83C /* CFURLSessionInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFURLSessionInterface.h; sourceTree = "<group>"; };
5B1FD9E01D6D178E0080E83C /* libcurl.4.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcurl.4.dylib; path = usr/lib/libcurl.4.dylib; sourceTree = SDKROOT; };
5B1FD9E01D6D178E0080E83C /* libcurl.3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcurl.3.dylib; path = usr/lib/libcurl.3.dylib; sourceTree = SDKROOT; };
5B1FD9E21D6D17B80080E83C /* TestURLSession.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestURLSession.swift; sourceTree = "<group>"; };
5B23AB861CE62D17000DB898 /* Boxing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Boxing.swift; sourceTree = "<group>"; };
5B23AB881CE62D4D000DB898 /* ReferenceConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReferenceConvertible.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1354,7 +1352,7 @@
buildActionMask = 2147483647;
files = (
15FF00CC22934AD7004AD205 /* libCFURLSessionInterface.a in Frameworks */,
15B80388228F376000B30FF6 /* libcurl.4.dylib in Frameworks */,
15B80388228F376000B30FF6 /* libcurl.3.dylib in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -1369,7 +1367,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
5B1FD9E11D6D178E0080E83C /* libcurl.4.dylib in Frameworks */,
5B1FD9E11D6D178E0080E83C /* libcurl.3.dylib in Frameworks */,
5B40F9F41C12524C000E72E3 /* libxml2.dylib in Frameworks */,
5B7C8B031BEA86A900C5B690 /* libCoreFoundation.a in Frameworks */,
5B5D89781BBDADDB00234F36 /* libz.dylib in Frameworks */,
Expand Down Expand Up @@ -1437,14 +1435,6 @@
path = AttributedString;
sourceTree = "<group>";
};
5A6AC80728E7649D00A22FA7 /* WebSocket */ = {
isa = PBXGroup;
children = (
5A6AC80A28E7652D00A22FA7 /* WebSocketURLProtocol.swift */,
);
name = WebSocket;
sourceTree = "<group>";
};
5B5D88531BBC938800234F36 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1794,7 +1784,7 @@
5B5D89AB1BBDCD0B00234F36 /* Frameworks */ = {
isa = PBXGroup;
children = (
5B1FD9E01D6D178E0080E83C /* libcurl.4.dylib */,
5B1FD9E01D6D178E0080E83C /* libcurl.3.dylib */,
5B40F9F31C12524C000E72E3 /* libxml2.dylib */,
5B5D89751BBDADD300234F36 /* libicucore.dylib */,
5B5D89791BBDADDF00234F36 /* libobjc.dylib */,
Expand Down Expand Up @@ -2276,7 +2266,6 @@
F023072D23F0B6D70023DBEC /* URLSession */ = {
isa = PBXGroup;
children = (
5A6AC80728E7649D00A22FA7 /* WebSocket */,
F023073A23F0B7060023DBEC /* libcurl */,
F023073523F0B6F60023DBEC /* HTTP */,
F023073223F0B6E90023DBEC /* FTP */,
Expand Down Expand Up @@ -2725,7 +2714,7 @@
};
5B7C8A6D1BEA7F8F00C5B690 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 1410;
LastSwiftMigration = 1150;
ProvisioningStyle = Manual;
};
5BDC405B1BD6D83B00ED97BB = {
Expand Down Expand Up @@ -2885,7 +2874,6 @@
buildActionMask = 2147483647;
files = (
B91161AA2429860900BD2907 /* DataURLProtocol.swift in Sources */,
5A6AC80C28E7BC8F00A22FA7 /* WebSocketURLProtocol.swift in Sources */,
F023073823F0B6FE0023DBEC /* HTTPMessage.swift in Sources */,
15B8043D228F38A600B30FF6 /* URLCredentialStorage.swift in Sources */,
F023074023F0B7100023DBEC /* libcurlHelpers.swift in Sources */,
Expand Down
1 change: 0 additions & 1 deletion Sources/FoundationNetworking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ add_library(FoundationNetworking
URLSession/FTP/FTPURLProtocol.swift
URLSession/HTTP/HTTPMessage.swift
URLSession/HTTP/HTTPURLProtocol.swift
URLSession/WebSocket/WebSocketURLProtocol.swift
URLSession/Message.swift
URLSession/NativeProtocol.swift
URLSession/NetworkingSpecific.swift
Expand Down
2 changes: 1 addition & 1 deletion Sources/FoundationNetworking/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>SwiftFoundationNetworking</string>
<string>SwiftFoundation</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
Expand Down
Loading