Explorar el Código

vccd: now we're using direct-write() instead of POLLOUT

intirain hace 4 años
padre
commit
e95435195f
Se han modificado 5 ficheros con 29 adiciones y 12 borrados
  1. 2 2
      Makefile
  2. 1 0
      include/vcc/vccd.h
  3. 2 2
      include/vcc/version.h
  4. 1 0
      session.c
  5. 23 8
      vcc.c

+ 2 - 2
Makefile

@@ -1,6 +1,6 @@
 VCCD_MAJOR 		= 1
-VCCD_MINOR 		= 8
-VCCD_PATCH 		= 1
+VCCD_MINOR 		= 9
+VCCD_PATCH 		= 0
 VCCD_STR 		= -rc 
 
 VCCD_COMPILE_TIME 	= $(shell date)

+ 1 - 0
include/vcc/vccd.h

@@ -40,6 +40,7 @@ int amalloc_report(char *s);
 int vcc_new_connection(int fd, struct in_addr *addr);
 int vcc_close_connection(int fd);
 
+int vcc_write_all(void);
 int vcc_write_packages(int fd);
 int vcc_new_msg(int fd, struct vcc_request *buf);
 int vcc_send_req(struct klist_node *, void *);

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCCD_VERSION "vccd 1.8.1 Sat Apr 16 21:37:32 CST 2022 root"
-#define VCCD_SEMVER "vccd 1.8.1-rc "
+#define VCCD_VERSION "vccd 1.9.0 Sun May  1 12:36:32 CST 2022 root"
+#define VCCD_SEMVER "vccd 1.9.0-rc "

+ 1 - 0
session.c

@@ -193,6 +193,7 @@ int session_broadcast(int sid, char *msg, char *usrname, int except, int flags)
 		i++;
 	}
 
+	vcc_write_all();
 	vcc_log("(%d) Message sent to %d users. \n", sid, i);
 
 	return 0;

+ 23 - 8
vcc.c

@@ -64,7 +64,7 @@ int vcc_new_connection(int fd, struct in_addr *addr) {
 		return 1;
 	}
 
-	klist_init(n->sending);	
+	klist_init(n->sending);
 	klist_add(&connections, n);
 
 	/* if we kill vcc before it logs in, the nusers will dec but it 
@@ -117,21 +117,22 @@ struct klist_node *find_connection(int fd) {
 
 
 int write_packages(struct klist_node *node) {
-	void *p;
+	struct klist_node *n;
 
 	if (unlikely(!node->sending)) 
 		return 0;
 
 	if (unlikely(klist_empty(node->sending))) 
 		return 0;
-	
-	p = node->sending->next->data;
 
-	write(node->value, p, REQ_SIZE);
-	afree(p, REQ_SIZE);
-
-	klist_del(node->sending, node->sending->next);
+	for (n = node->sending->next; n != node->sending; n = n->next) {
+		write(node->value, n->data, REQ_SIZE);
+		klist_del(node->sending, n);
 
+		afree(n->data, REQ_SIZE);
+		afree(n, sizeof(struct klist_node));
+	}
+	
 	return 0;
 }
 
@@ -139,6 +140,15 @@ int vcc_write_packages(int fd) {
 	return write_packages(find_connection(fd));
 }
 
+int vcc_write_all(void) {
+	struct klist_node *n;
+
+	for (n = connections.next; n != &connections; n = n->next) 
+		vcc_write_packages(n->value);
+	
+	return 0;
+}
+
 
 int vcc_send_req(struct klist_node *node, void *p) {
 	struct klist_node *n;
@@ -149,6 +159,8 @@ int vcc_send_req(struct klist_node *node, void *p) {
 		return 1;
 	}
 
+	klist_init(n);
+
 	n->data = p;
 	klist_add(node->sending, n);
 
@@ -193,6 +205,7 @@ int vcc_message_broadcast(char *msg, char *usrname, int except_fd, int flags) {
 		i++;
 	}
 
+	vcc_write_all();
 	vcc_log("Message sent to %d users. \n", i);
 
 	return 0;
@@ -331,6 +344,8 @@ int vcc_new_msg(int fd, struct vcc_request *req) {
 		break;
 	}
 
+	vcc_write_packages(fd);
+
 	return 0;
 }