From cc9e6a2318352a8fd3a35c25fcb294331ff54288 Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Tue, 28 Apr 2009 02:02:55 +0200 Subject: USB mostly complete, main loop added, polls for devices --- main.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 9 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index c2467a2..6773d0e 100644 --- a/main.c +++ b/main.c @@ -42,13 +42,13 @@ int create_socket(void) { int listenfd; if(unlink(socket_path) == -1 && errno != ENOENT) { - usbmuxd_log(LOG_FATAL, "unlink(%s) failed: %s", socket_path, strerror(errno)); + usbmuxd_log(LL_FATAL, "unlink(%s) failed: %s", socket_path, strerror(errno)); return -1; } listenfd = socket(AF_UNIX, SOCK_STREAM, 0); if (listenfd == -1) { - usbmuxd_log(LOG_FATAL, "socket() failed: %s", strerror(errno)); + usbmuxd_log(LL_FATAL, "socket() failed: %s", strerror(errno)); return -1; } @@ -56,37 +56,85 @@ int create_socket(void) { bind_addr.sun_family = AF_UNIX; strcpy(bind_addr.sun_path, socket_path); if (bind(listenfd, (struct sockaddr*)&bind_addr, sizeof(bind_addr)) != 0) { - usbmuxd_log(LOG_FATAL, "bind() failed: %s", strerror(errno)); + usbmuxd_log(LL_FATAL, "bind() failed: %s", strerror(errno)); return -1; } // Start listening if (listen(listenfd, 5) != 0) { - usbmuxd_log(LOG_FATAL, "listen() failed: %s", strerror(errno)); + usbmuxd_log(LL_FATAL, "listen() failed: %s", strerror(errno)); return -1; } return listenfd; } +int main_loop(int listenfd) +{ + int to, cnt, i; + struct fdlist pollfds; + + while(1) { + usbmuxd_log(LL_SPEW, "main_loop iteration"); + to = usb_get_timeout(); + usbmuxd_log(LL_SPEW, "USB timeout is %d ms", to); + + fdlist_create(&pollfds); + usb_get_fds(&pollfds); + usbmuxd_log(LL_SPEW, "fd count is %d", pollfds.count); + + cnt = poll(pollfds.fds, pollfds.count, to); + usbmuxd_log(LL_SPEW, "poll() returned %d", cnt); + + if(cnt == 0) { + if(usb_process() < 0) { + usbmuxd_log(LL_FATAL, "usb_process() failed"); + return -1; + } + } else { + for(i=0; i