intirain 4 лет назад
Родитель
Сommit
ef0290b103
6 измененных файлов с 16 добавлено и 10 удалено
  1. 1 1
      Makefile
  2. 4 1
      include/vcc/vcc.h
  3. 2 1
      include/vcc/vccd.h
  4. 1 1
      include/vcc/version.h
  5. 1 1
      main.c
  6. 7 5
      vcc.c

+ 1 - 1
Makefile

@@ -1,6 +1,6 @@
 VCCD_MAJOR 		= 0
 VCCD_MINOR 		= 1
-VCCD_PATCH 		= 4
+VCCD_PATCH 		= 5
 VCCD_COMPILE_TIME 	= $(shell date)
 VCCD_COMPILE_BY 	= $(shell whoami)
 

+ 4 - 1
include/vcc/vcc.h

@@ -35,6 +35,8 @@
 #define REQ_MSG_NEW 	2
 
 #define REQ_SIZE 	4096
+#define USRNAME_SIZE 	32
+#define MSG_SIZE 	(REQ_SIZE - 3 * sizeof(int) - USRNAME_SIZE)
 
 struct vcc_request {
 	int 		magic;
@@ -42,7 +44,8 @@ struct vcc_request {
 
 	/* to make server easy and fast */
 	int 		uid;
-	char 		*msg;
+	char 		usrname[USRNAME_SIZE];
+	char 		msg[MSG_SIZE];
 };
 
 #define to_boolean(c) 	(!!(c))

+ 2 - 1
include/vcc/vccd.h

@@ -24,6 +24,7 @@
 
 #include <stdio.h>
 #include <arpa/inet.h>
+#include <vcc/vcc.h>
 
 #define vcc_log(msg, ...) 	fprintf(stderr, msg, ##__VA_ARGS__)
 
@@ -31,7 +32,7 @@ int vcc_new_connection(int fd, struct in_addr *addr);
 int vcc_close_connection(int fd);
 
 int vcc_write_packages(int fd);
-int vcc_new_msg(int fd, char *msg);
+int vcc_new_msg(int fd, struct vcc_request *buf);
 
 
 #endif

+ 1 - 1
include/vcc/version.h

@@ -1 +1 @@
-#define VCCD_VERSION "vccd 0.1.4 Sat Mar  5 16:47:06 CST 2022 root"
+#define VCCD_VERSION "vccd 0.1.5 Sun Mar  6 08:00:25 CST 2022 root"

+ 1 - 1
main.c

@@ -146,7 +146,7 @@ static int init_socket(void) {
 int main(int argc, const char **argv) {
 	__uint32_t 	size;
 	int 		usr_fd, nfds_total, nfds_ready, i;
-	char 		*buf;
+	void 		*buf;
 
 	struct sockaddr_in usr_addr;
 

+ 7 - 5
vcc.c

@@ -176,20 +176,20 @@ int vcc_send_req(struct klist_node *node, void *p) {
 /* send to each user include who sends this message */
 
 int vcc_message_broadcast(char *msg) {
+	struct vcc_request *req;
 	struct klist_node *n;
 	int i;
-	char *buf;
 
 	for (n = connections.next, i = 0; n != &connections; n = n->next, i++) {
-		if (unlikely(!(buf = malloc(REQ_SIZE)))) {
+		if (unlikely(!(req = malloc(sizeof(struct vcc_request))))) {
 			vcc_log("*** malloc() failed\n");
 
 			continue;
 		}
 
-		strcpy(buf, msg);
+		strcpy(req->msg, msg);
 
-		vcc_send_req(n, buf);
+		vcc_send_req(n, req);
 	}
 
 	vcc_log("Message sent to %d users. \n", i);
@@ -198,7 +198,9 @@ int vcc_message_broadcast(char *msg) {
 }
 
 
-int vcc_new_msg(int fd, char *msg) {
+int vcc_new_msg(int fd, struct vcc_request *req) {
+	char *msg = req->msg;
+
 	if (((unsigned char *) msg)[0] == 0xffu || !*msg) 
 		return 0;