Changeset 214114 in webkit
- Timestamp:
- Mar 17, 2017, 1:30:37 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/CMakeLists.txt
r214105 r214114 2424 2424 platform/network/ResourceResponseBase.cpp 2425 2425 platform/network/SocketStreamHandle.cpp 2426 platform/network/SocketStreamHandleImpl.cpp 2426 2427 platform/network/SynchronousLoaderClient.cpp 2427 2428 -
trunk/Source/WebCore/ChangeLog
r214113 r214114 1 2017-03-17 Alex Christensen <achristensen@webkit.org> 2 3 Make SocketStreamHandle virtual functions asynchronous 4 https://bugs.webkit.org/show_bug.cgi?id=169818 5 6 Reviewed by Andy Estes. 7 8 No change in behavior. Instead of returning immediately, call a completion handler. 9 This is in preparation for making them truly asynchronous. 10 11 I still need to be able to synchronously get the number of buffered bytes, but the 12 buffer itself will soon be in the NetworkProcess with a new subclass of SocketStreamHandle 13 that messages across IPC. The number of buffered bytes will still be stored in the WebProcess, 14 and when it updates, the message from SocketStreamHandleClient::didUpdateBufferedAmount will update it. 15 16 * CMakeLists.txt: 17 * WebCore.xcodeproj/project.pbxproj: 18 * platform/network/SocketStreamHandle.cpp: 19 (WebCore::SocketStreamHandle::send): 20 (WebCore::SocketStreamHandle::close): 21 (WebCore::SocketStreamHandle::sendPendingData): Deleted. 22 * platform/network/SocketStreamHandle.h: 23 (WebCore::SocketStreamHandle::bufferedAmount): Deleted. 24 * platform/network/SocketStreamHandleImpl.cpp: Added. 25 (WebCore::SocketStreamHandleImpl::platformSend): 26 (WebCore::SocketStreamHandleImpl::sendPendingData): 27 (WebCore::SocketStreamHandleImpl::bufferedAmount): 28 m_buffer was moved from SocketStreamHandle to SocketStreamHandleImpl, so some of the logic must move with it. 29 I moved as much logic that was shared in the superclass to a new shared location for code shared among the subclass implementations. 30 * platform/network/cf/SocketStreamHandleImpl.h: 31 * platform/network/cf/SocketStreamHandleImplCFNet.cpp: 32 (WebCore::SocketStreamHandleImpl::platformSendInternal): 33 (WebCore::SocketStreamHandleImpl::platformSend): Deleted. 34 * platform/network/curl/SocketStreamHandleImpl.h: 35 * platform/network/curl/SocketStreamHandleImplCurl.cpp: 36 (WebCore::SocketStreamHandleImpl::platformSendInternal): 37 (WebCore::SocketStreamHandleImpl::platformSend): Deleted. 38 * platform/network/soup/SocketStreamHandleImpl.h: 39 * platform/network/soup/SocketStreamHandleImplSoup.cpp: 40 (WebCore::SocketStreamHandleImpl::platformSendInternal): 41 (WebCore::SocketStreamHandleImpl::platformSend): Deleted. 42 1 43 2017-03-17 Antti Koivisto <antti@apple.com> 2 44 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r214074 r214114 2648 2648 5C5381B21D87D4B200E2EBE6 /* URLSearchParams.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5C5381B01D87D45700E2EBE6 /* URLSearchParams.cpp */; }; 2649 2649 5C5381B51D87E08700E2EBE6 /* JSURLSearchParams.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5C5381B31D87E08100E2EBE6 /* JSURLSearchParams.cpp */; }; 2650 5C668E651E7C6C4000D32B3B /* SocketStreamHandleImpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5C668E641E7C6C3500D32B3B /* SocketStreamHandleImpl.cpp */; }; 2650 2651 5C688AA11D380BF8000B54FA /* ThreadableWebSocketChannel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5C688AA01D380509000B54FA /* ThreadableWebSocketChannel.cpp */; }; 2651 2652 5C688AA31D3814BF000B54FA /* SocketProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5C688AA21D38126F000B54FA /* SocketProvider.cpp */; }; … … 10339 10340 5C5381B31D87E08100E2EBE6 /* JSURLSearchParams.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSURLSearchParams.cpp; sourceTree = "<group>"; }; 10340 10341 5C5381B41D87E08100E2EBE6 /* JSURLSearchParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSURLSearchParams.h; sourceTree = "<group>"; }; 10342 5C668E641E7C6C3500D32B3B /* SocketStreamHandleImpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SocketStreamHandleImpl.cpp; sourceTree = "<group>"; }; 10341 10343 5C688AA01D380509000B54FA /* ThreadableWebSocketChannel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadableWebSocketChannel.cpp; sourceTree = "<group>"; }; 10342 10344 5C688AA21D38126F000B54FA /* SocketProvider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SocketProvider.cpp; sourceTree = "<group>"; }; … … 18764 18766 510D4A31103165EE0049EA54 /* SocketStreamHandle.h */, 18765 18767 510D4A32103165EE0049EA54 /* SocketStreamHandleClient.h */, 18768 5C668E641E7C6C3500D32B3B /* SocketStreamHandleImpl.cpp */, 18766 18769 E180811016FCF42E00B80D07 /* SynchronousLoaderClient.cpp */, 18767 18770 E180811516FCF9CB00B80D07 /* SynchronousLoaderClient.h */, … … 30754 30757 A9C6E4EB0D745E2B006442E9 /* DOMPlugin.cpp in Sources */, 30755 30758 A9C6E4EF0D745E38006442E9 /* DOMPluginArray.cpp in Sources */, 30759 5C668E651E7C6C4000D32B3B /* SocketStreamHandleImpl.cpp in Sources */, 30756 30760 BC5A86840C33676000EEA649 /* DOMSelection.cpp in Sources */, 30757 30761 C55610F111A704EB00B82D27 /* DOMStringList.cpp in Sources */, -
trunk/Source/WebCore/platform/network/SocketStreamHandle.cpp
r214106 r214114 37 37 namespace WebCore { 38 38 39 const unsigned bufferSize = 100 * 1024 * 1024;40 41 39 SocketStreamHandle::SocketStreamHandle(const URL& url, SocketStreamHandleClient& client) 42 40 : m_url(url) … … 55 53 if (m_state == Connecting || m_state == Closing) 56 54 return completionHandler(false); 57 if (!m_buffer.isEmpty()) { 58 if (m_buffer.size() + length > bufferSize) { 59 // FIXME: report error to indicate that buffer has no more space. 60 return completionHandler(false); 61 } 62 m_buffer.append(data, length); 63 m_client.didUpdateBufferedAmount(static_cast<SocketStreamHandle&>(*this), bufferedAmount()); 64 return completionHandler(true); 65 } 66 size_t bytesWritten = 0; 67 if (m_state == Open) { 68 if (auto result = platformSend(data, length)) 69 bytesWritten = result.value(); 70 else 71 return completionHandler(false); 72 } 73 if (m_buffer.size() + length - bytesWritten > bufferSize) { 74 // FIXME: report error to indicate that buffer has no more space. 75 return completionHandler(false); 76 } 77 if (bytesWritten < length) { 78 m_buffer.append(data + bytesWritten, length - bytesWritten); 79 m_client.didUpdateBufferedAmount(static_cast<SocketStreamHandle&>(*this), bufferedAmount()); 80 } 81 return completionHandler(true); 55 platformSend(data, length, WTFMove(completionHandler)); 82 56 } 83 57 … … 87 61 return; 88 62 m_state = Closing; 89 if ( !m_buffer.isEmpty())63 if (bufferedAmount()) 90 64 return; 91 65 disconnect(); … … 100 74 } 101 75 102 bool SocketStreamHandle::sendPendingData()103 {104 if (m_state != Open && m_state != Closing)105 return false;106 if (m_buffer.isEmpty()) {107 if (m_state == Open)108 return false;109 if (m_state == Closing) {110 disconnect();111 return false;112 }113 }114 bool pending;115 do {116 auto result = platformSend(m_buffer.firstBlockData(), m_buffer.firstBlockSize());117 if (!result)118 return false;119 size_t bytesWritten = result.value();120 if (!bytesWritten)121 return false;122 pending = bytesWritten != m_buffer.firstBlockSize();123 ASSERT(m_buffer.size() - bytesWritten <= bufferSize);124 m_buffer.consume(bytesWritten);125 } while (!pending && !m_buffer.isEmpty());126 m_client.didUpdateBufferedAmount(static_cast<SocketStreamHandle&>(*this), bufferedAmount());127 return true;128 }129 130 76 } // namespace WebCore -
trunk/Source/WebCore/platform/network/SocketStreamHandle.h
r214106 r214114 33 33 34 34 #include "URL.h" 35 #include <wtf/StreamBuffer.h>36 35 #include <wtf/ThreadSafeRefCounted.h> 37 36 … … 49 48 void close(); // Disconnect after all data in buffer are sent. 50 49 void disconnect(); 51 size_t bufferedAmount() const { return m_buffer.size(); }50 virtual size_t bufferedAmount() = 0; 52 51 53 52 protected: 54 53 SocketStreamHandle(const URL&, SocketStreamHandleClient&); 55 54 56 bool sendPendingData(); 57 virtual std::optional<size_t> platformSend(const char* data, size_t length) = 0; 55 virtual void platformSend(const char* data, size_t length, Function<void(bool)>&&) = 0; 58 56 virtual void platformClose() = 0; 59 57 60 58 URL m_url; 61 59 SocketStreamHandleClient& m_client; 62 StreamBuffer<char, 1024 * 1024> m_buffer;63 60 SocketStreamState m_state; 64 61 }; -
trunk/Source/WebCore/platform/network/cf/SocketStreamHandleImpl.h
r214106 r214114 35 35 #include "SocketStreamHandle.h" 36 36 #include <wtf/RetainPtr.h> 37 #include <wtf/StreamBuffer.h> 37 38 38 39 typedef struct __CFHTTPMessage* CFHTTPMessageRef; … … 51 52 52 53 private: 53 std::optional<size_t> platformSend(const char* data, size_t length) final;54 void platformSend(const char* data, size_t length, Function<void(bool)>&&) final; 54 55 void platformClose() final; 56 size_t bufferedAmount() final; 57 std::optional<size_t> platformSendInternal(const char*, size_t); 58 bool sendPendingData(); 55 59 56 60 WEBCORE_EXPORT SocketStreamHandleImpl(const URL&, SocketStreamHandleClient&, SessionID, const String& credentialPartition); … … 98 102 SessionID m_sessionID; 99 103 String m_credentialPartition; 104 105 StreamBuffer<char, 1024 * 1024> m_buffer; 106 static const unsigned maxBufferSize = 100 * 1024 * 1024; 100 107 }; 101 108 -
trunk/Source/WebCore/platform/network/cf/SocketStreamHandleImplCFNet.cpp
r214073 r214114 654 654 } 655 655 656 std::optional<size_t> SocketStreamHandleImpl::platformSend (const char* data, size_t length)656 std::optional<size_t> SocketStreamHandleImpl::platformSendInternal(const char* data, size_t length) 657 657 { 658 658 if (!CFWriteStreamCanAcceptBytes(m_writeStream.get())) -
trunk/Source/WebCore/platform/network/curl/SocketStreamHandleImpl.h
r211751 r214114 43 43 #include <wtf/Lock.h> 44 44 #include <wtf/RefCounted.h> 45 #include <wtf/StreamBuffer.h> 45 46 #include <wtf/Threading.h> 46 47 … … 58 59 SocketStreamHandleImpl(const URL&, SocketStreamHandleClient&); 59 60 60 std::optional<size_t> platformSend(const char* data, size_t length) final;61 void platformSend(const char* data, size_t length, Function<void(bool)>&&) final; 61 62 void platformClose() final; 63 size_t bufferedAmount() final; 64 std::optional<size_t> platformSendInternal(const char*, size_t); 65 bool sendPendingData(); 62 66 63 67 bool readData(CURL*); … … 95 99 Deque<SocketData> m_sendData; 96 100 Deque<SocketData> m_receiveData; 101 102 StreamBuffer<char, 1024 * 1024> m_buffer; 103 static const unsigned maxBufferSize = 100 * 1024 * 1024; 97 104 }; 98 105 -
trunk/Source/WebCore/platform/network/curl/SocketStreamHandleImplCurl.cpp
r208985 r214114 67 67 } 68 68 69 std::optional<size_t> SocketStreamHandleImpl::platformSend (const char* data, size_t length)69 std::optional<size_t> SocketStreamHandleImpl::platformSendInternal(const char* data, size_t length) 70 70 { 71 71 LOG(Network, "SocketStreamHandle %p platformSend", this); -
trunk/Source/WebCore/platform/network/soup/SocketStreamHandleImpl.h
r211751 r214114 39 39 #include "SessionID.h" 40 40 #include <wtf/RefCounted.h> 41 #include <wtf/StreamBuffer.h> 41 42 #include <wtf/glib/GRefPtr.h> 42 43 … … 56 57 SocketStreamHandleImpl(const URL&, SocketStreamHandleClient&); 57 58 58 std::optional<size_t> platformSend(const char* data, size_t length) final;59 void platformSend(const char* data, size_t length, Function<void(bool)>&&) final; 59 60 void platformClose() final; 61 size_t bufferedAmount() final; 62 std::optional<size_t> platformSendInternal(const char*, size_t); 63 bool sendPendingData(); 60 64 61 65 void beginWaitingForSocketWritability(); … … 77 81 GRefPtr<GCancellable> m_cancellable; 78 82 std::unique_ptr<char[]> m_readBuffer; 83 84 StreamBuffer<char, 1024 * 1024> m_buffer; 85 static const unsigned maxBufferSize = 100 * 1024 * 1024; 79 86 }; 80 87 -
trunk/Source/WebCore/platform/network/soup/SocketStreamHandleImplSoup.cpp
r214090 r214114 191 191 } 192 192 193 std::optional<size_t> SocketStreamHandleImpl::platformSend (const char* data, size_t length)193 std::optional<size_t> SocketStreamHandleImpl::platformSendInternal(const char* data, size_t length) 194 194 { 195 195 LOG(Network, "SocketStreamHandle %p platformSend", this);
Note:
See TracChangeset
for help on using the changeset viewer.