From fbb74de9b70fbcb8b8d4f21bd9846a127b5371e8 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Thu, 8 Nov 2012 15:45:43 -0800 Subject: [PATCH] TMXR fixes to support Virtual Null Modem Connections sim_tmxr.c sim_defs.h - Fixed parsing issues with NOTELNET option. - Fixed line closing logic to drop buffered contents when line errors occur before closing link. - Fixed logic to allow bidirectional line connections (i.e. listen=1234;connect=ip:2345 on both sides of a a virtual null modem). --- sim_defs.h | 2 +- sim_tmxr.c | 48 ++++++++++++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/sim_defs.h b/sim_defs.h index 8aa2d94c..12bf64af 100644 --- a/sim_defs.h +++ b/sim_defs.h @@ -277,7 +277,7 @@ typedef uint32 t_addr; /* String match - at least one character required */ -#define MATCH_CMD(ptr,cmd) (*(ptr) && strncmp ((ptr), (cmd), strlen (ptr))) +#define MATCH_CMD(ptr,cmd) ((!*(ptr)) || strncmp ((ptr), (cmd), strlen (ptr))) /* End of Linked List/Queue value */ /* Chosen for 2 reasons: */ diff --git a/sim_tmxr.c b/sim_tmxr.c index 7da4b16a..97298f95 100644 --- a/sim_tmxr.c +++ b/sim_tmxr.c @@ -708,11 +708,11 @@ static char mantra[] = { TN_IAC, TN_DO, TN_BIN }; -tmxr_debug_trace (mp, "tmxr_poll_conn()"); - if ((poll_time - mp->last_poll_time) < TMXR_CONNECT_POLL_INTERVAL) return -1; /* */ +tmxr_debug_trace (mp, "tmxr_poll_conn()"); + mp->last_poll_time = poll_time; /* Check for a pending Telnet connection */ @@ -765,21 +765,18 @@ if (newsock != INVALID_SOCKET) { /* got a live one? */ for (i = 0; i < mp->lines; i++) { /* check each line in sequence */ lp = mp->ldsc + i; /* get pointer to line descriptor */ - if (0 == lp->master) { /* not listening? */ - if (lp->connecting) { /* connecting? */ - switch (sim_check_conn(lp->connecting, FALSE)) - { - case 1: /* successful connection */ - lp->conn = lp->connecting; /* it now looks normal */ - lp->connecting = 0; - lp->cnms = sim_os_msec (); - break; - case -1: /* failed connection */ - tmxr_reset_ln (lp); /* retry */ - break; - } + if (lp->connecting) { /* connecting? */ + switch (sim_check_conn(lp->connecting, FALSE)) + { + case 1: /* successful connection */ + lp->conn = lp->connecting; /* it now looks normal */ + lp->connecting = 0; + lp->cnms = sim_os_msec (); + break; + case -1: /* failed connection */ + tmxr_reset_ln (lp); /* retry */ + break; } - continue; /* skip this line */ } /* Check for a pending Telnet connection */ @@ -803,6 +800,10 @@ for (i = 0; i < mp->lines; i++) { /* check each line in se free (address); continue; /* Move on to next line */ } + if (lp->connecting) { + sim_close_sock (lp->connecting, 0); /* abort our as yet unconnnected socket */ + lp->connecting = 0; + } } if (lp->conn == 0) { /* is the line available? */ tmxr_init_line (lp); /* init line */ @@ -1089,8 +1090,10 @@ for (i = 0; i < mp->lines; i++) { /* loop thru lines */ nbytes = tmxr_read (lp, /* yes, read to end */ TMXR_MAXBUF - lp->rxbpi); - if (nbytes < 0) /* line error? */ + if (nbytes < 0) { /* line error? */ + lp->txbpi = lp->txbpr = 0; /* Drop the data we already know we can't send */ tmxr_close_ln (lp); /* disconnect line */ + } else if (nbytes > 0) { /* if data rcvd */ @@ -1316,6 +1319,7 @@ if (nbytes) { /* >0? write */ nbytes = nbytes - sbytes; } if (sbytes < 0) { /* I/O Error? */ + lp->txbpi = lp->txbpr = 0; /* Drop the data we already know we can't send */ tmxr_close_ln (lp); /* close line/port on error */ return nbytes; /* done now. */ } @@ -1445,7 +1449,9 @@ while (*tptr) { sim_close_sock (sock, 0); else return SCPE_ARG; - if (cptr && (0 == MATCH_CMD (cptr, "NOTELNET"))) + if (cptr) + get_glyph (cptr, cptr, 0); /* upcase this string */ + if (0 == MATCH_CMD (cptr, "NOTELNET")) notelnet = TRUE; cptr = hostport; } @@ -1455,7 +1461,9 @@ while (*tptr) { cptr = get_glyph (gbuf, port, ';'); if (SCPE_OK != sim_parse_addr (port, NULL, 0, NULL, NULL, 0, NULL)) return SCPE_ARG; - if (cptr && (0 == MATCH_CMD (cptr, "NOTELNET"))) + if (cptr) + get_glyph (cptr, cptr, 0); /* upcase this string */ + if (0 == MATCH_CMD (cptr, "NOTELNET")) listennotelnet = TRUE; cptr = init_cptr; } @@ -1468,7 +1476,7 @@ while (*tptr) { sim_close_sock (sock, 1); strcpy(listen, port); cptr = get_glyph (cptr, option, ';'); - if (option[0] && (0 == MATCH_CMD (option, "NOTELNET"))) + if (0 == MATCH_CMD (option, "NOTELNET")) listennotelnet = TRUE; } if (line == -1) {