Accept incoming connections inside main loop
This commit is contained in:
parent
b39e263499
commit
21de6cd3e7
18
main.c
18
main.c
@ -16,6 +16,7 @@
|
|||||||
* <https://www.gnu.org/licenses/>.
|
* <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@ -65,8 +66,23 @@ int main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct sockaddr_in6 paddr;
|
||||||
|
socklen_t paddr_size = sizeof(paddr);
|
||||||
|
int cfd;
|
||||||
while (!exit_requested) {
|
while (!exit_requested) {
|
||||||
sleep(1);
|
cfd = accept(sfd, (struct sockaddr *)&paddr, &paddr_size);
|
||||||
|
if (cfd == -1) {
|
||||||
|
if (errno != EINTR) {
|
||||||
|
fprintf(stderr, "Error accepting connection\n");
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Accepted connection\n");
|
||||||
|
|
||||||
|
close(cfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
close(sfd);
|
close(sfd);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user