2009-03-04 04:32:55 +01:00
|
|
|
/* http://frotznet.googlecode.com/svn/trunk/utils/fdevent.c
|
|
|
|
**
|
|
|
|
** Copyright 2006, Brian Swetland <swetland@frotz.net>
|
|
|
|
**
|
2015-08-03 19:38:08 +02:00
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
2009-03-04 04:32:55 +01:00
|
|
|
**
|
2015-08-03 19:38:08 +02:00
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
2009-03-04 04:32:55 +01:00
|
|
|
**
|
2015-08-03 19:38:08 +02:00
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
2009-03-04 04:32:55 +01:00
|
|
|
** limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2015-09-23 00:52:57 +02:00
|
|
|
#define TRACE_TAG FDEVENT
|
2011-03-16 23:57:42 +01:00
|
|
|
|
2015-03-19 23:21:08 +01:00
|
|
|
#include "sysdeps.h"
|
|
|
|
#include "fdevent.h"
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
#include <fcntl.h>
|
2015-03-19 23:21:08 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2016-02-10 23:49:00 +01:00
|
|
|
#include <atomic>
|
2015-09-05 01:19:56 +02:00
|
|
|
#include <list>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
|
|
|
|
2015-12-05 07:00:26 +01:00
|
|
|
#include <android-base/logging.h>
|
|
|
|
#include <android-base/stringprintf.h>
|
2015-09-05 01:19:56 +02:00
|
|
|
|
2015-02-25 06:26:58 +01:00
|
|
|
#include "adb_io.h"
|
2014-07-29 21:50:02 +02:00
|
|
|
#include "adb_trace.h"
|
2015-10-07 00:10:05 +02:00
|
|
|
#include "adb_utils.h"
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2015-09-05 01:19:56 +02:00
|
|
|
#if !ADB_HOST
|
2011-03-16 23:57:42 +01:00
|
|
|
// This socket is used when a subproc shell service exists.
|
|
|
|
// It wakes up the fdevent_loop() and cause the correct handling
|
|
|
|
// of the shell's pseudo-tty master. I.e. force close it.
|
|
|
|
int SHELL_EXIT_NOTIFY_FD = -1;
|
2015-07-17 21:30:59 +02:00
|
|
|
#endif // !ADB_HOST
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
#define FDE_EVENTMASK 0x00ff
|
|
|
|
#define FDE_STATEMASK 0xff00
|
|
|
|
|
|
|
|
#define FDE_ACTIVE 0x0100
|
|
|
|
#define FDE_PENDING 0x0200
|
|
|
|
#define FDE_CREATED 0x0400
|
|
|
|
|
2015-09-05 01:19:56 +02:00
|
|
|
struct PollNode {
|
|
|
|
fdevent* fde;
|
2016-02-17 02:34:53 +01:00
|
|
|
adb_pollfd pollfd;
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2015-09-05 01:19:56 +02:00
|
|
|
PollNode(fdevent* fde) : fde(fde) {
|
|
|
|
memset(&pollfd, 0, sizeof(pollfd));
|
|
|
|
pollfd.fd = fde->fd;
|
2015-09-29 21:25:33 +02:00
|
|
|
|
|
|
|
#if defined(__linux__)
|
|
|
|
// Always enable POLLRDHUP, so the host server can take action when some clients disconnect.
|
|
|
|
// Then we can avoid leaving many sockets in CLOSE_WAIT state. See http://b/23314034.
|
|
|
|
pollfd.events = POLLRDHUP;
|
|
|
|
#endif
|
2015-09-05 01:19:56 +02:00
|
|
|
}
|
|
|
|
};
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2015-09-05 01:19:56 +02:00
|
|
|
// All operations to fdevent should happen only in the main thread.
|
|
|
|
// That's why we don't need a lock for fdevent.
|
2015-11-12 02:56:12 +01:00
|
|
|
static auto& g_poll_node_map = *new std::unordered_map<int, PollNode>();
|
|
|
|
static auto& g_pending_list = *new std::list<fdevent*>();
|
2016-02-10 23:49:00 +01:00
|
|
|
static std::atomic<bool> terminate_loop(false);
|
2015-10-31 02:37:26 +01:00
|
|
|
static bool main_thread_valid;
|
2016-02-17 02:34:53 +01:00
|
|
|
static unsigned long main_thread_id;
|
2015-10-31 02:37:26 +01:00
|
|
|
|
|
|
|
static void check_main_thread() {
|
|
|
|
if (main_thread_valid) {
|
2016-02-17 02:34:53 +01:00
|
|
|
CHECK_EQ(main_thread_id, adb_thread_id());
|
2015-10-31 02:37:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_main_thread() {
|
|
|
|
main_thread_valid = true;
|
2016-02-17 02:34:53 +01:00
|
|
|
main_thread_id = adb_thread_id();
|
2015-10-31 02:37:26 +01:00
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2015-09-05 01:19:56 +02:00
|
|
|
static std::string dump_fde(const fdevent* fde) {
|
|
|
|
std::string state;
|
|
|
|
if (fde->state & FDE_ACTIVE) {
|
|
|
|
state += "A";
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
2015-09-05 01:19:56 +02:00
|
|
|
if (fde->state & FDE_PENDING) {
|
|
|
|
state += "P";
|
2014-09-26 00:10:34 +02:00
|
|
|
}
|
2015-09-05 01:19:56 +02:00
|
|
|
if (fde->state & FDE_CREATED) {
|
|
|
|
state += "C";
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
2015-09-05 01:19:56 +02:00
|
|
|
if (fde->state & FDE_READ) {
|
|
|
|
state += "R";
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
2015-09-05 01:19:56 +02:00
|
|
|
if (fde->state & FDE_WRITE) {
|
|
|
|
state += "W";
|
|
|
|
}
|
|
|
|
if (fde->state & FDE_ERROR) {
|
|
|
|
state += "E";
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
2015-09-05 01:19:56 +02:00
|
|
|
if (fde->state & FDE_DONT_CLOSE) {
|
|
|
|
state += "D";
|
|
|
|
}
|
|
|
|
return android::base::StringPrintf("(fdevent %d %s)", fde->fd, state.c_str());
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
2015-09-05 01:19:56 +02:00
|
|
|
fdevent *fdevent_create(int fd, fd_func func, void *arg)
|
2009-03-04 04:32:55 +01:00
|
|
|
{
|
2015-10-31 02:37:26 +01:00
|
|
|
check_main_thread();
|
2015-09-05 01:19:56 +02:00
|
|
|
fdevent *fde = (fdevent*) malloc(sizeof(fdevent));
|
|
|
|
if(fde == 0) return 0;
|
|
|
|
fdevent_install(fde, fd, func, arg);
|
|
|
|
fde->state |= FDE_CREATED;
|
|
|
|
return fde;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
2015-09-05 01:19:56 +02:00
|
|
|
void fdevent_destroy(fdevent *fde)
|
2009-03-04 04:32:55 +01:00
|
|
|
{
|
2015-10-31 02:37:26 +01:00
|
|
|
check_main_thread();
|
2015-09-05 01:19:56 +02:00
|
|
|
if(fde == 0) return;
|
|
|
|
if(!(fde->state & FDE_CREATED)) {
|
|
|
|
LOG(FATAL) << "destroying fde not created by fdevent_create(): " << dump_fde(fde);
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
2015-09-05 01:19:56 +02:00
|
|
|
fdevent_remove(fde);
|
|
|
|
free(fde);
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
2015-09-05 01:19:56 +02:00
|
|
|
void fdevent_install(fdevent* fde, int fd, fd_func func, void* arg) {
|
2015-10-31 02:37:26 +01:00
|
|
|
check_main_thread();
|
2015-09-05 01:19:56 +02:00
|
|
|
CHECK_GE(fd, 0);
|
|
|
|
memset(fde, 0, sizeof(fdevent));
|
|
|
|
fde->state = FDE_ACTIVE;
|
|
|
|
fde->fd = fd;
|
|
|
|
fde->func = func;
|
|
|
|
fde->arg = arg;
|
2015-10-07 00:10:05 +02:00
|
|
|
if (!set_file_block_mode(fd, false)) {
|
2015-09-16 01:27:09 +02:00
|
|
|
// Here is not proper to handle the error. If it fails here, some error is
|
|
|
|
// likely to be detected by poll(), then we can let the callback function
|
|
|
|
// to handle it.
|
2015-10-07 00:10:05 +02:00
|
|
|
LOG(ERROR) << "failed to set non-blocking mode for fd " << fd;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
2015-09-05 01:19:56 +02:00
|
|
|
auto pair = g_poll_node_map.emplace(fde->fd, PollNode(fde));
|
|
|
|
CHECK(pair.second) << "install existing fd " << fd;
|
|
|
|
D("fdevent_install %s", dump_fde(fde).c_str());
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
2015-09-05 01:19:56 +02:00
|
|
|
void fdevent_remove(fdevent* fde) {
|
2015-10-31 02:37:26 +01:00
|
|
|
check_main_thread();
|
2015-09-05 01:19:56 +02:00
|
|
|
D("fdevent_remove %s", dump_fde(fde).c_str());
|
|
|
|
if (fde->state & FDE_ACTIVE) {
|
|
|
|
g_poll_node_map.erase(fde->fd);
|
|
|
|
if (fde->state & FDE_PENDING) {
|
|
|
|
g_pending_list.remove(fde);
|
|
|
|
}
|
|
|
|
if (!(fde->state & FDE_DONT_CLOSE)) {
|
|
|
|
adb_close(fde->fd);
|
|
|
|
fde->fd = -1;
|
|
|
|
}
|
|
|
|
fde->state = 0;
|
|
|
|
fde->events = 0;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
2015-09-05 01:19:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void fdevent_update(fdevent* fde, unsigned events) {
|
|
|
|
auto it = g_poll_node_map.find(fde->fd);
|
|
|
|
CHECK(it != g_poll_node_map.end());
|
|
|
|
PollNode& node = it->second;
|
|
|
|
if (events & FDE_READ) {
|
|
|
|
node.pollfd.events |= POLLIN;
|
2009-03-04 04:32:55 +01:00
|
|
|
} else {
|
2015-09-05 01:19:56 +02:00
|
|
|
node.pollfd.events &= ~POLLIN;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
2015-09-05 01:19:56 +02:00
|
|
|
|
|
|
|
if (events & FDE_WRITE) {
|
|
|
|
node.pollfd.events |= POLLOUT;
|
2009-03-04 04:32:55 +01:00
|
|
|
} else {
|
2015-09-05 01:19:56 +02:00
|
|
|
node.pollfd.events &= ~POLLOUT;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
2011-03-16 23:57:42 +01:00
|
|
|
fde->state = (fde->state & FDE_STATEMASK) | events;
|
|
|
|
}
|
|
|
|
|
2015-09-05 01:19:56 +02:00
|
|
|
void fdevent_set(fdevent* fde, unsigned events) {
|
2015-10-31 02:37:26 +01:00
|
|
|
check_main_thread();
|
2015-09-05 01:19:56 +02:00
|
|
|
events &= FDE_EVENTMASK;
|
|
|
|
if ((fde->state & FDE_EVENTMASK) == events) {
|
|
|
|
return;
|
2011-03-16 23:57:42 +01:00
|
|
|
}
|
2015-09-30 03:33:38 +02:00
|
|
|
CHECK(fde->state & FDE_ACTIVE);
|
|
|
|
fdevent_update(fde, events);
|
|
|
|
D("fdevent_set: %s, events = %u", dump_fde(fde).c_str(), events);
|
2015-09-05 01:19:56 +02:00
|
|
|
|
2015-09-30 03:33:38 +02:00
|
|
|
if (fde->state & FDE_PENDING) {
|
|
|
|
// If we are pending, make sure we don't signal an event that is no longer wanted.
|
|
|
|
fde->events &= events;
|
|
|
|
if (fde->events == 0) {
|
|
|
|
g_pending_list.remove(fde);
|
|
|
|
fde->state &= ~FDE_PENDING;
|
2011-03-16 23:57:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2015-09-05 01:19:56 +02:00
|
|
|
void fdevent_add(fdevent* fde, unsigned events) {
|
2015-10-31 02:37:26 +01:00
|
|
|
check_main_thread();
|
2015-09-05 01:19:56 +02:00
|
|
|
fdevent_set(fde, (fde->state & FDE_EVENTMASK) | events);
|
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2015-09-05 01:19:56 +02:00
|
|
|
void fdevent_del(fdevent* fde, unsigned events) {
|
2015-10-31 02:37:26 +01:00
|
|
|
check_main_thread();
|
2015-09-05 01:19:56 +02:00
|
|
|
fdevent_set(fde, (fde->state & FDE_EVENTMASK) & ~events);
|
|
|
|
}
|
2009-05-18 17:36:28 +02:00
|
|
|
|
2016-02-17 02:34:53 +01:00
|
|
|
static std::string dump_pollfds(const std::vector<adb_pollfd>& pollfds) {
|
2015-09-05 01:19:56 +02:00
|
|
|
std::string result;
|
2015-10-08 00:59:35 +02:00
|
|
|
for (const auto& pollfd : pollfds) {
|
2015-09-05 01:19:56 +02:00
|
|
|
std::string op;
|
|
|
|
if (pollfd.events & POLLIN) {
|
|
|
|
op += "R";
|
|
|
|
}
|
|
|
|
if (pollfd.events & POLLOUT) {
|
|
|
|
op += "W";
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
2015-09-05 01:19:56 +02:00
|
|
|
android::base::StringAppendF(&result, " %d(%s)", pollfd.fd, op.c_str());
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
2015-09-05 01:19:56 +02:00
|
|
|
return result;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
2015-09-05 01:19:56 +02:00
|
|
|
static void fdevent_process() {
|
2016-02-17 02:34:53 +01:00
|
|
|
std::vector<adb_pollfd> pollfds;
|
2015-10-08 00:59:35 +02:00
|
|
|
for (const auto& pair : g_poll_node_map) {
|
|
|
|
pollfds.push_back(pair.second.pollfd);
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
2015-09-05 01:19:56 +02:00
|
|
|
CHECK_GT(pollfds.size(), 0u);
|
|
|
|
D("poll(), pollfds = %s", dump_pollfds(pollfds).c_str());
|
2016-02-17 02:34:53 +01:00
|
|
|
int ret = adb_poll(&pollfds[0], pollfds.size(), -1);
|
2015-09-05 01:19:56 +02:00
|
|
|
if (ret == -1) {
|
2015-09-16 01:27:09 +02:00
|
|
|
PLOG(ERROR) << "poll(), ret = " << ret;
|
|
|
|
return;
|
2015-09-05 01:19:56 +02:00
|
|
|
}
|
2015-10-08 00:59:35 +02:00
|
|
|
for (const auto& pollfd : pollfds) {
|
2015-09-16 01:27:09 +02:00
|
|
|
if (pollfd.revents != 0) {
|
|
|
|
D("for fd %d, revents = %x", pollfd.fd, pollfd.revents);
|
|
|
|
}
|
2015-09-05 01:19:56 +02:00
|
|
|
unsigned events = 0;
|
|
|
|
if (pollfd.revents & POLLIN) {
|
|
|
|
events |= FDE_READ;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
2015-09-05 01:19:56 +02:00
|
|
|
if (pollfd.revents & POLLOUT) {
|
|
|
|
events |= FDE_WRITE;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
2015-09-05 01:19:56 +02:00
|
|
|
if (pollfd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
|
|
|
|
// We fake a read, as the rest of the code assumes that errors will
|
|
|
|
// be detected at that point.
|
|
|
|
events |= FDE_READ | FDE_ERROR;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
2015-09-29 21:25:33 +02:00
|
|
|
#if defined(__linux__)
|
|
|
|
if (pollfd.revents & POLLRDHUP) {
|
|
|
|
events |= FDE_READ | FDE_ERROR;
|
|
|
|
}
|
|
|
|
#endif
|
2015-09-05 01:19:56 +02:00
|
|
|
if (events != 0) {
|
|
|
|
auto it = g_poll_node_map.find(pollfd.fd);
|
|
|
|
CHECK(it != g_poll_node_map.end());
|
|
|
|
fdevent* fde = it->second.fde;
|
|
|
|
CHECK_EQ(fde->fd, pollfd.fd);
|
|
|
|
fde->events |= events;
|
|
|
|
D("%s got events %x", dump_fde(fde).c_str(), events);
|
|
|
|
fde->state |= FDE_PENDING;
|
|
|
|
g_pending_list.push_back(fde);
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-16 23:57:42 +01:00
|
|
|
static void fdevent_call_fdfunc(fdevent* fde)
|
|
|
|
{
|
|
|
|
unsigned events = fde->events;
|
|
|
|
fde->events = 0;
|
2015-09-30 03:33:38 +02:00
|
|
|
CHECK(fde->state & FDE_PENDING);
|
2011-03-16 23:57:42 +01:00
|
|
|
fde->state &= (~FDE_PENDING);
|
2015-09-05 01:19:56 +02:00
|
|
|
D("fdevent_call_fdfunc %s", dump_fde(fde).c_str());
|
2011-03-16 23:57:42 +01:00
|
|
|
fde->func(fde->fd, events, fde->arg);
|
|
|
|
}
|
|
|
|
|
2015-07-17 21:30:59 +02:00
|
|
|
#if !ADB_HOST
|
2016-02-17 02:34:53 +01:00
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
2014-11-25 08:34:35 +01:00
|
|
|
static void fdevent_subproc_event_func(int fd, unsigned ev,
|
|
|
|
void* /* userdata */)
|
2011-03-16 23:57:42 +01:00
|
|
|
{
|
|
|
|
|
2015-09-05 01:19:56 +02:00
|
|
|
D("subproc handling on fd = %d, ev = %x", fd, ev);
|
2011-03-16 23:57:42 +01:00
|
|
|
|
2015-09-05 01:19:56 +02:00
|
|
|
CHECK_GE(fd, 0);
|
2011-03-16 23:57:42 +01:00
|
|
|
|
2015-09-05 01:19:56 +02:00
|
|
|
if (ev & FDE_READ) {
|
|
|
|
int subproc_fd;
|
2011-03-16 23:57:42 +01:00
|
|
|
|
2015-09-05 01:19:56 +02:00
|
|
|
if(!ReadFdExactly(fd, &subproc_fd, sizeof(subproc_fd))) {
|
|
|
|
LOG(FATAL) << "Failed to read the subproc's fd from " << fd;
|
|
|
|
}
|
|
|
|
auto it = g_poll_node_map.find(subproc_fd);
|
|
|
|
if (it == g_poll_node_map.end()) {
|
|
|
|
D("subproc_fd %d cleared from fd_table", subproc_fd);
|
2016-01-20 01:21:17 +01:00
|
|
|
adb_close(subproc_fd);
|
2015-09-05 01:19:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
fdevent* subproc_fde = it->second.fde;
|
|
|
|
if(subproc_fde->fd != subproc_fd) {
|
|
|
|
// Already reallocated?
|
2016-01-20 01:21:17 +01:00
|
|
|
LOG(FATAL) << "subproc_fd(" << subproc_fd << ") != subproc_fde->fd(" << subproc_fde->fd
|
|
|
|
<< ")";
|
2015-09-05 01:19:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
subproc_fde->force_eof = 1;
|
|
|
|
|
|
|
|
int rcount = 0;
|
|
|
|
ioctl(subproc_fd, FIONREAD, &rcount);
|
|
|
|
D("subproc with fd %d has rcount=%d, err=%d", subproc_fd, rcount, errno);
|
|
|
|
if (rcount != 0) {
|
|
|
|
// If there is data left, it will show up in the select().
|
|
|
|
// This works because there is no other thread reading that
|
|
|
|
// data when in this fd_func().
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
D("subproc_fde %s", dump_fde(subproc_fde).c_str());
|
|
|
|
subproc_fde->events |= FDE_READ;
|
|
|
|
if(subproc_fde->state & FDE_PENDING) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
subproc_fde->state |= FDE_PENDING;
|
|
|
|
fdevent_call_fdfunc(subproc_fde);
|
2011-03-16 23:57:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-17 21:30:59 +02:00
|
|
|
void fdevent_subproc_setup()
|
|
|
|
{
|
|
|
|
int s[2];
|
|
|
|
|
|
|
|
if(adb_socketpair(s)) {
|
2015-09-05 01:19:56 +02:00
|
|
|
PLOG(FATAL) << "cannot create shell-exit socket-pair";
|
2015-07-17 21:30:59 +02:00
|
|
|
}
|
2015-09-05 01:19:56 +02:00
|
|
|
D("fdevent_subproc: socket pair (%d, %d)", s[0], s[1]);
|
2015-07-17 21:30:59 +02:00
|
|
|
|
|
|
|
SHELL_EXIT_NOTIFY_FD = s[0];
|
2015-09-05 01:19:56 +02:00
|
|
|
fdevent *fde = fdevent_create(s[1], fdevent_subproc_event_func, NULL);
|
|
|
|
CHECK(fde != nullptr) << "cannot create fdevent for shell-exit handler";
|
2015-07-17 21:30:59 +02:00
|
|
|
fdevent_add(fde, FDE_READ);
|
|
|
|
}
|
|
|
|
#endif // !ADB_HOST
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
void fdevent_loop()
|
|
|
|
{
|
2015-10-31 02:37:26 +01:00
|
|
|
set_main_thread();
|
2015-07-17 21:30:59 +02:00
|
|
|
#if !ADB_HOST
|
2011-03-16 23:57:42 +01:00
|
|
|
fdevent_subproc_setup();
|
2015-07-17 21:30:59 +02:00
|
|
|
#endif // !ADB_HOST
|
2009-05-18 17:36:28 +02:00
|
|
|
|
2015-08-03 19:38:08 +02:00
|
|
|
while (true) {
|
2016-02-10 23:49:00 +01:00
|
|
|
if (terminate_loop) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-05 01:19:56 +02:00
|
|
|
D("--- --- waiting for events");
|
2011-03-16 23:57:42 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
fdevent_process();
|
2009-05-18 17:36:28 +02:00
|
|
|
|
2015-09-05 01:19:56 +02:00
|
|
|
while (!g_pending_list.empty()) {
|
|
|
|
fdevent* fde = g_pending_list.front();
|
|
|
|
g_pending_list.pop_front();
|
2011-03-16 23:57:42 +01:00
|
|
|
fdevent_call_fdfunc(fde);
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-16 01:27:09 +02:00
|
|
|
|
2016-02-10 23:49:00 +01:00
|
|
|
void fdevent_terminate_loop() {
|
|
|
|
terminate_loop = true;
|
|
|
|
}
|
|
|
|
|
2015-09-16 01:27:09 +02:00
|
|
|
size_t fdevent_installed_count() {
|
|
|
|
return g_poll_node_map.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void fdevent_reset() {
|
|
|
|
g_poll_node_map.clear();
|
|
|
|
g_pending_list.clear();
|
2015-10-31 02:37:26 +01:00
|
|
|
main_thread_valid = false;
|
2016-02-10 23:49:00 +01:00
|
|
|
terminate_loop = false;
|
2015-09-16 01:27:09 +02:00
|
|
|
}
|