Implemented Hello World

This commit is contained in:
2020-12-09 22:45:35 +01:00
parent 00382a71e2
commit 24ce5d8cd6
4 changed files with 150 additions and 6 deletions

View File

@@ -5,6 +5,10 @@
* Lorenz Stechauner, 2020-12-03
*/
#include <sys/types.h>
#include <unistd.h>
#include "necronda-server.h"
#include "utils.h"
#include "net/http.h"
@@ -23,3 +27,28 @@ int client_connection_handler() {
// TODO implement client_connection_handler
return 0;
}
pid_t client_handler(int socket) {
struct sockaddr_in client_addr;
unsigned int client_addr_len = sizeof(client_addr);
int client = accept(socket, (struct sockaddr *) &client_addr, &client_addr_len);
if (client == -1) {
fprintf(stderr, ERR_STR "Unable to accept connection: %s" CLR_STR "\n", strerror(errno));
return -1;
}
pid_t pid = fork();
if (pid == 0) {
// child
recv(client, NULL, 0, 0);
char buf[] = "Hello world!\n";
send(client, buf, strlen(buf), 0);
close(client);
return 0;
} else {
// parent
close(client);
return pid;
}
}