Skip to content

Commit

Permalink
fix: int -> i32
Browse files Browse the repository at this point in the history
  • Loading branch information
iWas-Coder committed Apr 1, 2024
1 parent ed6d4c0 commit c9c088d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions include/sk_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
#define SK_SERVER_MSG_HELLO SK_SERVER_NAME "::hello"
#define SK_SERVER_MSG_HOWDY SK_SERVER_NAME "::howdy::%u/%u"

int sk_server_socket_create(void);
i32 sk_server_socket_create(void);

void sk_server_socket_destroy(int sock_fd);
void sk_server_socket_destroy(i32 sock_fd);

int sk_server_socket_bind(int sock_fd);
i32 sk_server_socket_bind(i32 sock_fd);

u8 sk_server_run(void);
4 changes: 2 additions & 2 deletions src/sk_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ u8 sk_client_run(const char *ip) {
.sin_port = htons(SK_SERVER_PORT),
.sin_addr.s_addr = inet_addr(ip)
};
int sock_fd = sk_server_socket_create();
i32 sock_fd = sk_server_socket_create();
if (sock_fd == -1) return 1;
SK_LOG_INFO("Connecting to `%s` ...", ip);
if (sendto(sock_fd,
Expand All @@ -67,7 +67,7 @@ u8 sk_client_run(const char *ip) {
return 1;
}
char howdy_msg[SK_SERVER_MSG_MAX_SIZE];
int howdy_msg_n = recv(sock_fd, howdy_msg, sizeof(howdy_msg), MSG_WAITALL);
i32 howdy_msg_n = recv(sock_fd, howdy_msg, sizeof(howdy_msg), MSG_WAITALL);
if (howdy_msg_n == -1) {
SK_LOG_ERROR("recv(2) :: %s", strerror(errno));
close(sock_fd);
Expand Down
16 changes: 8 additions & 8 deletions src/sk_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
static volatile u8 running = 1;
static volatile u8 clients = 0;

static inline void handle_interrupt(int signum) {
static inline void handle_interrupt(i32 signum) {
if (signum == SIGINT) running = 0;
}

Expand All @@ -57,28 +57,28 @@ static void wait_next_tick(double t) {
#endif
}

int sk_server_socket_create(void) {
int sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
i32 sk_server_socket_create(void) {
i32 sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sock_fd == -1) SK_LOG_ERROR("sk_server_socket_create :: %s", strerror(errno));
else SK_LOG_INFO("UDP socket created");
return sock_fd;
}

void sk_server_socket_destroy(int sock_fd) {
void sk_server_socket_destroy(i32 sock_fd) {
if (sock_fd == -1) {
SK_LOG_WARN("sk_server_socket_destroy :: `sock_fd` not valid");
return;
}
close(sock_fd);
}

int sk_server_socket_bind(int sock_fd) {
i32 sk_server_socket_bind(i32 sock_fd) {
const struct sockaddr_in addr = {
.sin_family = AF_INET,
.sin_port = htons(SK_SERVER_PORT),
.sin_addr.s_addr = inet_addr("127.0.0.1")
};
int result = bind(sock_fd, (const struct sockaddr *) &addr, sizeof(addr));
i32 result = bind(sock_fd, (const struct sockaddr *) &addr, sizeof(addr));
if (result == -1) {
SK_LOG_ERROR("sk_server_socket_bind :: %s", strerror(errno));
sk_server_socket_destroy(sock_fd);
Expand All @@ -89,15 +89,15 @@ int sk_server_socket_bind(int sock_fd) {

u8 sk_server_run(void) {
SK_LOG_INFO("Initializing %s", SK_SERVER_NAME);
int sock_fd = sk_server_socket_create();
i32 sock_fd = sk_server_socket_create();
if (sock_fd == -1) return 1;
if (sk_server_socket_bind(sock_fd) == -1) return 1;
double dt = 1 / SK_SERVER_TICK_RATE;
signal(SIGINT, handle_interrupt);
struct sockaddr_in client_addr;
socklen_t client_addr_len = sizeof(client_addr);
char msg[SK_SERVER_MSG_MAX_SIZE];
int msg_n = 0;
i32 msg_n = 0;
while (running) {
client_addr = (struct sockaddr_in) {0};
client_addr_len = sizeof(client_addr);
Expand Down

0 comments on commit c9c088d

Please sign in to comment.