/[LeafOK_CVS]/lbbs/src/bbs_net.c
ViewVC logotype

Diff of /lbbs/src/bbs_net.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.9 by sysadm, Tue Mar 22 12:12:33 2005 UTC Revision 1.12 by sysadm, Sat May 7 09:28:12 2005 UTC
# Line 152  bbsnet_connect (int n) Line 152  bbsnet_connect (int n)
152    char remote_addr[256];    char remote_addr[256];
153    int remote_port;    int remote_port;
154    time_t t_used;    time_t t_used;
155    struct tm * tm_used;    struct tm *tm_used;
156    
157    clearscr ();    clearscr ();
158    
159    moveto (0, 0);    moveto (0, 0);
160    prints ("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\r\n",    prints ("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\r\n",
161      bbsnet_conf[n].host1, bbsnet_conf[n].ip);            bbsnet_conf[n].host1, bbsnet_conf[n].ip);
162    prints ("\033[1;32m如果在 %d 秒内无法连上,穿梭程序将放弃连接。\033[m\r\n",    prints ("\033[1;32m如果在 %d 秒内无法连上,穿梭程序将放弃连接。\033[m\r\n",
163      TIME_OUT);            TIME_OUT);
164    iflush ();    iflush ();
165    
166    pHost = gethostbyname (bbsnet_conf[n].ip);    pHost = gethostbyname (bbsnet_conf[n].ip);
# Line 192  bbsnet_connect (int n) Line 192  bbsnet_connect (int n)
192                   inet_ntoa (sin.sin_addr), ntohs (sin.sin_port));                   inet_ntoa (sin.sin_addr), ntohs (sin.sin_port));
193        return -2;        return -2;
194      }      }
195      
196    bzero (&sin, sizeof (sin));    bzero (&sin, sizeof (sin));
197    sin.sin_family = AF_INET;    sin.sin_family = AF_INET;
198    sin.sin_addr = *(struct in_addr *) pHost->h_addr_list[0];    sin.sin_addr = *(struct in_addr *) pHost->h_addr_list[0];
# Line 236  bbsnet_connect (int n) Line 236  bbsnet_connect (int n)
236    setsockopt (sock, IPPROTO_IP, IP_TOS, &tos, sizeof (int));    setsockopt (sock, IPPROTO_IP, IP_TOS, &tos, sizeof (int));
237    
238    prints ("\033[1;31m连接成功!\033[m\r\n");    prints ("\033[1;31m连接成功!\033[m\r\n");
239    log_std ("BBSNET connect to %s:%d\n",    log_std ("BBSNET connect to %s:%d\n", remote_addr, remote_port);
     remote_addr, remote_port);  
240    
241    FD_ZERO (&inputs);    FD_ZERO (&inputs);
242    FD_SET (0, &inputs);    FD_SET (0, &inputs);
# Line 253  bbsnet_connect (int n) Line 252  bbsnet_connect (int n)
252        timeout.tv_sec = TIME_OUT;        timeout.tv_sec = TIME_OUT;
253        timeout.tv_usec = 0;        timeout.tv_usec = 0;
254    
255        result = select (FD_SETSIZE, &testfds, (fd_set *) NULL,        result = SignalSafeSelect (FD_SETSIZE, &testfds, (fd_set *) NULL,
256                         (fd_set *) NULL, &timeout);                         (fd_set *) NULL, &timeout);
257    
258        switch (result)        if (result == 0)
259          {          {
         case 0:  
260            if (time (0) - BBS_last_access_tm >= MAX_DELAY_TIME)            if (time (0) - BBS_last_access_tm >= MAX_DELAY_TIME)
261              {              {
262                loop = 0;                loop = 0;
263              }              }
264            break;          }
265          case -1:        if (result < 0)
266            {
267            log_error ("select() error!\n");            log_error ("select() error!\n");
268            break;            loop = 0;
269          default:          }
270          if (result > 0)
271            {
272            if (FD_ISSET (0, &testfds))            if (FD_ISSET (0, &testfds))
273              {              {
274                len = read (0, buf, 255);                len = read (0, buf, 255);
275                if (len == 0)                if (len == 0)
276                  {                  {
277                    loop = 0;                    loop = 0;
                   break;  
278                  }                  }
279                write (sock, buf, len);                write (sock, buf, len);
280              }              }
# Line 284  bbsnet_connect (int n) Line 284  bbsnet_connect (int n)
284                if (len == 0)                if (len == 0)
285                  {                  {
286                    loop = 0;                    loop = 0;
                   break;  
287                  }                  }
288                write (1, buf, len);                write (1, buf, len);
289              }              }
           break;  
290            BBS_last_access_tm = time (0);            BBS_last_access_tm = time (0);
291          }          }
292      }      }
# Line 302  bbsnet_connect (int n) Line 300  bbsnet_connect (int n)
300    tm_used = gmtime (&t_used);    tm_used = gmtime (&t_used);
301    
302    log_std ("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n",    log_std ("BBSNET disconnect, %d days %d hours %d minutes %d seconds used\n",
303      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,
304               tm_used->tm_sec);
305    
306    return 0;    return 0;
307  }  }
# Line 315  bbsnet_refresh () Line 314  bbsnet_refresh ()
314    clearscr ();    clearscr ();
315    moveto (1, 0);    moveto (1, 0);
316    prints    prints
317      ("╭══════════════════════════════════════╮");      ("?q?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?r");
318    for (i = 2; i < 19; i++)    for (i = 2; i < 19; i++)
319      {      {
320        moveto (i, 0);        moveto (i, 0);
321        prints ("║");        prints ("?U");
322        moveto (i, 79);        moveto (i, 79);
323        prints ("║");        prints ("?U");
324      }      }
325    moveto (19, 0);    moveto (19, 0);
326    prints    prints
327      ("║——————————————————————————————————————║");      ("?U——————————————————————————————————————?U");
328    moveto (22, 0);    moveto (22, 0);
329    prints    prints
330      ("╰══════════════════════════════════════╯");      ("?t?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?s");
331    moveto (23, 0);    moveto (23, 0);
332    prints (" [\x1b[1;32mCtrl+C\x1b[m]退出");    prints (" [\x1b[1;32mCtrl+C\x1b[m]退出");
333    iflush ();    iflush ();
# Line 341  bbsnet_selchange (int new_pos) Line 340  bbsnet_selchange (int new_pos)
340  {  {
341    moveto (20, 0);    moveto (20, 0);
342    clrtoeol ();    clrtoeol ();
343    prints ("║\x1b[1m单位:\x1b[1;33m%-18s\x1b[m  站名:\x1b[1;33m%s\x1b[m",    prints ("?U\x1b[1m单位:\x1b[1;33m%-18s\x1b[m  站名:\x1b[1;33m%s\x1b[m",
344            bbsnet_conf[new_pos].host2, bbsnet_conf[new_pos].host1);            bbsnet_conf[new_pos].host2, bbsnet_conf[new_pos].host1);
345    moveto (20, 79);    moveto (20, 79);
346    prints ("║");    prints ("?U");
347    moveto (21, 0);    moveto (21, 0);
348    clrtoeol ();    clrtoeol ();
349    prints ("║\x1b[1m连往:\x1b[1;33m%-20s", bbsnet_conf[new_pos].ip);    prints ("?U\x1b[1m连往:\x1b[1;33m%-20s", bbsnet_conf[new_pos].ip);
350    if (bbsnet_conf[new_pos].port != 23)    if (bbsnet_conf[new_pos].port != 23)
351      prints ("  %d", bbsnet_conf[new_pos].port);      prints ("  %d", bbsnet_conf[new_pos].port);
352    prints ("\x1b[m");    prints ("\x1b[m");
353    moveto (21, 79);    moveto (21, 79);
354    prints ("║");    prints ("?U");
355    iflush ();    iflush ();
356    
357    return 0;    return 0;


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1