void BlobResourceHandle::consumeData(const char* data, int bytesRead) { ASSERT(m_async); m_totalRemainingSize -= bytesRead; // Notify the client. if (bytesRead) notifyReceiveData(data, bytesRead); if (m_fileOpened) { // When the current item is a file item, the reading is completed only if bytesRead is 0. if (!bytesRead) { // Close the file. m_fileOpened = false; m_asyncStream->close(); // Move to the next item. m_readItemCount++; } } else { // Otherwise, we read the current text item as a whole and move to the next item. m_readItemCount++; } // Continue the reading. readAsync(); }
void BlobResourceHandle::getSizeForNext() { // Do we finish validating and counting size for all items? if (m_sizeItemCount >= m_blobData->items().size()) { seek(); // Start reading if in asynchronous mode. if (m_async) { notifyResponse(); m_buffer.resize(bufferSize); readAsync(); } return; } const BlobDataItem& item = m_blobData->items().at(m_sizeItemCount); switch (item.type) { case BlobDataItem::Data: didGetSize(item.length); break; case BlobDataItem::File: if (m_async) m_asyncStream->getSize(item.path, item.expectedModificationTime); else didGetSize(m_stream->getSize(item.path, item.expectedModificationTime)); break; default: ASSERT_NOT_REACHED(); } }
void BlobResourceHandle::getSizeForNext() { ASSERT(isMainThread()); // Do we finish validating and counting size for all items? if (m_sizeItemCount >= m_blobData->items().size()) { seek(); // Start reading if in asynchronous mode. if (m_async) { Ref<BlobResourceHandle> protect(*this); notifyResponse(); m_buffer.resize(bufferSize); readAsync(); } return; } const BlobDataItem& item = m_blobData->items().at(m_sizeItemCount); switch (item.type) { case BlobDataItem::Data: didGetSize(item.length()); break; case BlobDataItem::File: // Files know their sizes, but asking the stream to verify that the file wasn't modified. if (m_async) m_asyncStream->getSize(item.file->path(), item.file->expectedModificationTime()); else didGetSize(m_stream->getSize(item.file->path(), item.file->expectedModificationTime())); break; default: ASSERT_NOT_REACHED(); } }
void BlobResourceHandle::didOpen(bool success) { ASSERT(m_async); if (!success) { failed(notReadableError); return; } // Continue the reading. readAsync(); }
void MasterNodeConnection::didAccept() { auto self = shared_from_this(); std::lock_guard<ioMutexType> lock(mutex); accepted = true; log.setChannel(str(format("Unknown [%s]") % tcpSocket().remote_endpoint())); auto headerBuffer = std::make_shared<std::uint32_t>(); readAsync(asio::buffer(headerBuffer.get(), 4), [this, headerBuffer] (const boost::system::error_code& error, std::size_t readCount){ try { if (error) { MSCThrow(boost::system::system_error(error)); } std::uint32_t header = *headerBuffer; std::shared_ptr<MasterNodeConnectionHandler> h; if (header == ControlStreamHeaderMagic) { h = std::make_shared<MasterNode>(shared_from_this()); } else if (header == VersionDownloadRequestMagic) { MSCThrow(NotImplementedException()); } else if (header == DataStreamMagic) { h = std::make_shared<MasterNodeClientStream>(shared_from_this()); } else { MSCThrow(InvalidOperationException( str(format("Invalid header magic 0x%08x received.") % header))); } assert(h != nullptr); handler = h; h->service(); } catch (...) { performShutdownByError(boost::current_exception_diagnostic_information()); } }); }
ScriptPromise Body::json(ScriptState* scriptState) { return readAsync(scriptState, ResponseAsJSON); }
ScriptPromise Body::formData(ScriptState* scriptState) { return readAsync(scriptState, ResponseAsFormData); }
ScriptPromise Body::blob(ScriptState* scriptState) { return readAsync(scriptState, ResponseAsBlob); }
ScriptPromise Body::arrayBuffer(ScriptState* scriptState) { return readAsync(scriptState, ResponseAsArrayBuffer); }
ScriptPromise Body::text(ScriptState* scriptState) { return readAsync(scriptState, ResponseAsText); }