asio changeset 48031 - cpu spike fix (hopefully)

This commit is contained in:
Marcos Pinto 2008-08-13 02:37:14 +00:00
parent 07f65d8a22
commit fe2b8bf5d4
2 changed files with 16 additions and 16 deletions

View File

@ -421,15 +421,15 @@ private:
more_writes = write_op_queue_.perform_operation(descriptor, ec); more_writes = write_op_queue_.perform_operation(descriptor, ec);
else else
more_writes = write_op_queue_.has_operation(descriptor); more_writes = write_op_queue_.has_operation(descriptor);
if ((events[i].events & (POLLERR | POLLHUP)) != 0
if ((events[i].events == POLLHUP) && (events[i].events & ~(POLLERR | POLLHUP)) == 0
&& !more_except && !more_reads && !more_writes) && !more_except && !more_reads && !more_writes)
{ {
// If we have only an POLLHUP event and no operations associated // If we have an event and no operations associated with the
// with the descriptor then we need to delete the descriptor from // descriptor then we need to delete the descriptor from /dev/poll.
// /dev/poll. The poll operation might produce POLLHUP events even // The poll operation can produce POLLHUP or POLLERR events when there
// if they are not specifically requested, so if we do not remove the // is no operation pending, so if we do not remove the descriptor we
// descriptor we can end up in a tight polling loop. // can end up in a tight polling loop.
::pollfd ev = { 0 }; ::pollfd ev = { 0 };
ev.fd = descriptor; ev.fd = descriptor;
ev.events = POLLREMOVE; ev.events = POLLREMOVE;

View File

@ -495,15 +495,15 @@ private:
more_writes = write_op_queue_.perform_operation(descriptor, ec); more_writes = write_op_queue_.perform_operation(descriptor, ec);
else else
more_writes = write_op_queue_.has_operation(descriptor); more_writes = write_op_queue_.has_operation(descriptor);
if ((events[i].events & (EPOLLERR | EPOLLHUP)) != 0
if ((events[i].events == EPOLLHUP) && (events[i].events & ~(EPOLLERR | EPOLLHUP)) == 0
&& !more_except && !more_reads && !more_writes) && !more_except && !more_reads && !more_writes)
{ {
// If we have only an EPOLLHUP event and no operations associated // If we have an event and no operations associated with the
// with the descriptor then we need to delete the descriptor from // descriptor then we need to delete the descriptor from epoll. The
// epoll. The epoll_wait system call will produce EPOLLHUP events // epoll_wait system call can produce EPOLLHUP or EPOLLERR events
// even if they are not specifically requested, so if we do not // when there is no operation pending, so if we do not remove the
// remove the descriptor we can end up in a tight loop of repeated // descriptor we can end up in a tight loop of repeated
// calls to epoll_wait. // calls to epoll_wait.
epoll_event ev = { 0, { 0 } }; epoll_event ev = { 0, { 0 } };
epoll_ctl(epoll_fd_, EPOLL_CTL_DEL, descriptor, &ev); epoll_ctl(epoll_fd_, EPOLL_CTL_DEL, descriptor, &ev);