From 46f0b52197574d76f7f0d852dfd6df208db0980b Mon Sep 17 00:00:00 2001 From: piaip Date: Fri, 8 Apr 2005 16:12:35 +0000 Subject: a patch to fix bug caused by changes of igetch()'s behavior which was introduced in r2690. (cpu freaks out on chatroom/chess [I_OTHERDATA]) git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2692 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/io.c | 7 +++++-- mbbsd/mbbsd.c | 26 +++++++++++++++++--------- 2 files changed, 22 insertions(+), 11 deletions(-) (limited to 'mbbsd') diff --git a/mbbsd/io.c b/mbbsd/io.c index b2ffd476..9ff8b04d 100644 --- a/mbbsd/io.c +++ b/mbbsd/io.c @@ -125,7 +125,7 @@ num_in_buf(void) * be inconsistent. We try to not segfault here... */ - static int +static int dogetch(void) { ssize_t len; @@ -221,11 +221,13 @@ dogetch(void) } static int water_which_flag = 0; + int igetch(void) { register int ch, mode = 0, last = 0; - while ((ch = dogetch()) >= 0) { + while (1) { + ch = dogetch(); if (mode == 0 && ch == KEY_ESC) // here is state machine for 2 bytes key mode = 1; @@ -435,6 +437,7 @@ igetch(void) return ch; } } + // should not reach here. just to make compiler happy. return 0; } diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 6fdba9f8..14d52237 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -1585,7 +1585,6 @@ telnet_init(void) IAC, SB, TELOPT_TTYPE, TELQUAL_SEND, IAC, SE, /* i'm a smart term with resize ability. */ - IAC, WILL, TELOPT_NAWS, IAC, DO, TELOPT_NAWS, /* i will echo. */ @@ -1728,17 +1727,26 @@ telnet_handler(unsigned char c) * However because we have a poor term which does not allow * most abilities, let's be a strong boss here. * - * If client says 'DONT' or DO, - * ignore because we can't really do/don't that. + * Although my imeplementation works, it's even better to follow this: + * http://www.tcpipguide.com/free/t_TelnetOptionsandOptionNegotiation-3.htm */ + +#ifdef DEBUG + switch(iac_opt_req) { + case WILL: write(0, "WILL ", 5); break; + case WONT: write(0, "WONT ", 5); break; + case DO: write(0, "DO ", 5); break; + case DONT: write(0, "DONT ", 5); break; + } +#endif switch(c) { case TELOPT_ECHO: /* echo */ case TELOPT_RCP: /* prepare to reconnect */ case TELOPT_SGA: /* suppress go ahead */ - if(iac_opt_req == WONT) { + if(iac_opt_req == WILL || iac_opt_req == DO) { /* we need these options, whether you want or not */ - unsigned char cmd[3] = { IAC, 0, 0 }; - cmd[1] = WILL; + unsigned char cmd[3] = { IAC, DO, 0 }; + if(iac_opt_req == DO) cmd[1] = WILL; cmd[2] = c; write(0, cmd, sizeof(cmd)); } @@ -1750,11 +1758,11 @@ telnet_handler(unsigned char c) break; default: - if (iac_opt_req == WILL) + if (iac_opt_req == WILL || iac_opt_req == DO) { /* unknown option, reply with won't */ - unsigned char cmd[3] = { IAC, 0, 0 }; - cmd[1] = WONT; + unsigned char cmd[3] = { IAC, DONT, 0 }; + if(iac_opt_req == DO) cmd[1] = WONT; cmd[2] = c; write(0, cmd, sizeof(cmd)); } -- cgit v1.2.3