manual testing
Some checks failed
Test and Deploy / test (push) Failing after 10s
Test and Deploy / docs (push) Has been skipped

This commit is contained in:
2024-07-07 20:05:32 -07:00
parent 1424925cbf
commit c52712471f
5 changed files with 43 additions and 14 deletions

View File

@ -1,4 +1,5 @@
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
@ -115,13 +116,26 @@ void handler_tcp_echo(Server *s) {
printf("Received connection from %s\n", buf);
// Start child process
if (!fork()) {
close(s->fd); // Child doesn't need the initial socket
if (send(new_fd, "Hello, world!", 13, 0) == -1) {
fprintf(stderr, "Failed to send hello world\n");
}
close(new_fd);
_exit(0);
if (!fork()) {
close(s->fd); // Child doesn't need the initial socket
char recv_buf[256];
int r = recv(new_fd, recv_buf, 256, 0);
if (r == -1) {
fprintf(stderr, "Failed to recv. Errno: %d\n", errno);
goto CHILD_END;
} else if (r == 0) {
fprintf(stderr, "Client closed connection\n");
goto CHILD_END;
}
if (send(new_fd, recv_buf, strlen(recv_buf), 0) == -1) {
fprintf(stderr, "Failed to send echo\n");
}
CHILD_END:
close(new_fd);
_exit(0);
}
// End child process