feat: Print statements labeled with Host tag
This commit is contained in:
parent
83a5dcaec7
commit
425062ab5c
8
main.c
8
main.c
|
@ -16,11 +16,11 @@ int start_server(int* socket_fd) {
|
||||||
server_addr.sin_port = htons(1337);
|
server_addr.sin_port = htons(1337);
|
||||||
server_addr.sin_addr.s_addr = INADDR_ANY;
|
server_addr.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
|
||||||
printf("Starting Server\n");
|
printf("[Host] Starting Server\n");
|
||||||
*socket_fd = socket(AF_INET, SOCK_STREAM, 0);
|
*socket_fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
int bound = bind(*socket_fd, (struct sockaddr*)&server_addr, sizeof(server_addr));
|
int bound = bind(*socket_fd, (struct sockaddr*)&server_addr, sizeof(server_addr));
|
||||||
if(bound < 0) {
|
if(bound < 0) {
|
||||||
printf("Bind Error: %s (%d)\n", strerror(errno), errno);
|
printf("[Host] Bind Error: %s (%d)\n", strerror(errno), errno);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
listen(*socket_fd, 5);
|
listen(*socket_fd, 5);
|
||||||
|
@ -54,7 +54,7 @@ int assign_workers(int* socket_fd) {
|
||||||
for(int i = 0; i < sizeof(ports); i++) {
|
for(int i = 0; i < sizeof(ports); i++) {
|
||||||
if(!ports[i]) {
|
if(!ports[i]) {
|
||||||
int port = 11000+i;
|
int port = 11000+i;
|
||||||
printf("Assigning port %i to worker\n", port);
|
printf("[Host] Assigning port %i to worker\n", port);
|
||||||
char buff[sizeof(int)];
|
char buff[sizeof(int)];
|
||||||
memcpy(buff, &port, sizeof(int));
|
memcpy(buff, &port, sizeof(int));
|
||||||
write(client_sock, buff, sizeof(buff));
|
write(client_sock, buff, sizeof(buff));
|
||||||
|
@ -69,7 +69,7 @@ int assign_workers(int* socket_fd) {
|
||||||
u_int32_t port;
|
u_int32_t port;
|
||||||
memcpy(&port, buffer+1, sizeof(u_int32_t));
|
memcpy(&port, buffer+1, sizeof(u_int32_t));
|
||||||
port = ntohl(port);
|
port = ntohl(port);
|
||||||
printf("Unassigning port %i\n", port);
|
printf("[Host] Unassigning port %i\n", port);
|
||||||
ports[11000-port] = false;
|
ports[11000-port] = false;
|
||||||
shutdown(client_sock, SHUT_RDWR);
|
shutdown(client_sock, SHUT_RDWR);
|
||||||
close(client_sock);
|
close(client_sock);
|
||||||
|
|
Loading…
Reference in New Issue