Esempio n. 1
0
	bool UdpSocket::isRecvReady(int millisecs)
	{
		if (!select_for_read(m_sockfd, millisecs))
		{
			m_eError = ERR::SELECT_READ_ERROR;
			return false;
		}
		return true;
	}
Esempio n. 2
0
int
main(int argc, char *argv[]) {
    struct udev *udev;
    // struct udev_enumerate *enumerate;
//    struct udev_list_entry *devices, *device;
    udev_monitor = NULL;

    struct udev_device *udev_device;
    const char *action;


    udev = udev_new();
    if (!udev) {
        printf("udev_new failed\n");
        return 0;
    }
    udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
    if (!udev_monitor) {
        printf("udev_monitor_new_from_netlink failed\n");
        return 0;
    }

    udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "input", NULL);

    if (udev_monitor_enable_receiving(udev_monitor)) {
        printf("config/udev: failed to bind the udev monitor\n");
        return 0;
    }


    int udev_fd = udev_monitor_get_fd(udev_monitor);

    select_for_read(udev_fd);

    udev_device = udev_monitor_receive_device(udev_monitor);
    if (!udev_device) {
        printf("udev_monitor_receive_device failed\n");
        return 0;
    }
    action = udev_device_get_action(udev_device);
    printf("udev action %s\n", action);
    if (action) {
        if (!strcmp(action, "add") || !strcmp(action, "change")) {
            printf("device_removed(udev_device); device_added(udev_device);\n");
        }
        else if (!strcmp(action, "remove")) {
            printf("device_removed(udev_device);\n");
	}
    }
    udev_device_unref(udev_device);

    return 0;
}
Esempio n. 3
0
	bool TcpSocket::CanRecv()
	{
		return select_for_read(m_sockfd, 0);
	}