如何在libevent中使用libusb?
|
我正在使用libevent编写事件驱动的应用程序,并且需要使用libusb-1.0进行USB传输。
我想使用libusb_get_pollfds获取文件描述符列表(在
fds
中),并将它们添加到libevent中,如下所示:
const struct libusb_pollfd **fds = libusb_get_pollfds(device->context);
const struct libusb_pollfd *it = *fds;
for(;it != NULL; ++it) {
cout << \"Adding fd: \" << it->fd << \", \" << it->events << endl;
struct event * ev = event_new(base_,
it->fd, it->events | EV_PERSIST,
callbacks::libusb_cb, this);
event_add(ev, 0);
libusb_fds_events.insert(std::make_pair(it->fd, ev));
}
free(fds);
// (...)
// And the callback function:
void callbacks::libusb_cb(evutil_socket_t fd, short what, void *arg) {
Server *s = reinterpret_cast<Server*>(arg);
libusb_handle_events_timeout(s->device_->context, 0);
}
另外,我使用libusb_set_pollfd_notifiers从libusb_fds_events
添加/删除fds。
问题是我在libusb返回的列表上得到了许多奇怪的fds(例如,在事件等于0的情况下,我多次获得stdin
(!)。
我是否以正确的方式使用它?
没有找到相关结果
已邀请:
1 个回复
摊揉售