Compare commits

...

2 commits

Author SHA1 Message Date
Imbus
655b310328 Formatting ...... 2025-05-12 12:09:54 +02:00
Imbus
5392c8e418 Formatting target 2025-05-12 12:09:50 +02:00
3 changed files with 72 additions and 66 deletions

View file

@ -21,5 +21,10 @@ tags:
compile_commands.json:
bear -- make
format:
clang-format -i $(shell git ls-files '*.c' '*.h')
clean:
rm -rf $(OBJ) $(ELF) *.json .cache
.PHONY: format

View file

@ -15,8 +15,7 @@
// Round size up to nearest power-of-two order
static int size_to_order(size_t size) {
int order = MIN_ORDER;
while ((1U << order) < size)
order++;
while ((1U << order) < size) order++;
return order;
}

12
sock.c
View file

@ -1,10 +1,10 @@
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#include <unistd.h>
int main(void) {
// Get TCP protocol entry
@ -29,7 +29,8 @@ int main(void) {
};
// Bind socket
if (bind(server_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
if (bind(server_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) <
0) {
perror("bind failed");
close(server_fd);
return EXIT_FAILURE;
@ -47,7 +48,8 @@ int main(void) {
// Accept one client connection
struct sockaddr_in client_addr;
socklen_t client_len = sizeof(client_addr);
int client_fd = accept(server_fd, (struct sockaddr *)&client_addr, &client_len);
int client_fd =
accept(server_fd, (struct sockaddr *)&client_addr, &client_len);
if (client_fd < 0) {
perror("accept failed");
close(server_fd);