From 1e2cead07bb1e106fecace944765ec33cd351dcb Mon Sep 17 00:00:00 2001 From: Fritz Elfert Date: Thu, 14 Feb 2002 06:22:08 +0000 Subject: - Bugfix: ncpd sucked up lot of CPU when Psion disconnects. (finally found that!!) - Unified Headers - close stdin, stdout and stderr when in daemon mode. --- ncpd/link.cc | 2 +- ncpd/link.h | 53 ++++++++++++++++++++++------------------ ncpd/main.cc | 54 ++++++++++++++++++++++------------------ ncpd/mp_serial.h | 29 +++++++++++++++++++++- ncpd/packet.cc | 73 ++++++++++++++++++++++++++++++------------------------- ncpd/packet.h | 53 ++++++++++++++++++++++------------------ ncpd/socketchan.h | 53 ++++++++++++++++++++++------------------ 7 files changed, 186 insertions(+), 131 deletions(-) (limited to 'ncpd') diff --git a/ncpd/link.cc b/ncpd/link.cc index 6811d10..6e3be36 100644 --- a/ncpd/link.cc +++ b/ncpd/link.cc @@ -293,7 +293,7 @@ flush() { bool link:: stuffToSend() { - return (somethingToSend || !sendQueue.empty()); + return (!failed && (somethingToSend || !sendQueue.empty())); } bool link:: diff --git a/ncpd/link.h b/ncpd/link.h index f8a7d73..b6700e9 100644 --- a/ncpd/link.h +++ b/ncpd/link.h @@ -1,27 +1,26 @@ -// $Id$ -// -// PLP - An implementation of the PSION link protocol -// -// Copyright (C) 1999 Philip Proudman -// Modifications for plptools: -// Copyright (C) 1999 Fritz Elfert -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// e-mail philip.proudman@btinternet.com - +/*-*-c++-*- + * $Id$ + * + * This file is part of plptools. + * + * Copyright (C) 1999 Philip Proudman + * Copyright (C) 1999-2001 Fritz Elfert + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ #ifndef _link_h_ #define _link_h_ @@ -69,3 +68,9 @@ class link { }; #endif + +/* + * Local variables: + * c-basic-offset: 4 + * End: + */ diff --git a/ncpd/main.cc b/ncpd/main.cc index 8c4de20..50931c6 100644 --- a/ncpd/main.cc +++ b/ncpd/main.cc @@ -1,27 +1,26 @@ -// $Id$ -// -// PLP - An implementation of the PSION link protocol -// -// Copyright (C) 1999 Philip Proudman -// Modifications for plptools: -// Copyright (C) 1999 Fritz Elfert -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// e-mail philip.proudman@btinternet.com - +/*-*-c++-*- + * $Id$ + * + * This file is part of plptools. + * + * Copyright (C) 1999 Philip Proudman + * Copyright (C) 1999-2001 Fritz Elfert + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -209,6 +208,7 @@ main(int argc, char **argv) syslog(LOG_INFO, "daemon started. Listening at 127.0.0.1:%d, using device %s\n", sockNum, serialDevice); + close(0); close(1); close(2); } ncp *a = new ncp(serialDevice, baudRate, iow); int numScp = 0; @@ -251,3 +251,9 @@ main(int argc, char **argv) exit(0); } } + +/* + * Local variables: + * c-basic-offset: 4 + * End: + */ diff --git a/ncpd/mp_serial.h b/ncpd/mp_serial.h index 0bef3e5..da559e4 100644 --- a/ncpd/mp_serial.h +++ b/ncpd/mp_serial.h @@ -1,4 +1,25 @@ -/* $Id$ +/*-*-c++-*- + * $Id$ + * + * This file is part of plptools. + * + * Copyright (C) 1999 Philip Proudman + * Copyright (C) 1999-2001 Fritz Elfert + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * */ #ifndef _mp_serial_h #define _mp_serial_h @@ -7,3 +28,9 @@ int init_serial(const char *dev, int speed, int debug); void ser_exit(int fd); #endif + +/* + * Local variables: + * c-basic-offset: 4 + * End: + */ diff --git a/ncpd/packet.cc b/ncpd/packet.cc index 1b4daad..81b8894 100644 --- a/ncpd/packet.cc +++ b/ncpd/packet.cc @@ -1,28 +1,26 @@ -// $Id$ -// -// PLP - An implementation of the PSION link protocol -// -// Copyright (C) 1999 Philip Proudman -// Modifications for plptools: -// Copyright (C) 1999 Fritz Elfert -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// e-mail philip.proudman@btinternet.com - - +/*-*-c++-*- + * $Id$ + * + * This file is part of plptools. + * + * Copyright (C) 1999 Philip Proudman + * Copyright (C) 1999-2001 Fritz Elfert + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ #ifdef HAVE_CONFIG_H #include #endif @@ -83,10 +81,10 @@ void packet::reset() inPtr = inBuffer; outPtr = outBuffer; foundSync = 0; - serialStatus = -1; esc = false; + lastFatal = false; + serialStatus = -1; crcIn = crcOut = 0; - fd = init_serial(devname, baud, 0); if (fd != -1) { iow.addIO(fd); @@ -273,7 +271,7 @@ terminated() } if (!foundSync) return false; - + if (verbose & PKT_DEBUG_LOG) { if (foundSync != 3) cout << "packet: terminated found sync at " << foundSync << endl; @@ -339,12 +337,16 @@ linkFailed() } serialStatus = arg; } -#ifdef sun - if ((arg & TIOCM_CTS) == 0) -#else - if (((arg & TIOCM_DSR) == 0) || ((arg & TIOCM_CTS) == 0)) + if (((arg & TIOCM_CTS) == 0) +#ifndef sun + || ((arg & TIOCM_DSR) == 0) #endif - failed = true; + ) { + // eat possible junk on line + while (read(fd, &res, sizeof(res)) > 0) + ; + failed = true; + } if ((verbose & PKT_DEBUG_LOG) && lastFatal) cout << "packet: linkFATAL\n"; if ((verbose & PKT_DEBUG_LOG) && failed) @@ -352,3 +354,8 @@ linkFailed() return lastFatal || failed; } +/* + * Local variables: + * c-basic-offset: 4 + * End: + */ diff --git a/ncpd/packet.h b/ncpd/packet.h index afab41d..a21412e 100644 --- a/ncpd/packet.h +++ b/ncpd/packet.h @@ -1,27 +1,26 @@ -// $Id$ -// -// PLP - An implementation of the PSION link protocol -// -// Copyright (C) 1999 Philip Proudman -// Modifications for plptools: -// Copyright (C) 1999 Fritz Elfert -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// e-mail philip.proudman@btinternet.com - +/*-*-c++-*- + * $Id$ + * + * This file is part of plptools. + * + * Copyright (C) 1999 Philip Proudman + * Copyright (C) 1999-2001 Fritz Elfert + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ #ifndef _packet_h #define _packet_h @@ -77,3 +76,9 @@ class packet { }; #endif + +/* + * Local variables: + * c-basic-offset: 4 + * End: + */ diff --git a/ncpd/socketchan.h b/ncpd/socketchan.h index a3c53d3..1c6b1f1 100644 --- a/ncpd/socketchan.h +++ b/ncpd/socketchan.h @@ -1,27 +1,26 @@ -// $Id$ -// -// PLP - An implementation of the PSION link protocol -// -// Copyright (C) 1999 Philip Proudman -// Modifications for plptools: -// Copyright (C) 1999 Fritz Elfert -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// e-mail philip.proudman@btinternet.com - +/*-*-c++-*- + * $Id$ + * + * This file is part of plptools. + * + * Copyright (C) 1999 Philip Proudman + * Copyright (C) 1999-2001 Fritz Elfert + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ #ifndef _socketchan_h_ #define _socketchan_h_ @@ -57,3 +56,9 @@ private: }; #endif + +/* + * Local variables: + * c-basic-offset: 4 + * End: + */ -- cgit v1.2.3