file_handler *next_file_handler;
#ifdef HAVE_POLL
- /* Ptr to array of pollfd structures. */
- struct pollfd *poll_fds;
+ /* Descriptors to poll. */
+ std::vector<struct pollfd> poll_fds;
/* Next file descriptor to handle, for the poll variant. To level
the fairness across event sources, we poll the file descriptors
if (use_poll)
{
gdb_notifier.num_fds++;
- if (gdb_notifier.poll_fds)
- gdb_notifier.poll_fds =
- (struct pollfd *) xrealloc (gdb_notifier.poll_fds,
- (gdb_notifier.num_fds
- * sizeof (struct pollfd)));
- else
- gdb_notifier.poll_fds =
- XNEW (struct pollfd);
- (gdb_notifier.poll_fds + gdb_notifier.num_fds - 1)->fd = fd;
- (gdb_notifier.poll_fds + gdb_notifier.num_fds - 1)->events = mask;
- (gdb_notifier.poll_fds + gdb_notifier.num_fds - 1)->revents = 0;
+ struct pollfd new_fd;
+ new_fd.fd = fd;
+ new_fd.events = mask;
+ new_fd.revents = 0;
+ gdb_notifier.poll_fds.push_back (new_fd);
}
else
#endif /* HAVE_POLL */
#ifdef HAVE_POLL
if (use_poll)
{
- int j;
- struct pollfd *new_poll_fds;
-
- /* Create a new poll_fds array by copying every fd's information
- but the one we want to get rid of. */
-
- new_poll_fds = (struct pollfd *)
- xmalloc ((gdb_notifier.num_fds - 1) * sizeof (struct pollfd));
-
- for (i = 0, j = 0; i < gdb_notifier.num_fds; i++)
- {
- if ((gdb_notifier.poll_fds + i)->fd != fd)
- {
- (new_poll_fds + j)->fd = (gdb_notifier.poll_fds + i)->fd;
- (new_poll_fds + j)->events = (gdb_notifier.poll_fds + i)->events;
- (new_poll_fds + j)->revents
- = (gdb_notifier.poll_fds + i)->revents;
- j++;
- }
- }
- xfree (gdb_notifier.poll_fds);
- gdb_notifier.poll_fds = new_poll_fds;
+ auto iter = std::remove_if (gdb_notifier.poll_fds.begin (),
+ gdb_notifier.poll_fds.end (),
+ [=] (const pollfd &item)
+ {
+ return item.fd == fd;
+ });
+ gdb_notifier.poll_fds.erase (iter, gdb_notifier.poll_fds.end());
gdb_notifier.num_fds--;
}
else
else
timeout = 0;
- num_found = poll (gdb_notifier.poll_fds,
+ num_found = poll (gdb_notifier.poll_fds.data (),
(unsigned long) gdb_notifier.num_fds, timeout);
/* Don't print anything if we get out of poll because of a
i = gdb_notifier.next_poll_fds_index++;
gdb_assert (i < gdb_notifier.num_fds);
- if ((gdb_notifier.poll_fds + i)->revents)
+ if (gdb_notifier.poll_fds[i].revents)
break;
}
file_ptr != NULL;
file_ptr = file_ptr->next_file)
{
- if (file_ptr->fd == (gdb_notifier.poll_fds + i)->fd)
+ if (file_ptr->fd == gdb_notifier.poll_fds[i].fd)
break;
}
gdb_assert (file_ptr != NULL);
- mask = (gdb_notifier.poll_fds + i)->revents;
+ mask = gdb_notifier.poll_fds[i].revents;
handle_file_event (file_ptr, mask);
return 1;
}