intirain 4 жил өмнө
parent
commit
d7504895e8
5 өөрчлөгдсөн 16 нэмэгдсэн , 21 устгасан
  1. 1 1
      Makefile
  2. 1 1
      include/vcc/vcc.h
  3. 2 2
      include/vcc/version.h
  4. 10 15
      main.c
  5. 2 2
      vcc.c

+ 1 - 1
Makefile

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

+ 1 - 1
include/vcc/vcc.h

@@ -41,7 +41,7 @@
  * server -> client. login ack  */
 #define REQ_CTL_LOGIN 	4
 
-#define REQ_SIZE 	1024
+#define REQ_SIZE 	512
 #define USRNAME_SIZE 	32
 #define MSG_SIZE 	(REQ_SIZE - 3 * sizeof(int) - USRNAME_SIZE)
 

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCCD_VERSION "vccd 1.1.0 Mon Mar 14 07:44:31 CST 2022 root"
-#define VCCD_SYMVER "vcc 1.1.0-beta "
+#define VCCD_VERSION "vccd 1.1.1 Sat Mar 19 20:23:53 CST 2022 root"
+#define VCCD_SYMVER "vcc 1.1.1-beta "

+ 10 - 15
main.c

@@ -54,8 +54,6 @@ int fd;
 int rate;
 
 char usrname[USRNAME_SIZE];
-static char *reading;
-static int size_read;
 
 static int usage(void) {
 	fprintf(stderr, "Usage: vcc [server]\n");
@@ -124,7 +122,7 @@ static int login(void) {
 int main(int argc, const char **argv) {
 	struct pollfd 		fds[2];
 	struct vcc_request 	*req;
-	char 			*buf;
+	char 			*buf, *msg;
 	int 			n, size;
 
 	if (unlikely(argc != 1 && argc != 2)) 
@@ -154,14 +152,12 @@ int main(int argc, const char **argv) {
 		return 1;
 	}
 
-	if (unlikely(!(reading = malloc(REQ_SIZE)))) {
+	if (unlikely(!(req = malloc(REQ_SIZE)))) {
 		fprintf(stderr, "*** malloc() failed\n");
 
 		return 1;
 	}
 
-	size_read = 0;
-
 	for (;;) {
 		n = poll(fds, 2, rate);
 
@@ -206,14 +202,13 @@ int main(int argc, const char **argv) {
 		}
 
 		if (fds[1].revents & POLLIN) {
-			size = read(fd, reading + size_read, REQ_SIZE);
-			size_read += size;
+			size = read(fd, req, REQ_SIZE);
 
-			if (size_read < REQ_SIZE) 
-				continue;
+			if (unlikely(!size)) {
+				fprintf(stderr, "Server closed. \n");
 
-			size_read = 0;
-			req = (struct vcc_request *) reading;
+				break;
+			}
 
 			if (ntohl(req->reqtype) != REQ_MSG_NEW) {
 				do_bh(req);
@@ -221,12 +216,12 @@ int main(int argc, const char **argv) {
 				continue;
 			}
 
-			buf = req->msg;
+			msg = req->msg;
 
-			if (!*buf || *(unsigned char *) buf == 0xffu) 
+			if (!*msg || *(unsigned char *) msg == 0xffu) 
 				continue;
 
-			pretty_new_msg(req->usrname, buf);
+			pretty_new_msg(req->usrname, msg);
 			pretty_prompt(usrname);
 		}
 	}

+ 2 - 2
vcc.c

@@ -105,7 +105,7 @@ int do_bh(struct vcc_request *req) {
 		break;
 
 	default:
-		fprintf(stderr, "*** unexpected packet. \n");
+		fprintf(stderr, "*** unexpected packet type %d. \n", ntohl(req->reqtype));
 
 		break;
 	}
@@ -141,7 +141,7 @@ int vcc_login_bh(struct vcc_request *req) {
 
 	else {
 		fprintf(stderr, "login failed: wrong password or user doesn't exists. \n");
-		fprintf(stderr, "if you haven't got an account on this server, ask the administrator" 
+		fprintf(stderr, "if you haven't got an account on this server, ask the administrator " 
 				"and you can get one. \n");
 
 		exit(1);