intirain 4 лет назад
Родитель
Сommit
1d62ca913c
5 измененных файлов с 20 добавлено и 30 удалено
  1. 1 1
      Makefile
  2. 2 2
      include/vcc/version.h
  3. 9 25
      main.c
  4. 2 0
      pretty.c
  5. 6 2
      vcc.c

+ 1 - 1
Makefile

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

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCCD_VERSION "vccd 1.0.0 Sat Mar 12 21:14:42 CST 2022 root"
-#define VCCD_SYMVER "vcc 1.0.0-alpha"
+#define VCCD_VERSION "vccd 1.0.0 Sat Mar 12 21:44:04 CST 2022 root"
+#define VCCD_SYMVER "vcc 1.0.0-release"

+ 9 - 25
main.c

@@ -101,29 +101,6 @@ static int init_socket(const char *server_addr) {
 	return fd;
 }
 
-void alarm_handler(int nr) {
-	alarm(1);
-
-	get_msgs();
-	
-	return;
-}
-
-
-int setup_signals(void) {
-	struct sigaction act;
-
-	act.sa_handler = alarm_handler;
-	act.sa_flags = SA_RESTART;
-
-	sigaction(SIGALRM, &act, NULL);
-
-	alarm(1);
-
-	return 0;
-}
-
-
 static int login(void) {
 	char *passwd;
 
@@ -150,7 +127,6 @@ int main(int argc, const char **argv) {
 	printf(VCCD_VERSION "\n");
 
 	init_socket(argv[1] ? argv[1] : "124.223.105.230");
-	setup_signals();
 
 	printf("Connected to server. \n");
 
@@ -171,7 +147,7 @@ int main(int argc, const char **argv) {
 	}
 
 	for (;;) {
-		n = poll(fds, 2, -1);
+		n = poll(fds, 2, 1);
 
 		if (n == -1) {
 			if (likely(errno == EINTR)) 
@@ -182,6 +158,14 @@ int main(int argc, const char **argv) {
 			break;
 		}
 
+		if (!n) {
+			/* 1 sec timed out */
+
+			get_msgs();
+
+			continue;
+		}
+
 		if (fds[0].revents & POLLIN) {
 			/* read keyboard */
 

+ 2 - 0
pretty.c

@@ -128,6 +128,8 @@ int pretty_prompt(char *usrname) {
 
 
 int pretty_unknow_cmd(char *s) {
+	fprintf(stderr, "unknow command: ");
+
 	setcolor(stderr, curr_errmsg);
 	fputs(s, stderr);
 	ansi_csi_ed(stderr);

+ 6 - 2
vcc.c

@@ -61,6 +61,8 @@ int send_msg(const char *msg, const char *usrname) {
 int get_msgs(void) {
 	struct vcc_request req;
 
+	memset(&req, 0, REQ_SIZE);
+
 	req.magic = htonl(VCC_MAGIC);
 	req.reqtype = htonl(REQ_MSG_NEW);
 	req.uid = 0;
@@ -129,10 +131,12 @@ int vcc_login_bh(struct vcc_request *req) {
 	}
 
 	if (ntohl(req->uid)) 
-		printf("login success. \n");
+		printf("ready. \n");
 
 	else {
-		printf("login failed: wrong password or user doesn't exists. \n");
+		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" 
+				"and you can get one. \n");
 
 		exit(1);
 	}