gint main(gint argc, gchar *argv[]) { /* setup the functions filetransfer will use in place of the shadow library */ b.shadowlib = &bmain_functionTable; /* Let's download some files */ browser_start(&b, argc, argv); /* now we need to watch all the epoll descriptors in our main loop */ gint epolld = epoll_create(1); if(epolld == -1) { bmain_log(SHADOW_LOG_LEVEL_WARNING, __FUNCTION__, "Error in server epoll_create"); close(epolld); return -1; } struct epoll_event ev; ev.events = EPOLLIN|EPOLLOUT; /* watch the inner epoll descriptor */ if(b.epolld) { ev.data.fd = b.epolld; epoll_ctl(epolld, EPOLL_CTL_ADD, ev.data.fd, &ev); } /* main loop on our epoll descriptors that watch the filetransfer epollds */ struct epoll_event events[10]; int nReadyFDs; while(TRUE) { /* wait for some events */ nReadyFDs = epoll_wait(epolld, events, 10, 0); if(nReadyFDs == -1) { bmain_log(SHADOW_LOG_LEVEL_WARNING, __FUNCTION__, "error in client epoll_wait"); return -1; } /* activate for every socket thats ready */ for(int i = 0; i < nReadyFDs; i++) { browser_activate(&b, events[i].data.fd); } /* break out if the client is done */ if(b.state == SB_SUCCESS) { break; } } /* cleanup and close */ if(b.epolld) { ev.data.fd = b.epolld; epoll_ctl(epolld, EPOLL_CTL_DEL, ev.data.fd, &ev); } close(epolld); browser_free(&b); return 0; }
static void browserplugin_activate() { if(!b.epolld) { b.shadowlib->log(G_LOG_LEVEL_WARNING, __FUNCTION__, "client cant wait on epoll without epoll descriptor"); } else { struct epoll_event events[10]; int nfds = epoll_wait(b.epolld, events, 10, 0); if(nfds == -1) { b.shadowlib->log(G_LOG_LEVEL_WARNING, __FUNCTION__, "error in client epoll_wait"); } else { /* finally, activate client for every socket thats ready */ for(int i = 0; i < nfds; i++) { browser_activate(&b, events[i].data.fd); } } } }