Compare commits

..

No commits in common. "655b310328ff9025188bf61d2a7d13a9ccd35f2b" and "c2b9a13235032e0c2343a6a2914ad840e4e94180" have entirely different histories.

3 changed files with 66 additions and 72 deletions

View file

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

View file

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

12
sock.c
View file

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