From 160886c6c4336da5a6090bca5af2a87919103ae3 Mon Sep 17 00:00:00 2001 From: Ilya Bezrukov Date: Wed, 25 Feb 2026 21:23:07 +0300 Subject: [PATCH] some fixes in lab2 --- lab02/Makefile | 4 ++-- lab02/client.c | 6 +++--- lab02/server.c | 20 +++++++++++--------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lab02/Makefile b/lab02/Makefile index 56b7df5..faf7d47 100644 --- a/lab02/Makefile +++ b/lab02/Makefile @@ -6,13 +6,13 @@ LIBS := -lpthread SSOURCES := server.c SOBJECTS = $(addprefix $(BIN), $(SSOURCES:.c=.o)) -SERVERNAME := otpserver +SERVERNAME := server SERVERNAME := $(addprefix $(BIN), $(SERVERNAME)) CSOURCES := client.c COBJECTS = $(addprefix $(BIN), $(CSOURCES:.c=.o)) -CLIENTNAME := otpclient +CLIENTNAME := client CLIENTNAME := $(addprefix $(BIN), $(CLIENTNAME)) diff --git a/lab02/client.c b/lab02/client.c index 7a183ca..b16dadd 100644 --- a/lab02/client.c +++ b/lab02/client.c @@ -8,7 +8,7 @@ #include #include -#define SOCKET_PATH "/tmp/otp_socket" +#define SOCKET_PATH "/tmp/socket" #define CMD_ECHO 1 #define CMD_TIMER 2 @@ -25,7 +25,7 @@ void send_fd(int socket, int fd) { char buf[CMSG_SPACE(sizeof(fd))]; memset(buf, 0, sizeof(buf)); - struct iovec io = { .iov_base = (void*)"F", .iov_len = 1 }; + struct iovec io = { .iov_base = "F", .iov_len = 1 }; msg.msg_iov = &io; msg.msg_iovlen = 1; @@ -67,7 +67,7 @@ int main(int argc, char *argv[]) { req.command = atoi(argv[2]); req.value = atoi(argv[3]); - write(sock, &req, sizeof(req)); + write(sock, &req, sizeof(struct request)); int response; read(sock, &response, sizeof(response)); diff --git a/lab02/server.c b/lab02/server.c index a857504..72b16a1 100644 --- a/lab02/server.c +++ b/lab02/server.c @@ -11,7 +11,7 @@ #include #include -#define SOCKET_PATH "/tmp/otp_socket" +#define SOCKET_PATH "/tmp/socket" #define MAX_CLIENTS 10 #define CMD_ECHO 1 @@ -71,18 +71,20 @@ void* worker_thread(void *arg) { continue; } + struct request *req = &(node->req); + char buffer[128]; - sprintf(buffer, "Processing request with priority %d", node->req.priority); + sprintf(buffer, "Processing (p: %d, c: %d, v: %d)", req->priority, req->command, req->value); log_msg(buffer); int response = 0; - if (node->req.command == CMD_ECHO) { - response = node->req.value; + if (req->command == CMD_ECHO) { + response = req->value; write(node->client_fd, &response, sizeof(response)); } - else if (node->req.command == CMD_TIMER) { - sleep(node->req.value); + else if (req->command == CMD_TIMER) { + sleep(req->value); uint64_t val = 1; write(node->event_fd, &val, sizeof(val)); response = 0; @@ -99,7 +101,7 @@ int recv_fd(int socket) { char buf[CMSG_SPACE(sizeof(int))]; memset(buf, 0, sizeof(buf)); - struct iovec io = { .iov_base = (void*)"F", .iov_len = 1 }; + struct iovec io = { .iov_base = "F", .iov_len = 1 }; msg.msg_iov = &io; msg.msg_iovlen = 1; @@ -138,8 +140,8 @@ int main() { int event_fd = recv_fd(client_fd); - struct request req; - read(client_fd, &req, sizeof(req)); + struct request req = {0, 0, 0}; + read(client_fd, &req, sizeof(struct request)); client_request_t *node = malloc(sizeof(client_request_t)); node->client_fd = client_fd;