Ver código fonte

vccd: great. a big bug fixed.

intirain 4 anos atrás
pai
commit
8cceec8044
6 arquivos alterados com 36 adições e 8 exclusões
  1. 2 2
      Makefile
  2. 4 0
      include/klist.h
  3. 1 1
      include/vcc/vccd.h
  4. 2 2
      include/vcc/version.h
  5. 1 1
      main.c
  6. 26 2
      vcc.c

+ 2 - 2
Makefile

@@ -1,7 +1,7 @@
 VCCD_MAJOR 		= 1
-VCCD_MINOR 		= 0
+VCCD_MINOR 		= 2
 VCCD_PATCH 		= 0
-VCCD_STR 		= -release
+VCCD_STR 		= -stable 
 
 VCCD_COMPILE_TIME 	= $(shell date)
 VCCD_COMPILE_BY 	= $(shell whoami)

+ 4 - 0
include/klist.h

@@ -30,6 +30,8 @@ struct klist_node {
 	void 			*data;
 	char 			*usrname;
 	struct klist_node 	*sending;
+	struct vcc_request 	*reading;
+	int 			size_did_read;
 
 	struct klist_node 	*next, *prev;
 };
@@ -50,6 +52,8 @@ void klist_del(struct klist_node *head, struct klist_node *will_del);
 	.data = NULL, \
 	.sending = NULL, \
 	.usrname = NULL, \
+	.reading = NULL, \
+	.size_did_read = 0, \
 	.next = __x, \
 	.prev = __x, \
 }

+ 1 - 1
include/vcc/vccd.h

@@ -35,7 +35,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, struct vcc_request *buf);
+int vcc_new_msg(int fd, void *buf, int size);
 int vcc_send_msg(struct klist_node *, void *);
 int vcc_message_broadcast(char *msg, char *usr, int except_fd);
 

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCCD_VERSION "vccd 1.0.0 Sun Mar 13 13:57:00 CST 2022 root"
-#define VCCD_SYMVER "vccd 1.0.0 Sun Mar 13 13:57:00 CST 2022 root"
+#define VCCD_VERSION "vccd 1.2.0 Sun Mar 13 14:25:22 CST 2022 root"
+#define VCCD_SYMVER "vccd 1.2.0 Sun Mar 13 14:25:22 CST 2022 root"

+ 1 - 1
main.c

@@ -221,7 +221,7 @@ int main(int argc, const char **argv) {
 
 				vcc_log("%d bytes i read. \n", size);
 
-				vcc_new_msg(fds[i].fd, buf);
+				vcc_new_msg(fds[i].fd, buf, size);
 
 				free(buf);
 

+ 26 - 2
vcc.c

@@ -252,8 +252,30 @@ int send_users(int fd) {
 }
 
 
-int vcc_new_msg(int fd, struct vcc_request *req) {
-	char *msg = req->msg;
+int vcc_new_msg(int fd, void *packet, int size) {
+	struct klist_node *n = find_connection(fd);
+	struct vcc_request *req;
+	char *msg;
+
+	if (unlikely(!n)) 
+		return 1;
+
+	if (!n->size_did_read) 
+		if (unlikely(!(n->reading = malloc(REQ_SIZE)))) {
+			vcc_log("*** malloc() failed. \n");
+
+			return 1;
+		}
+
+	memcpy(n->reading + n->size_did_read, packet, size);
+	n->size_did_read += size;
+
+	if (n->size_did_read + size < REQ_SIZE) 
+		return 0;
+
+	n->size_did_read = 0;
+	req = n->reading;
+	msg = req->msg;
 
 	if (unlikely(ntohl(req->magic) != VCC_MAGIC)) {
 		vcc_log("--- bad magic number from %d\n", fd);
@@ -294,6 +316,8 @@ int vcc_new_msg(int fd, struct vcc_request *req) {
 		break;
 	}
 
+	free(req);
+
 	return 0;
 }