void central(int port) { struct epoll_event ev, events[MAX_EVENTS]; int nfds, epollfd; struct sockaddr_in saddr_client; int sock = mk_sock(port, INADDR_ANY, SOCK_STREAM); epollfd = epoll_create(10); if (epollfd == -1) { perror("epoll_create"); exit(EXIT_FAILURE); } ev.events = EPOLLIN; ev.data.fd = sock; if (epoll_ctl(epollfd, EPOLL_CTL_ADD, sock, &ev) == -1) { perror("epoll_ctl: sock"); exit(EXIT_FAILURE); } for (;;) { nfds = epoll_wait(epollfd, events, MAX_EVENTS, -1); puts("working ..."); if (nfds == -1) { perror("epoll_pwait"); exit(EXIT_FAILURE); } int n; for (n = 0; n < nfds; ++n) { if (events[n].data.fd == sock) { socklen_t size_addr = sizeof(struct sockaddr_in); int csock = accept(sock, (struct sockaddr *)&saddr_client, &size_addr); printf("accept : %s\n", strerror(errno)); printf("Connection de %s :: %d\n", inet_ntoa(saddr_client.sin_addr), htons(saddr_client.sin_port)); if (csock == -1) { perror("accept"); exit(EXIT_FAILURE); } /*setnonblocking(csock);*/ ev.events = EPOLLIN | EPOLLET; ev.data.fd = csock; if (epoll_ctl(epollfd, EPOLL_CTL_ADD, csock, &ev) == -1) { perror("epoll_ctl: csock"); exit(EXIT_FAILURE); } } else{ printf("%d\n", events[n].events == 1); if (events[n].events == 1) send_get_answer(events[n].data.fd); } } } }
/* make (or delete) an object in the filesystem */ gboolean mk_obj(FILE * in, char *p, struct rdup * e, GHashTable * uidhash, GHashTable * gidhash) { if (opt_verbose >= 1 && e->f_name) { if (S_ISLNK(e->f_mode) || e->f_lnk) fprintf(stderr, "%s -> %s\n", e->f_name, e->f_target); else fprintf(stderr, "%s\n", e->f_name); } if (opt_table) rdup_write_table(e, stdout); /* split here - or above - return when path is zero length * for links check that the f_size is zero */ switch (e->plusmin) { case MINUS: if (opt_dry || !e->f_name) return TRUE; return rm(e->f_name); case PLUS: /* opt_dry handled within the subfunctions */ /* only files, no hardlinks! */ if (S_ISREG(e->f_mode) && !e->f_lnk) return mk_reg(in, e, uidhash, gidhash); /* no name, we can exit here - for files this is handled * in mk_reg, because we may need to suck in data */ if (e->f_name == NULL) return TRUE; if (S_ISDIR(e->f_mode)) return mk_dir(e, uidhash, gidhash); /* First sym and hardlinks and then regular files */ if (S_ISLNK(e->f_mode) || e->f_lnk) return mk_link(e, p, uidhash, gidhash); if (S_ISBLK(e->f_mode) || S_ISCHR(e->f_mode)) return mk_dev(e, uidhash, gidhash); // There's no way to restore a named socket if (S_ISSOCK(e->f_mode)) return TRUE; if (S_ISFIFO(e->f_mode)) return mk_sock(e, uidhash, gidhash); } /* only reached during the heat death of the universe */ return TRUE; }