Trying to fk
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
HttpServerRunStatus http_server_setup(HttpServer *s) {
|
HttpServerRunStatus http_server_setup(HttpServer *s) {
|
||||||
@@ -48,6 +49,16 @@ HttpServerRunStatus http_server_run(HttpServer *s) {
|
|||||||
accept(s->server_fd, (struct sockaddr *)s->address, &addrlen)) < 0)
|
accept(s->server_fd, (struct sockaddr *)s->address, &addrlen)) < 0)
|
||||||
return HTTP_SRS_ACCEPT_FAILED;
|
return HTTP_SRS_ACCEPT_FAILED;
|
||||||
|
|
||||||
|
pid_t pid = fork();
|
||||||
|
if (pid < 0) {
|
||||||
|
close(client_fd);
|
||||||
|
return HTTP_SRS_FORK_FAILED;
|
||||||
|
}
|
||||||
|
if (pid > 0) {
|
||||||
|
close(client_fd);
|
||||||
|
return HTTP_SRS_WONT_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
char request[BUFSIZ] = {0};
|
char request[BUFSIZ] = {0};
|
||||||
|
|
||||||
if ((valread = read(client_fd, request, 1024 - 1)) < 0)
|
if ((valread = read(client_fd, request, 1024 - 1)) < 0)
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ typedef enum {
|
|||||||
HTTP_SRS_ACCEPT_FAILED,
|
HTTP_SRS_ACCEPT_FAILED,
|
||||||
HTTP_SRS_READ_FAILED,
|
HTTP_SRS_READ_FAILED,
|
||||||
HTTP_SRS_HANDLE_REQUEST_FAILED,
|
HTTP_SRS_HANDLE_REQUEST_FAILED,
|
||||||
|
HTTP_SRS_FORK_FAILED,
|
||||||
|
HTTP_SRS_WONT_HANDLE,
|
||||||
} HttpServerRunStatus;
|
} HttpServerRunStatus;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user