From d4e7c6876eed2733a2678668bdcabdd87659e826 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Mon, 21 Oct 2024 00:12:02 +0200 Subject: Added common code for messages - add: send_message, receive_message functions - change: use u8, u16, u32, where possible - fix: use PORT in server.c --- common.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'common.h') diff --git a/common.h b/common.h index fcf6c53..4786c14 100644 --- a/common.h +++ b/common.h @@ -39,3 +39,11 @@ u8 save_message(struct message *msg, FILE *f); // load the message msg from file f, returns zero on success, returns 1 if the msg.text // was empty which should not be allowed. u8 load_message(struct message *msg, FILE *f); + +// Send a stream of bytes containing msg +// return -1 if send() returns -1. Otherwise returns number of bytes sent. +u32 send_message(struct message msg, u32 serverfd); +// Receives a stream of bytes and populates msg with the data received +// if recv() returns 0 or -1 it will return early and return 0 or -1 accordingly. +// Otherwise returns the number of bytes received +u32 receive_message(struct message *msg, u32 clientfd); -- cgit v1.2.3