--- lbbs/src/bbs_net.c 2005/03/22 12:12:33 1.9 +++ lbbs/src/bbs_net.c 2005/05/07 12:08:28 1.13 @@ -152,15 +152,15 @@ bbsnet_connect (int n) char remote_addr[256]; int remote_port; time_t t_used; - struct tm * tm_used; + struct tm *tm_used; clearscr (); moveto (0, 0); prints ("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\r\n", - bbsnet_conf[n].host1, bbsnet_conf[n].ip); + bbsnet_conf[n].host1, bbsnet_conf[n].ip); prints ("\033[1;32m如果在 %d 秒内无法连上,穿梭程序将放弃连接。\033[m\r\n", - TIME_OUT); + TIME_OUT); iflush (); pHost = gethostbyname (bbsnet_conf[n].ip); @@ -192,7 +192,7 @@ bbsnet_connect (int n) inet_ntoa (sin.sin_addr), ntohs (sin.sin_port)); return -2; } - + bzero (&sin, sizeof (sin)); sin.sin_family = AF_INET; sin.sin_addr = *(struct in_addr *) pHost->h_addr_list[0]; @@ -236,8 +236,7 @@ bbsnet_connect (int n) setsockopt (sock, IPPROTO_IP, IP_TOS, &tos, sizeof (int)); prints ("\033[1;31m连接成功!\033[m\r\n"); - log_std ("BBSNET connect to %s:%d\n", - remote_addr, remote_port); + log_std ("BBSNET connect to %s:%d\n", remote_addr, remote_port); FD_ZERO (&inputs); FD_SET (0, &inputs); @@ -253,28 +252,29 @@ bbsnet_connect (int n) timeout.tv_sec = TIME_OUT; timeout.tv_usec = 0; - result = select (FD_SETSIZE, &testfds, (fd_set *) NULL, + result = SignalSafeSelect (FD_SETSIZE, &testfds, (fd_set *) NULL, (fd_set *) NULL, &timeout); - switch (result) + if (result == 0) { - case 0: if (time (0) - BBS_last_access_tm >= MAX_DELAY_TIME) { loop = 0; } - break; - case -1: - log_error ("select() error!\n"); - break; - default: + } + if (result < 0) + { + log_error ("select() error (%d) !\n", result); + loop = 0; + } + if (result > 0) + { if (FD_ISSET (0, &testfds)) { len = read (0, buf, 255); if (len == 0) { loop = 0; - break; } write (sock, buf, len); } @@ -284,11 +284,9 @@ bbsnet_connect (int n) if (len == 0) { loop = 0; - break; } write (1, buf, len); } - break; BBS_last_access_tm = time (0); } } @@ -302,7 +300,8 @@ bbsnet_connect (int n) tm_used = gmtime (&t_used); log_std ("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n", - tm_used->tm_mday - 1, tm_used->tm_hour, tm_used->tm_min, tm_used->tm_sec); + tm_used->tm_mday - 1, tm_used->tm_hour, tm_used->tm_min, + tm_used->tm_sec); return 0; } @@ -331,6 +330,7 @@ bbsnet_refresh () ("╰══════════════════════════════════════╯"); moveto (23, 0); prints (" [\x1b[1;32mCtrl+C\x1b[m]退出"); + iflush (); return 0;