Changeset 279993 in webkit
- Timestamp:
- Jul 16, 2021, 1:19:40 PM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r279990 r279993 1 2021-07-16 Fujii Hironori <Hironori.Fujii@sony.com> 2 3 [curl] Use curl_multi_poll and curl_multi_wakeup instead of select 4 https://bugs.webkit.org/show_bug.cgi?id=227966 5 6 Reviewed by Don Olmstead. 7 8 libcurl 7.68.0 added curl_multi_poll and curl_multi_wakeup. 9 10 * platform/network/curl/CurlContext.cpp: 11 (WebCore::CurlMultiHandle::poll): Added. 12 (WebCore::CurlMultiHandle::wakeUp): Added. 13 * platform/network/curl/CurlContext.h: 14 * platform/network/curl/CurlRequestScheduler.cpp: 15 (WebCore::CurlRequestScheduler::add): 16 (WebCore::CurlRequestScheduler::callOnWorkerThread): 17 (WebCore::CurlRequestScheduler::startOrWakeUpThread): 18 (WebCore::CurlRequestScheduler::wakeUpThreadIfPossible): Added. 19 (WebCore::CurlRequestScheduler::stopThread): 20 (WebCore::CurlRequestScheduler::workerThread): 21 (WebCore::CurlRequestScheduler::startThreadIfNeeded): Deleted. 22 * platform/network/curl/CurlRequestScheduler.h: 23 1 24 2021-07-16 Myles C. Maxfield <mmaxfield@apple.com> 2 25 -
trunk/Source/WebCore/platform/network/curl/CurlContext.cpp
r279575 r279993 267 267 } 268 268 269 CURLMcode CurlMultiHandle::poll(const Vector<curl_waitfd>& extraFds, int timeoutMS) 270 { 271 int numFds = 0; 272 return curl_multi_poll(m_multiHandle, const_cast<curl_waitfd*>(extraFds.data()), extraFds.size(), timeoutMS, &numFds); 273 } 274 275 CURLMcode CurlMultiHandle::wakeUp() 276 { 277 return curl_multi_wakeup(m_multiHandle); 278 } 279 269 280 CURLMcode CurlMultiHandle::perform(int& runningHandles) 270 281 { -
trunk/Source/WebCore/platform/network/curl/CurlContext.h
r278516 r279993 175 175 176 176 CURLMcode getFdSet(fd_set&, fd_set&, fd_set&, int&); 177 CURLMcode poll(const Vector<curl_waitfd>&, int); 178 CURLMcode wakeUp(); 177 179 CURLMcode perform(int&); 178 180 CURLMsg* readInfo(int&); -
trunk/Source/WebCore/platform/network/curl/CurlRequestScheduler.cpp
r277908 r279993 50 50 51 51 startTransfer(client); 52 start ThreadIfNeeded();52 startOrWakeUpThread(); 53 53 54 54 return true; … … 72 72 } 73 73 74 start ThreadIfNeeded();75 } 76 77 void CurlRequestScheduler::start ThreadIfNeeded()74 startOrWakeUpThread(); 75 } 76 77 void CurlRequestScheduler::startOrWakeUpThread() 78 78 { 79 79 ASSERT(isMainThread()); … … 81 81 { 82 82 Locker locker { m_mutex }; 83 if (m_runThread) 83 if (m_runThread) { 84 wakeUpThreadIfPossible(); 84 85 return; 86 } 85 87 } 86 88 … … 95 97 m_thread = Thread::create("curlThread", [this] { 96 98 workerThread(); 97 98 Locker locker { m_mutex };99 m_runThread = false;100 99 }, ThreadType::Network); 100 } 101 102 void CurlRequestScheduler::wakeUpThreadIfPossible() 103 { 104 Locker locker { m_multiHandleMutex }; 105 if (!m_curlMultiHandle) 106 return; 107 108 m_curlMultiHandle->wakeUp(); 101 109 } 102 110 … … 120 128 121 129 if (m_thread) { 130 wakeUpThreadIfPossible(); 122 131 m_thread->waitForCompletion(); 123 132 m_thread = nullptr; … … 144 153 ASSERT(!isMainThread()); 145 154 146 m_curlMultiHandle = makeUnique<CurlMultiHandle>(); 147 m_curlMultiHandle->setMaxConnects(m_maxConnects); 148 m_curlMultiHandle->setMaxTotalConnections(m_maxTotalConnections); 149 m_curlMultiHandle->setMaxHostConnections(m_maxHostConnections); 155 { 156 Locker locker { m_multiHandleMutex }; 157 m_curlMultiHandle.emplace(); 158 m_curlMultiHandle->setMaxConnects(m_maxConnects); 159 m_curlMultiHandle->setMaxTotalConnections(m_maxTotalConnections); 160 m_curlMultiHandle->setMaxHostConnections(m_maxHostConnections); 161 } 150 162 151 163 while (true) { … … 158 170 executeTasks(); 159 171 160 // Retry 'select' if it was interrupted by a process signal. 161 int rc = 0; 162 do { 163 fd_set fdread; 164 fd_set fdwrite; 165 fd_set fdexcep; 166 int maxfd = 0; 167 168 const int selectTimeoutMS = 5; 169 170 struct timeval timeout; 171 timeout.tv_sec = 0; 172 timeout.tv_usec = selectTimeoutMS * 1000; // select waits microseconds 173 174 m_curlMultiHandle->getFdSet(fdread, fdwrite, fdexcep, maxfd); 175 176 // When the 3 file descriptors are empty, winsock will return -1 177 // and bail out, stopping the file download. So make sure we 178 // have valid file descriptors before calling select. 179 if (maxfd >= 0) 180 rc = ::select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout); 181 } while (rc == -1 && errno == EINTR); 172 const int selectTimeoutMS = INT_MAX; 173 m_curlMultiHandle->poll({ }, selectTimeoutMS); 182 174 183 175 int activeCount = 0; … … 200 192 } 201 193 202 m_curlMultiHandle = nullptr; 194 { 195 Locker locker { m_multiHandleMutex }; 196 m_curlMultiHandle.reset(); 197 } 203 198 } 204 199 -
trunk/Source/WebCore/platform/network/curl/CurlRequestScheduler.h
r248762 r279993 52 52 53 53 private: 54 void startThreadIfNeeded(); 54 void startOrWakeUpThread(); 55 void wakeUpThreadIfPossible(); 55 56 void stopThreadIfNoMoreJobRunning(); 56 57 void stopThread(); … … 73 74 HashMap<CURL*, CurlRequestSchedulerClient*> m_clientMaps; 74 75 75 std::unique_ptr<CurlMultiHandle> m_curlMultiHandle; 76 Lock m_multiHandleMutex; 77 std::optional<CurlMultiHandle> m_curlMultiHandle; 76 78 77 79 long m_maxConnects;
Note:
See TracChangeset
for help on using the changeset viewer.