Browse Source

vccd: now use relay to -ls

intirain 4 năm trước cách đây
mục cha
commit
b29b340e8f
5 tập tin đã thay đổi với 39 bổ sung và 30 xóa
  1. 2 2
      Makefile
  2. 1 0
      include/vcc/vccd.h
  3. 2 2
      include/vcc/version.h
  4. 17 8
      relay.c
  5. 17 18
      vcc.c

+ 2 - 2
Makefile

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

+ 1 - 0
include/vcc/vccd.h

@@ -81,6 +81,7 @@ int relay_broadcast(const char *restrict msg, int expect,
 		const struct vcc_relay_header *restrict hdr);
 int relay_send_to(const char *restrict msg, const char *restrict visible, int expect_fd, 
 		const struct vcc_relay_header *restrict hdr);
+int relay_send_packet(int fd, const char *restrict msg, const struct vcc_relay_header *restrict hdr, int size);
 int read_until(int fd, void *, int);
 
 struct klist_node *find_connection(int fd);

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCCD_VERSION "vccd 1.12.1 Thu Jun  2 09:13:58 PM CST 2022 root"
-#define VCCD_SEMVER "vccd 1.12.1-rc "
+#define VCCD_VERSION "vccd 1.13.0 Fri Jun  3 05:10:49 PM CST 2022 root"
+#define VCCD_SEMVER "vccd 1.13.0-rc "

+ 17 - 8
relay.c

@@ -69,6 +69,20 @@ int relay_new_msg(int fd, void *t) {
 }
 
 
+int relay_send_packet(int fd, const char *restrict buf, 
+		const struct vcc_relay_header *restrict hdr, int size) {
+	struct vcc_relay_header req;
+
+	memcpy(&req, hdr, sizeof(struct vcc_relay_header));
+	req.size = htonl(sizeof(struct vcc_relay_header) + size);
+
+	write(fd, &req, sizeof(struct vcc_relay_header));
+	write(fd, buf, size);
+
+	return 0;
+}
+
+
 int send_to(int fd, const char *restrict msg, int is_only_visible, 
 		const struct vcc_relay_header *restrict hdr, int size) {
 	struct vcc_relay_header req;
@@ -79,16 +93,9 @@ int send_to(int fd, const char *restrict msg, int is_only_visible,
 	req.reqtype = htonl(REQ_REL_NEW);
 	req.uid = htonl(is_only_visible);
 	req.session = 0;
-	req.size = htonl(sizeof(struct vcc_relay_header) + size);
 
 	strncpy(req.usrname, hdr->usrname, USRNAME_SIZE);
-
-	/* direct writes here 
-	 * vcc_send_req(n, req); 
-	 * */
-
-	write(fd, &req, sizeof(struct vcc_relay_header));
-	write(fd, msg, size);
+	relay_send_packet(fd, msg, &req, size);
 
 	return 0;
 }
@@ -98,6 +105,8 @@ int relay_send_to(const char *restrict msg, const char *restrict visible, int ex
 	struct klist_node 		*n;
 	struct user 			*u;
 
+	vcc_write_all();
+
 	for (n = logged_users.next; n != &logged_users; n = n->next) {
 		u = n->data;
 

+ 17 - 18
vcc.c

@@ -229,35 +229,34 @@ int vcc_update_usrname(int fd, const char *usrname) {
 
 
 int send_users(int fd) {
-	struct vcc_request *req;
-	struct klist_node *n;
-	int i;
+	struct vcc_relay_header 	req;
+	struct klist_node 		*n;
+	int 				i, size;
+	char 				*buf;
+
+	size = USRNAME_SIZE * nusers;
 
-	if (unlikely(!(req = amalloc(sizeof(struct vcc_request))))) {
+	if (unlikely(!(buf = amalloc(size)))) {
 		vcc_log("*** malloc() failed\n");
+		vcc_log("*** %d users, %d bytes. ", nusers, size);
 
 		return 1;
 	}
 
-	memset(req, 0, REQ_SIZE);
+	vcc_log("%d users online. \n", nusers);
 
-	req->magic = htonl(VCC_MAGIC);
-	req->reqtype = htonl(REQ_CTL_USRS);
+	req.magic = htonl(VCC_MAGIC_RL);
+	req.reqtype = htonl(REQ_CTL_USRS);
+	req.session = 0;
 
-	for (n = connections.next, i = 0; n != &connections; n = n->next, i++) {
-		strncpy(req->msg + i * USRNAME_SIZE, n->usrname ? n->usrname : "unnamed", USRNAME_SIZE);
-
-		if (unlikely(i >= (int) MSG_SIZE / USRNAME_SIZE)) {
-			vcc_log("--- too many users\n");
-
-			break;
-		}
-	}
+	for (n = connections.next, i = 0; n != &connections; n = n->next, i++) 
+		strncpy(buf + i * USRNAME_SIZE, n->usrname ? n->usrname : "unnamed", USRNAME_SIZE);
 
-	req->uid = htonl(i);
+	req.uid = htonl(i);
+	relay_send_packet(fd, buf, &req, size);
 
-	vcc_send_req(find_connection(fd), req);
 	vcc_log("%d user names sent to %d\n", i, fd);
+	afree(buf, size);
 
 	return 0;
 }