static void formClose(CFReadStreamRef, void* context) { FormStreamFields* form = static_cast<FormStreamFields*>(context); LockHolder locker(form->streamIsBeingOpenedOrClosedLock); closeCurrentStream(form); }
static void advanceCurrentStream(FormStreamFields *form) { closeCurrentStream(form); if (form->remainingElements.isEmpty()) return; // Create the new stream. FormDataElement& nextInput = form->remainingElements.last(); if (nextInput.m_type == FormDataElement::data) { size_t size = nextInput.m_data.size(); char* data = nextInput.m_data.releaseBuffer(); form->currentStream = CFReadStreamCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(data), size, kCFAllocatorNull); form->currentData = data; } else { CFStringRef filename = nextInput.m_filename.createCFString(); #if PLATFORM(WIN) CFURLRef fileURL = CFURLCreateWithFileSystemPath(0, filename, kCFURLWindowsPathStyle, FALSE); #else CFURLRef fileURL = CFURLCreateWithFileSystemPath(0, filename, kCFURLPOSIXPathStyle, FALSE); #endif CFRelease(filename); form->currentStream = CFReadStreamCreateWithFile(0, fileURL); CFRelease(fileURL); } form->remainingElements.removeLast(); // Set up the callback. CFStreamClientContext context = { 0, form, NULL, NULL, NULL }; CFReadStreamSetClient(form->currentStream, kCFStreamEventHasBytesAvailable | kCFStreamEventErrorOccurred | kCFStreamEventEndEncountered, formEventCallback, &context); // Schedule with the current set of run loops. CFSetApplyFunction(form->scheduledRunLoopPairs, scheduleWithPair, form->currentStream); }
static void formFinalize(CFReadStreamRef stream, void* context) { FormStreamFields* form = static_cast<FormStreamFields*>(context); ASSERT_UNUSED(stream, form->formStream == stream); callOnMainThread([form] { closeCurrentStream(form); delete form; }); }
static void formFinalize(CFReadStreamRef stream, void* context) { FormStreamFields* form = static_cast<FormStreamFields*>(context); getStreamFormDatas().remove(stream); closeCurrentStream(form); CFRelease(form->scheduledRunLoopPairs); delete form; }
// Return false if we cannot advance the stream. Currently the only possible failure is that the underlying file has been removed or changed since File.slice. static bool advanceCurrentStream(FormStreamFields* form) { closeCurrentStream(form); if (form->remainingElements.isEmpty()) return true; // Create the new stream. FormDataElement& nextInput = form->remainingElements.last(); if (nextInput.m_type == FormDataElement::data) { size_t size = nextInput.m_data.size(); MallocPtr<char> data = nextInput.m_data.releaseBuffer(); form->currentStream = CFReadStreamCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(data.get()), size, kCFAllocatorNull); form->currentData = std::move(data); } else { #if ENABLE(BLOB) // Check if the file has been changed or not if required. if (isValidFileTime(nextInput.m_expectedFileModificationTime)) { time_t fileModificationTime; if (!getFileModificationTime(nextInput.m_filename, fileModificationTime) || fileModificationTime != static_cast<time_t>(nextInput.m_expectedFileModificationTime)) return false; } #endif const String& path = nextInput.m_shouldGenerateFile ? nextInput.m_generatedFilename : nextInput.m_filename; form->currentStream = CFReadStreamCreateWithFile(0, pathAsURL(path).get()); if (!form->currentStream) { // The file must have been removed or become unreadable. return false; } #if ENABLE(BLOB) if (nextInput.m_fileStart > 0) { RetainPtr<CFNumberRef> position = adoptCF(CFNumberCreate(0, kCFNumberLongLongType, &nextInput.m_fileStart)); CFReadStreamSetProperty(form->currentStream, kCFStreamPropertyFileCurrentOffset, position.get()); } form->currentStreamRangeLength = nextInput.m_fileLength; #endif } form->remainingElements.removeLast(); // Set up the callback. CFStreamClientContext context = { 0, form, 0, 0, 0 }; CFReadStreamSetClient(form->currentStream, kCFStreamEventHasBytesAvailable | kCFStreamEventErrorOccurred | kCFStreamEventEndEncountered, formEventCallback, &context); // Schedule with the current set of run loops. SchedulePairHashSet::iterator end = form->scheduledRunLoopPairs.end(); for (SchedulePairHashSet::iterator it = form->scheduledRunLoopPairs.begin(); it != end; ++it) CFReadStreamScheduleWithRunLoop(form->currentStream, (*it)->runLoop(), (*it)->mode()); return true; }
static void formFinalize(CFReadStreamRef stream, void* context) { FormStreamFields* form = static_cast<FormStreamFields*>(context); ASSERT_UNUSED(stream, form->formStream == stream); callOnMainThread([form] { { LockHolder locker(form->streamIsBeingOpenedOrClosedLock); closeCurrentStream(form); } delete form; }); }
static void formClose(CFReadStreamRef, void* context) { FormStreamFields* form = static_cast<FormStreamFields*>(context); closeCurrentStream(form); }
static void formFinishFinalizationOnMainThread(void* context) { OwnPtr<FormStreamFields> form = adoptPtr(static_cast<FormStreamFields*>(context)); closeCurrentStream(form.get()); }