Changeset 214106 in webkit
- Timestamp:
- Mar 17, 2017, 8:57:23 AM (8 years ago)
- Location:
- trunk/Source
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r214105 r214106 1 2017-03-16 Alex Christensen <achristensen@webkit.org> 2 3 Use completion handlers instead of return values for sending websocket data 4 https://bugs.webkit.org/show_bug.cgi?id=169802 5 6 Reviewed by Carlos Garcia Campos. 7 8 No change in behavior, but this is a baby step towards making things more asynchronous. 9 10 * Modules/websockets/WebSocketChannel.cpp: 11 (WebCore::WebSocketChannel::didOpenSocketStream): 12 (WebCore::WebSocketChannel::processOutgoingFrameQueue): 13 (WebCore::WebSocketChannel::sendFrame): 14 * Modules/websockets/WebSocketChannel.h: 15 * platform/network/SocketStreamHandle.cpp: 16 (WebCore::SocketStreamHandle::send): 17 * platform/network/SocketStreamHandle.h: 18 * platform/network/cf/SocketStreamHandleImpl.h: 19 1 20 2017-03-17 Zan Dobersek <zdobersek@igalia.com> 2 21 -
trunk/Source/WebCore/Modules/websockets/WebSocketChannel.cpp
r214073 r214106 279 279 InspectorInstrumentation::willSendWebSocketHandshakeRequest(m_document, m_identifier, m_handshake->clientHandshakeRequest()); 280 280 CString handshakeMessage = m_handshake->clientHandshakeMessage(); 281 if (!handle.send(handshakeMessage.data(), handshakeMessage.length())) 282 fail("Failed to send WebSocket handshake."); 281 handle.send(handshakeMessage.data(), handshakeMessage.length(), [this, protectedThis = makeRef(*this)] (bool success) { 282 if (!success) 283 fail("Failed to send WebSocket handshake."); 284 }); 283 285 } 284 286 … … 743 745 switch (frame->frameType) { 744 746 case QueuedFrameTypeString: { 745 if (!sendFrame(frame->opCode, frame->stringData.data(), frame->stringData.length())) 746 fail("Failed to send WebSocket frame."); 747 sendFrame(frame->opCode, frame->stringData.data(), frame->stringData.length(), [this, protectedThis = makeRef(*this)] (bool success) { 748 if (!success) 749 fail("Failed to send WebSocket frame."); 750 }); 747 751 break; 748 752 } 749 753 750 754 case QueuedFrameTypeVector: 751 if (!sendFrame(frame->opCode, frame->vectorData.data(), frame->vectorData.size())) 752 fail("Failed to send WebSocket frame."); 755 sendFrame(frame->opCode, frame->vectorData.data(), frame->vectorData.size(), [this, protectedThis = makeRef(*this)] (bool success) { 756 if (!success) 757 fail("Failed to send WebSocket frame."); 758 }); 753 759 break; 754 760 … … 774 780 m_blobLoader = nullptr; 775 781 m_blobLoaderStatus = BlobLoaderNotStarted; 776 if (!sendFrame(frame->opCode, static_cast<const char*>(result->data()), result->byteLength())) 777 fail("Failed to send WebSocket frame."); 782 sendFrame(frame->opCode, static_cast<const char*>(result->data()), result->byteLength(), [this, protectedThis = makeRef(*this)] (bool success) { 783 if (!success) 784 fail("Failed to send WebSocket frame."); 785 }); 778 786 break; 779 787 } … … 805 813 } 806 814 807 bool WebSocketChannel::sendFrame(WebSocketFrame::OpCode opCode, const char* data, size_t dataLength)815 void WebSocketChannel::sendFrame(WebSocketFrame::OpCode opCode, const char* data, size_t dataLength, Function<void(bool)> completionHandler) 808 816 { 809 817 ASSERT(m_handle); … … 816 824 if (!deflateResult->succeeded()) { 817 825 fail(deflateResult->failureReason()); 818 return false;826 return completionHandler(false); 819 827 } 820 828 … … 822 830 frame.makeFrameData(frameData); 823 831 824 return m_handle->send(frameData.data(), frameData.size());832 m_handle->send(frameData.data(), frameData.size(), WTFMove(completionHandler)); 825 833 } 826 834 -
trunk/Source/WebCore/Modules/websockets/WebSocketChannel.h
r214073 r214106 174 174 // If you are going to send a hybi-10 frame, you need to use the outgoing frame queue 175 175 // instead of call sendFrame() directly. 176 bool sendFrame(WebSocketFrame::OpCode, const char* data, size_t dataLength);176 void sendFrame(WebSocketFrame::OpCode, const char* data, size_t dataLength, Function<void(bool)> completionHandler); 177 177 178 178 enum BlobLoaderStatus { -
trunk/Source/WebCore/platform/network/SocketStreamHandle.cpp
r204512 r214106 33 33 34 34 #include "SocketStreamHandleClient.h" 35 #include <wtf/Function.h> 35 36 36 37 namespace WebCore { … … 50 51 } 51 52 52 bool SocketStreamHandle::send(const char* data, size_t length)53 void SocketStreamHandle::send(const char* data, size_t length, Function<void(bool)> completionHandler) 53 54 { 54 55 if (m_state == Connecting || m_state == Closing) 55 return false;56 return completionHandler(false); 56 57 if (!m_buffer.isEmpty()) { 57 58 if (m_buffer.size() + length > bufferSize) { 58 59 // FIXME: report error to indicate that buffer has no more space. 59 return false;60 return completionHandler(false); 60 61 } 61 62 m_buffer.append(data, length); 62 63 m_client.didUpdateBufferedAmount(static_cast<SocketStreamHandle&>(*this), bufferedAmount()); 63 return true;64 return completionHandler(true); 64 65 } 65 66 size_t bytesWritten = 0; … … 68 69 bytesWritten = result.value(); 69 70 else 70 return false;71 return completionHandler(false); 71 72 } 72 73 if (m_buffer.size() + length - bytesWritten > bufferSize) { 73 74 // FIXME: report error to indicate that buffer has no more space. 74 return false;75 return completionHandler(false); 75 76 } 76 77 if (bytesWritten < length) { … … 78 79 m_client.didUpdateBufferedAmount(static_cast<SocketStreamHandle&>(*this), bufferedAmount()); 79 80 } 80 return true;81 return completionHandler(true); 81 82 } 82 83 -
trunk/Source/WebCore/platform/network/SocketStreamHandle.h
r208985 r214106 46 46 SocketStreamState state() const; 47 47 48 bool send(const char* data, size_t length);48 void send(const char* data, size_t length, Function<void(bool)>); 49 49 void close(); // Disconnect after all data in buffer are sent. 50 50 void disconnect(); -
trunk/Source/WebCore/platform/network/cf/SocketStreamHandleImpl.h
r211751 r214106 51 51 52 52 private: 53 virtual std::optional<size_t> platformSend(const char* data, size_t length);54 v irtual void platformClose();53 std::optional<size_t> platformSend(const char* data, size_t length) final; 54 void platformClose() final; 55 55 56 56 WEBCORE_EXPORT SocketStreamHandleImpl(const URL&, SocketStreamHandleClient&, SessionID, const String& credentialPartition); -
trunk/Source/WebKit2/ChangeLog
r214104 r214106 1 2017-03-16 Alex Christensen <achristensen@webkit.org> 2 3 Use completion handlers instead of return values for sending websocket data 4 https://bugs.webkit.org/show_bug.cgi?id=169802 5 6 Reviewed by Carlos Garcia Campos. 7 8 * UIProcess/InspectorServer/WebSocketServerConnection.cpp: 9 (WebKit::WebSocketServerConnection::sendWebSocketMessage): 10 (WebKit::WebSocketServerConnection::sendHTTPResponseHeader): 11 (WebKit::WebSocketServerConnection::sendRawData): 12 1 13 2017-03-17 Tomas Popela <tpopela@redhat.com> 2 14 -
trunk/Source/WebKit2/UIProcess/InspectorServer/WebSocketServerConnection.cpp
r214091 r214106 40 40 #include <WebCore/WebSocketChannel.h> 41 41 #include <WebCore/WebSocketHandshake.h> 42 #include <wtf/Function.h> 42 43 #include <wtf/text/CString.h> 43 44 #include <wtf/text/StringBuilder.h> … … 92 93 frame.makeFrameData(frameData); 93 94 94 m_socket->send(frameData.data(), frameData.size() );95 m_socket->send(frameData.data(), frameData.size(), [](bool) { }); 95 96 } 96 97 … … 113 114 114 115 CString header = builder.toString().latin1(); 115 m_socket->send(header.data(), header.length() );116 m_socket->send(header.data(), header.length(), [](bool) { }); 116 117 } 117 118 118 119 void WebSocketServerConnection::sendRawData(const char* data, size_t length) 119 120 { 120 m_socket->send(data, length );121 m_socket->send(data, length, [](bool) { }); 121 122 } 122 123
Note:
See TracChangeset
for help on using the changeset viewer.