From f6d25b8861f97439d7086e4569e209c46486d009 Mon Sep 17 00:00:00 2001 From: Fritz Elfert Date: Sun, 14 Jan 2001 22:28:37 +0000 Subject: - Added Hint for man pages in README. - Added signal handles for SIGINT and SIGTERM in ncpd for - properly shutting down the link. - Added flush() method in link.cc, needed for above feature. - If started with option -e and no -s option is given, assume being started by mgetty and use the line ncpd is started on instead of builtin default. - Added auto-reset in packet.cc. This helps making IrDA (ircomm-tty) based connections. Still not satisfying as i sometimes have to toggle infrared on the Psion (probably a bug in the Psion's IrDA). --- ncpd/packet.cc | 71 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 15 deletions(-) (limited to 'ncpd/packet.cc') diff --git a/ncpd/packet.cc b/ncpd/packet.cc index 2aa0509..5c05849 100644 --- a/ncpd/packet.cc +++ b/ncpd/packet.cc @@ -56,24 +56,42 @@ iow(_iow) inLen = outLen = termLen = 0; foundSync = 0; esc = false; + lastFatal = false; + serialStatus = -1; crcIn = crcOut = 0; fd = init_serial(devname, baud, 0); - iow.addIO(fd); + if (fd == -1) + lastFatal = true; + else + iow.addIO(fd); } void packet::reset() { - iow.remIO(fd); - ser_exit(fd); + if (verbose & PKT_DEBUG_LOG) + cout << "resetting serial connection" << endl; + if (fd != -1) { + iow.remIO(fd); + ser_exit(fd); + } usleep(100000); inLen = outLen = termLen = 0; + inPtr = inBuffer; + outPtr = outBuffer; foundSync = 0; + serialStatus = -1; esc = false; crcIn = crcOut = 0; fd = init_serial(devname, baud, 0); - iow.addIO(fd); + if (fd != -1) { + iow.addIO(fd); + lastFatal = false; + } + if (verbose & PKT_DEBUG_LOG) + cout << "serial connection reset, fd=" << fd << endl; + sleep(1); } short int packet:: @@ -90,8 +108,10 @@ setVerbose(short int _verbose) packet::~packet() { - iow.remIO(fd); - ser_exit(fd); + if (fd != -1) { + iow.remIO(fd); + ser_exit(fd); + } usleep(100000); delete[]inBuffer; delete[]outBuffer; @@ -287,24 +307,45 @@ bool packet:: linkFailed() { int arg; + int res; bool failed = false; - int res = ioctl(fd, TIOCMGET, &arg); + + if (lastFatal) + reset(); + res = ioctl(fd, TIOCMGET, &arg); if (res < 0) - failed = true; - if (verbose & PKT_DEBUG_HANDSHAKE) - cout << "packet: DTR:" << ((arg & TIOCM_DTR)?1:0) - << " RTS:" << ((arg & TIOCM_RTS)?1:0) - << " DCD:" << ((arg & TIOCM_CAR)?1:0) - << " DSR:" << ((arg & TIOCM_DSR)?1:0) - << " CTS:" << ((arg & TIOCM_CTS)?1:0) << endl; + lastFatal = true; + if ((serialStatus == -1) || (arg != serialStatus)) { + if (verbose & PKT_DEBUG_HANDSHAKE) + cout << "packet: < DTR:" << ((arg & TIOCM_DTR)?1:0) + << " RTS:" << ((arg & TIOCM_RTS)?1:0) + << " DCD:" << ((arg & TIOCM_CAR)?1:0) + << " DSR:" << ((arg & TIOCM_DSR)?1:0) + << " CTS:" << ((arg & TIOCM_CTS)?1:0) << endl; + if (!((arg & TIOCM_RTS) && (arg & TIOCM_DTR))) { + arg |= (TIOCM_DTR | TIOCM_RTS); + res = ioctl(fd, TIOCMSET, &arg); + if (res < 0) + lastFatal = true; + if (verbose & PKT_DEBUG_HANDSHAKE) + cout << "packet: > DTR:" << ((arg & TIOCM_DTR)?1:0) + << " RTS:" << ((arg & TIOCM_RTS)?1:0) + << " DCD:" << ((arg & TIOCM_CAR)?1:0) + << " DSR:" << ((arg & TIOCM_DSR)?1:0) + << " CTS:" << ((arg & TIOCM_CTS)?1:0) << endl; + } + serialStatus = arg; + } #ifdef sun if ((arg & TIOCM_CTS) == 0) #else if (((arg & TIOCM_DSR) == 0) || ((arg & TIOCM_CTS) == 0)) #endif failed = true; + if ((verbose & PKT_DEBUG_LOG) && lastFatal) + cout << "packet: linkFATAL\n"; if ((verbose & PKT_DEBUG_LOG) && failed) cout << "packet: linkFAILED\n"; - return failed; + return lastFatal || failed; } -- cgit v1.2.3