Backed out changeset af367782bea4 (bug 1677509) for multipe failures. CLOSED TREE

This commit is contained in:
Dorel Luca 2021-05-20 02:26:36 +03:00
parent 3ad38859ed
commit 3416acf7b4
4 changed files with 38 additions and 50 deletions

View File

@ -452,55 +452,45 @@ void MessagePumpForIO::WaitForWork() {
}
bool MessagePumpForIO::WaitForIOCompletion(DWORD timeout, IOHandler* filter) {
IOItemChunk items;
if (completed_io_.empty() || !MatchCompletedIOItem(filter, items.values)) {
if (!GetIOItems(timeout, &items)) return false;
} else {
items.count = 1;
IOItem item;
if (completed_io_.empty() || !MatchCompletedIOItem(filter, &item)) {
// We have to ask the system for another IO completion.
if (!GetIOItem(timeout, &item)) return false;
if (ProcessInternalIOItem(item)) return true;
}
for (ULONG i = 0; i < items.count; ++i) {
IOItem& item = items.values[i];
if (ProcessInternalIOItem(item)) {
continue;
}
if (item.context->handler) {
if (filter && item.handler != filter) {
// Save this item for later
completed_io_.push_back(item);
} else {
DCHECK(item.context->handler == item.handler);
item.handler->OnIOCompleted(item.context, item.bytes_transfered);
}
if (item.context->handler) {
if (filter && item.handler != filter) {
// Save this item for later
completed_io_.push_back(item);
} else {
// The handler must be gone by now, just cleanup the mess.
delete item.context;
DCHECK(item.context->handler == item.handler);
item.handler->OnIOCompleted(item.context, item.bytes_transfered,
item.error);
}
} else {
// The handler must be gone by now, just cleanup the mess.
delete item.context;
}
return true;
}
// Asks the OS for another IO completion result.
bool MessagePumpForIO::GetIOItems(DWORD timeout, IOItemChunk* items) {
memset(items, 0, sizeof(*items));
OVERLAPPED_ENTRY entries[arraysize(items->values)];
bool MessagePumpForIO::GetIOItem(DWORD timeout, IOItem* item) {
memset(item, 0, sizeof(*item));
ULONG_PTR key = 0;
OVERLAPPED* overlapped = NULL;
AUTO_PROFILER_LABEL("MessagePumpForIO::GetIOItem::Wait", IDLE);
if (!GetQueuedCompletionStatusEx(port_.Get(), entries,
arraysize(items->values), &items->count,
timeout, FALSE)) {
return false; // Nothing in the queue.
}
for (int i = 0; i < (int)items->count; ++i) {
items->values[i].handler =
reinterpret_cast<IOHandler*>(entries[i].lpCompletionKey);
items->values[i].bytes_transfered = entries[i].dwNumberOfBytesTransferred;
items->values[i].context =
reinterpret_cast<IOContext*>(entries[i].lpOverlapped);
if (!GetQueuedCompletionStatus(port_.Get(), &item->bytes_transfered, &key,
&overlapped, timeout)) {
if (!overlapped) return false; // Nothing in the queue.
item->error = GetLastError();
item->bytes_transfered = 0;
}
item->handler = reinterpret_cast<IOHandler*>(key);
item->context = reinterpret_cast<IOContext*>(overlapped);
return true;
}

View File

@ -222,8 +222,8 @@ class MessagePumpForIO : public MessagePumpWin {
// delete context_;
// }
// }
// virtual void OnIOCompleted(IOContext* context, DWORD bytes_transfered)
// {
// virtual void OnIOCompleted(IOContext* context, DWORD bytes_transfered,
// DWORD error) {
// pending_ = false;
// }
// void DoSomeIo() {
@ -248,8 +248,8 @@ class MessagePumpForIO : public MessagePumpWin {
// // while there are pending IO operations.
// ~MyFile() {
// }
// virtual void OnIOCompleted(IOContext* context, DWORD bytes_transfered)
// {
// virtual void OnIOCompleted(IOContext* context, DWORD bytes_transfered,
// DWORD error) {
// ...
// delete context;
// }
@ -280,7 +280,8 @@ class MessagePumpForIO : public MessagePumpWin {
// |context| completes. |error| is the Win32 error code of the IO operation
// (ERROR_SUCCESS if there was no error). |bytes_transfered| will be zero
// on error.
virtual void OnIOCompleted(IOContext* context, DWORD bytes_transfered) = 0;
virtual void OnIOCompleted(IOContext* context, DWORD bytes_transfered,
DWORD error) = 0;
};
// The extended context that should be used as the base structure on every
@ -325,16 +326,13 @@ class MessagePumpForIO : public MessagePumpWin {
IOHandler* handler;
IOContext* context;
DWORD bytes_transfered;
};
struct IOItemChunk {
IOItem values[8];
ULONG count;
DWORD error;
};
virtual void DoRunLoop();
void WaitForWork();
bool MatchCompletedIOItem(IOHandler* filter, IOItem* item);
bool GetIOItems(DWORD timeout, IOItemChunk* items);
bool GetIOItem(DWORD timeout, IOItem* item);
bool ProcessInternalIOItem(const IOItem& item);
// The completion port associated with this thread.

View File

@ -286,7 +286,7 @@ bool Channel::ChannelImpl::Connect() {
// to true, we indicate to OnIOCompleted that this is the special
// initialization signal.
MessageLoopForIO::current()->PostTask(factory_.NewRunnableMethod(
&Channel::ChannelImpl::OnIOCompleted, &input_state_.context, 0));
&Channel::ChannelImpl::OnIOCompleted, &input_state_.context, 0, 0));
}
if (!waiting_connect_) ProcessOutgoingMessages(NULL, 0);
@ -556,7 +556,7 @@ bool Channel::ChannelImpl::ProcessOutgoingMessages(
}
void Channel::ChannelImpl::OnIOCompleted(MessageLoopForIO::IOContext* context,
DWORD bytes_transfered) {
DWORD bytes_transfered, DWORD error) {
bool ok;
ASSERT_OWNINGTHREAD(ChannelImpl);
if (context == &input_state_.context) {

View File

@ -68,7 +68,7 @@ class Channel::ChannelImpl : public MessageLoopForIO::IOHandler {
// MessageLoop::IOHandler implementation.
virtual void OnIOCompleted(MessageLoopForIO::IOContext* context,
DWORD bytes_transfered);
DWORD bytes_transfered, DWORD error);
private:
struct State {