~ubuntu-branches/ubuntu/breezy/uucp/breezy

« back to all changes in this revision

Viewing changes to unix/serial.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter Palfrader
  • Date: 2004-12-30 15:30:22 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20041230153022-mx4cdr9j3u9bldo3
Tags: 1.07-12
Add cs localisation for debconf templates (closes: #287305).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* serial.c
2
2
   The serial port communication routines for Unix.
3
3
 
4
 
   Copyright (C) 1991, 1992, 1993, 1994, 1995 Ian Lance Taylor
 
4
   Copyright (C) 1991, 1992, 1993, 1994, 1995, 2002 Ian Lance Taylor
5
5
 
6
6
   This file is part of the Taylor UUCP package.
7
7
 
17
17
 
18
18
   You should have received a copy of the GNU General Public License
19
19
   along with this program; if not, write to the Free Software
20
 
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
20
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
21
21
 
22
 
   The author of the program may be contacted at ian@airs.com or
23
 
   c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
 
22
   The author of the program may be contacted at ian@airs.com.
24
23
   */
25
24
 
26
25
#include "uucp.h"
27
26
 
28
27
#if USE_RCS_ID
29
 
const char serial_rcsid[] = "$Id: serial.c,v 1.65 1995/08/10 00:53:54 ian Rel $";
 
28
const char serial_rcsid[] = "$Id: serial.c,v 1.78 2002/03/05 19:10:42 ian Rel $";
30
29
#endif
31
30
 
32
31
#include "uudefs.h"
123
122
#include <sys/dev.h>
124
123
#endif
125
124
 
 
125
#if HAVE_SYS_TERMIOX_H
 
126
#include <sys/termiox.h>
 
127
#endif
 
128
 
126
129
/* Get definitions for both O_NONBLOCK and O_NDELAY.  */
127
130
#ifndef O_NDELAY
128
131
#ifdef FNDELAY
237
240
static boolean fsserial_lockfile P((boolean flok,
238
241
                                    const struct sconnection *));
239
242
static boolean fsserial_lock P((struct sconnection *qconn,
240
 
                                boolean fin));
 
243
                                boolean fin, boolean fuser));
241
244
static boolean fsserial_unlock P((struct sconnection *qconn));
242
245
static boolean fsserial_open P((struct sconnection *qconn, long ibaud,
243
 
                                boolean fwait, enum tclocal_setting tlocal));
 
246
                                boolean fwait, boolean fuser,
 
247
                                enum tclocal_setting tlocal));
244
248
static boolean fsstdin_open P((struct sconnection *qconn, long ibaud,
245
 
                               boolean fwait));
 
249
                               boolean fwait, boolean fuser));
246
250
static boolean fsmodem_open P((struct sconnection *qconn, long ibaud,
247
 
                               boolean fwait));
 
251
                               boolean fwait, boolean fuser));
248
252
static boolean fsdirect_open P((struct sconnection *qconn, long ibaud,
249
 
                                boolean fwait));
 
253
                                boolean fwait, boolean fuser));
250
254
static boolean fsblock P((struct ssysdep_conn *q, boolean fblock));
251
255
static boolean fsserial_close P((struct ssysdep_conn *q));
252
256
static boolean fsstdin_close P((struct sconnection *qconn,
358
362
 
359
363
static RETSIGTYPE
360
364
usalarm (isig)
361
 
     int isig;
 
365
     int isig ATTRIBUTE_UNUSED;
362
366
{
363
367
#if ! HAVE_SIGACTION && ! HAVE_SIGVEC && ! HAVE_SIGSET
364
368
  (void) signal (isig, usalarm);
633
637
        {
634
638
          char *zl;
635
639
 
636
 
          for (zl = zalc + sizeof LCK_TEMPLATE - 1; *zl != '\0'; zl++)
637
 
            if (isupper (*zl))
638
 
              *zl = tolower (*zl);
 
640
          zl = zalc + sizeof LCK_TEMPLATE + clen - 2;
 
641
          if (isupper (*zl))
 
642
            *zl = tolower (*zl);
639
643
        }
640
644
#endif
641
645
        z = zalc;
729
733
   open because we can't fail out if it is locked then.  */
730
734
 
731
735
static boolean
732
 
fsserial_lock (qconn, fin)
 
736
fsserial_lock (qconn, fin, fuser)
733
737
     struct sconnection *qconn;
734
738
     boolean fin;
 
739
     boolean fuser;
735
740
{
736
741
  if (! fsserial_lockfile (TRUE, qconn))
737
742
    return FALSE;
741
746
  {
742
747
    struct ssysdep_conn *qsysdep;
743
748
    int iflag;
 
749
    uid_t ieuid;
 
750
    gid_t iegid;
744
751
 
745
752
    qsysdep = (struct ssysdep_conn *) qconn->psysdep;
746
753
 
749
756
    else
750
757
      iflag = iSunblock;
751
758
 
 
759
    if (fuser)
 
760
      {
 
761
        if (! fsuser_perms (&ieuid, &iegid))
 
762
          {
 
763
            (void) fsserial_lockfile (FALSE, qconn);
 
764
            return FALSE;
 
765
          }
 
766
      }
 
767
 
752
768
    qsysdep->o = open (qsysdep->zdevice, O_RDWR | iflag);
753
769
    if (qsysdep->o < 0)
754
770
      {
762
778
#endif
763
779
        if (qsysdep->o < 0)
764
780
          {
765
 
            if (errno != EBUSY)
 
781
            int ierr;
 
782
 
 
783
            ierr = errno;
 
784
            if (fuser)
 
785
              (void) fsuucp_perms ((long) ieuid, (long) iegid);
 
786
            if (ierr != EBUSY)
766
787
              ulog (LOG_ERROR, "open (%s): %s", qsysdep->zdevice,
767
 
                    strerror (errno));
 
788
                    strerror (ierr));
 
789
            (void) fsserial_lockfile (FALSE, qconn);
 
790
            return FALSE;
 
791
          }
 
792
      }
 
793
 
 
794
    if (fuser)
 
795
      {
 
796
        if (! fsuucp_perms ((long) ieuid, (long) iegid))
 
797
          {
 
798
            (void) close (qsysdep->o);
 
799
            qsysdep->o = -1;
768
800
            (void) fsserial_lockfile (FALSE, qconn);
769
801
            return FALSE;
770
802
          }
922
954
#endif
923
955
#ifdef B230400
924
956
  { B230400, 230400 },
925
 
#endif
 
957
#else
 
958
#ifdef _B230400
 
959
  { _B230400, 230400 },
 
960
#endif /* _B230400 */
 
961
#endif /* ! defined (B230400) */
926
962
#ifdef B460800
927
963
  { B460800, 460800 },
 
964
#else
 
965
#ifdef _B460800
 
966
  { _B460800, 460800 },
 
967
#endif /* _B460800 */
 
968
#endif /* ! defined (B460800) */
 
969
#ifdef B500000
 
970
  { B500000, 500000 },
 
971
#endif
 
972
#ifdef B576000
 
973
  { B576000, 576000 },
 
974
#endif
 
975
#ifdef B921600
 
976
  { B921600, 921600 },
 
977
#endif
 
978
#ifdef B1000000
 
979
  { B1000000, 1000000 },
 
980
#endif
 
981
#ifdef B1152000
 
982
  { B1152000, 1152000 },
 
983
#endif
 
984
#ifdef B1500000
 
985
  { B1500000, 1500000 },
 
986
#endif
 
987
#ifdef B2000000
 
988
  { B2000000, 2000000 },
 
989
#endif
 
990
#ifdef B2500000
 
991
  { B2500000, 2500000 },
 
992
#endif
 
993
#ifdef B3000000
 
994
  { B3000000, 3000000 },
 
995
#endif
 
996
#ifdef B3500000
 
997
  { B3500000, 3500000 },
 
998
#endif
 
999
#ifdef B4000000
 
1000
  { B4000000, 4000000 },
928
1001
#endif
929
1002
  { B0, 0 }
930
1003
};
939
1012
 
940
1013
/* Open a serial line.  This sets the terminal settings.  We begin in
941
1014
   seven bit mode and let the protocol change if necessary.  If fwait
942
 
   is FALSE we open the terminal in non-blocking mode.  If flocal is
943
 
   TRUE we set CLOCAL on the terminal when using termio[s]; this is
944
 
   supposedly required on some versions of BSD/386.  */
 
1015
   is FALSE we open the terminal in non-blocking mode.  If fuser is
 
1016
   true we open the port using the user's permissions.  The tlocal
 
1017
   parameter indicates whether to set, clear, or ignore CLOCAL.  */
945
1018
 
946
1019
static boolean
947
 
fsserial_open (qconn, ibaud, fwait, tlocal)
 
1020
fsserial_open (qconn, ibaud, fwait, fuser, tlocal)
948
1021
     struct sconnection *qconn;
949
1022
     long ibaud;
950
1023
     boolean fwait;
 
1024
     boolean fuser;
951
1025
     enum tclocal_setting tlocal;
952
1026
{
953
1027
  struct ssysdep_conn *q;
987
1061
  ib = B0;
988
1062
  if (ibaud != 0)
989
1063
    {
990
 
      int i;
 
1064
      size_t i;
991
1065
 
992
1066
      for (i = 0; i < CBAUD_TABLE; i++)
993
1067
        if (asSbaud_table[i].ibaud == ibaud)
1004
1078
  if (q->o < 0)
1005
1079
    {
1006
1080
      int iflag;
 
1081
      uid_t ieuid;
 
1082
      gid_t iegid;
1007
1083
 
1008
1084
      if (fwait)
1009
1085
        iflag = 0;
1010
1086
      else
1011
1087
        iflag = iSunblock;
1012
1088
 
 
1089
      if (fuser)
 
1090
        {
 
1091
          if (! fsuser_perms (&ieuid, &iegid))
 
1092
            return FALSE;
 
1093
        }
 
1094
          
1013
1095
      q->o = open (q->zdevice, O_RDWR | iflag);
1014
1096
      if (q->o < 0)
1015
1097
        {
1022
1104
#endif
1023
1105
          if (q->o < 0)
1024
1106
            {
 
1107
              int ierr;
 
1108
 
 
1109
              ierr = errno;
 
1110
              if (fuser)
 
1111
                (void) fsuucp_perms ((long) ieuid, (long) iegid);
1025
1112
              ulog (LOG_ERROR, "open (%s): %s", q->zdevice,
1026
 
                    strerror (errno));
 
1113
                    strerror (ierr));
1027
1114
              return FALSE;
1028
1115
            }
1029
1116
        }
1030
1117
 
 
1118
      if (fuser)
 
1119
        {
 
1120
          if (! fsuucp_perms ((long) ieuid, (long) iegid))
 
1121
            return FALSE;
 
1122
        }
 
1123
 
1031
1124
      if (fcntl (q->o, F_SETFD, fcntl (q->o, F_GETFD, 0) | FD_CLOEXEC) < 0)
1032
1125
        {
1033
1126
          ulog (LOG_ERROR, "fcntl (FD_CLOEXEC): %s", strerror (errno));
1045
1138
    }
1046
1139
  q->iwr_flags = -1;
1047
1140
 
 
1141
  if (! fsblock (q, TRUE))
 
1142
    return FALSE;
 
1143
 
1048
1144
  if (! fgetterminfo (q->o, &q->sorig))
1049
1145
    {
1050
1146
      q->fterminal = FALSE;
1187
1283
    q->ibaud = ibaud;
1188
1284
  else
1189
1285
    {
1190
 
      int i;
 
1286
      size_t i;
1191
1287
 
1192
1288
      q->ibaud = (long) 1200;
1193
1289
      for (i = 0; i < CBAUD_TABLE; i++)
1194
1290
        {
1195
 
          if (asSbaud_table[i].icode == ib)
 
1291
          if (asSbaud_table[i].icode == ib
 
1292
              && asSbaud_table[i].ibaud != 0)
1196
1293
            {
1197
1294
              q->ibaud = asSbaud_table[i].ibaud;
1198
1295
              break;
1211
1308
   call to fsblock.  */
1212
1309
 
1213
1310
static boolean
1214
 
fsstdin_open (qconn, ibaud, fwait)
 
1311
fsstdin_open (qconn, ibaud, fwait, fuser)
1215
1312
     struct sconnection *qconn;
1216
1313
     long ibaud;
1217
1314
     boolean fwait;
 
1315
     boolean fuser;
1218
1316
{
1219
1317
  struct ssysdep_conn *q;
1220
1318
 
1223
1321
  q->owr = 1;
1224
1322
 
1225
1323
  q->o = q->ord;
1226
 
  if (! fsserial_open (qconn, ibaud, fwait, IGNORE_CLOCAL))
 
1324
  if (! fsserial_open (qconn, ibaud, fwait, fuser, IGNORE_CLOCAL))
1227
1325
    return FALSE;
1228
1326
  q->iwr_flags = fcntl (q->owr, F_GETFL, 0);
1229
1327
  if (q->iwr_flags < 0)
1237
1335
/* Open a modem port.  */
1238
1336
 
1239
1337
static boolean
1240
 
fsmodem_open (qconn, ibaud, fwait)
 
1338
fsmodem_open (qconn, ibaud, fwait, fuser)
1241
1339
     struct sconnection *qconn;
1242
1340
     long ibaud;
1243
1341
     boolean fwait;
 
1342
     boolean fuser;
1244
1343
{
1245
1344
  struct uuconf_modem_port *qm;
1246
1345
 
1248
1347
  if (ibaud == (long) 0)
1249
1348
    ibaud = qm->uuconf_ibaud;
1250
1349
 
1251
 
  if (! fsserial_open (qconn, ibaud, fwait,
 
1350
  if (! fsserial_open (qconn, ibaud, fwait, fuser,
1252
1351
                       fwait ? CLEAR_CLOCAL : SET_CLOCAL))
1253
1352
    return FALSE;
1254
1353
 
1267
1366
/* Open a direct port.  */
1268
1367
 
1269
1368
static boolean
1270
 
fsdirect_open (qconn, ibaud, fwait)
 
1369
fsdirect_open (qconn, ibaud, fwait, fuser)
1271
1370
     struct sconnection *qconn;
1272
1371
     long ibaud;
1273
1372
     boolean fwait;
 
1373
     boolean fuser;
1274
1374
{
1275
1375
  struct uuconf_direct_port *qd;
1276
1376
 
1277
1377
  qd = &qconn->qport->uuconf_u.uuconf_sdirect;
1278
1378
  if (ibaud == (long) 0)
1279
1379
    ibaud = qd->uuconf_ibaud;
1280
 
  if (! fsserial_open (qconn, ibaud, fwait,
 
1380
  if (! fsserial_open (qconn, ibaud, fwait, fuser,
1281
1381
                       qd->uuconf_fcarrier ? CLEAR_CLOCAL : SET_CLOCAL))
1282
1382
    return FALSE;
1283
1383
 
1333
1433
      else
1334
1434
        iwant = qs->iwr_flags | iSunblock;
1335
1435
 
1336
 
      if (fcntl (qs->owr, F_SETFL, iwant) < 0)
 
1436
      isys = fcntl (qs->owr, F_SETFL, iwant);
 
1437
      if (isys < 0)
1337
1438
        {
1338
 
          /* We don't bother to fix up iSunblock here, since we
1339
 
             succeeded above.  */
1340
 
          ulog (LOG_ERROR, "fcntl: %s", strerror (errno));
1341
 
          return FALSE;
 
1439
#if O_NONBLOCK != 0
 
1440
          if (! fblock && iSunblock != O_NONBLOCK && errno == EINVAL)
 
1441
            {
 
1442
              iSunblock = O_NONBLOCK;
 
1443
              iwant = qs->iwr_flags | O_NONBLOCK;
 
1444
              isys = fcntl (qs->owr, F_SETFL, iwant);
 
1445
            }
 
1446
#endif
 
1447
          if (isys < 0)
 
1448
            {
 
1449
              ulog (LOG_ERROR, "fcntl: %s", strerror (errno));
 
1450
              return FALSE;
 
1451
            }
1342
1452
        }
1343
1453
 
1344
1454
      qs->iwr_flags = iwant;
1405
1515
static boolean
1406
1516
fsstdin_close (qconn, puuconf, qdialer, fsuccess)
1407
1517
     struct sconnection *qconn;
1408
 
     pointer puuconf;
1409
 
     struct uuconf_dialer *qdialer;
1410
 
     boolean fsuccess;
 
1518
     pointer puuconf ATTRIBUTE_UNUSED;
 
1519
     struct uuconf_dialer *qdialer ATTRIBUTE_UNUSED;
 
1520
     boolean fsuccess ATTRIBUTE_UNUSED;
1411
1521
{
1412
1522
  struct ssysdep_conn *qsysdep;
1413
1523
 
1573
1683
static boolean
1574
1684
fsdirect_close (qconn, puuconf, qdialer, fsuccess)
1575
1685
     struct sconnection *qconn;
1576
 
     pointer puuconf;
1577
 
     struct uuconf_dialer *qdialer;
1578
 
     boolean fsuccess;
 
1686
     pointer puuconf ATTRIBUTE_UNUSED;
 
1687
     struct uuconf_dialer *qdialer ATTRIBUTE_UNUSED;
 
1688
     boolean fsuccess ATTRIBUTE_UNUSED;
1579
1689
{
1580
1690
  return fsserial_close ((struct ssysdep_conn *) qconn->psysdep);
1581
1691
}
1825
1935
 
1826
1936
/* Tell the port to use hardware flow control.  There is no standard
1827
1937
   mechanism for controlling this.  This implementation supports
1828
 
   CRTSCTS on SunOS, RTS/CTSFLOW on 386(ish) unix, CTSCD on the 3b1,
1829
 
   CCTS_OFLOW/CRTS_IFLOW on BSDI, TXADDCD/TXDELCD on AIX, and IRTS on
1830
 
   NCR Tower.  If you know how to do it on other systems, please
1831
 
   implement it and send me the patches.  */
 
1938
   CRTSCTS and CRTSXOFF on SunOS/Solaris, RTS/CTSFLOW on 386(ish)
 
1939
   unix, CTSCD on the 3b1, CCTS_OFLOW/CRTS_IFLOW on BSDI,
 
1940
   TXADDCD/TXDELCD on AIX, IRTS on NCR Tower, and TCGETX/TCSETX on
 
1941
   HP/UX.  If you know how to do it on other systems, please implement
 
1942
   it and send me the patches.  */
1832
1943
 
1833
1944
static boolean
1834
1945
fsserial_hardflow (qconn, fhardflow)
1882
1993
#ifdef CRTSCTS
1883
1994
      q->snew.c_cflag |= CRTSCTS;
1884
1995
#endif /* defined (CRTSCTS) */
 
1996
#ifdef CRTSXOFF
 
1997
      q->snew.c_cflag |= CRTSXOFF;
 
1998
#endif /* defined (CRTSXOFF) */
1885
1999
#ifdef CTSCD
1886
2000
      q->snew.c_cflag |= CTSCD;
1887
2001
#endif /* defined (CTSCD) */
1898
2012
                strerror (errno));
1899
2013
          return FALSE;
1900
2014
        }
 
2015
#if HAVE_SYS_TERMIOX
 
2016
#ifdef TCGETX
 
2017
      {
 
2018
        struct termiox tx;
 
2019
 
 
2020
        if (ioctl (q->o, TCGETX, &tx) < 0)
 
2021
          {
 
2022
            ulog (LOG_ERROR,
 
2023
                  "Can't enable hardware flow control: ioctl (TCGETX): %s",
 
2024
                  strerror (errno));
 
2025
            return FALSE;
 
2026
          }
 
2027
        tx.x_hflag |= RTSXOFF | CTSXON;
 
2028
        if (ioctl (q->o, TCSETX, &tx) < 0)
 
2029
          {
 
2030
            ulog (LOG_ERROR,
 
2031
                  "Can't enable hardware flow control: ioctl (TCSETX): %s",
 
2032
                  strerror (errno));
 
2033
            return FALSE;
 
2034
          }
 
2035
      }
 
2036
#endif /* TCGETX */
 
2037
#endif /* HAVE_SYS_TERMIOX */
1901
2038
#endif /* ! HAVE_TXADDCD */
1902
2039
    }
1903
2040
  else
1915
2052
#ifdef CRTSCTS
1916
2053
      q->snew.c_cflag &=~ CRTSCTS;
1917
2054
#endif /* defined (CRTSCTS) */
 
2055
#ifdef CRTSXOFF
 
2056
      q->snew.c_cflag &=~ CRTSXOFF;
 
2057
#endif /* defined (CRTSXOFF) */
1918
2058
#ifdef CTSCD
1919
2059
      q->snew.c_cflag &=~ CTSCD;
1920
2060
#endif /* defined (CTSCD) */
1931
2071
                strerror (errno));
1932
2072
          return FALSE;
1933
2073
        }
 
2074
#if HAVE_SYS_TERMIOX
 
2075
#ifdef TCGETX
 
2076
      {
 
2077
        struct termiox tx;
 
2078
 
 
2079
        if (ioctl (q->o, TCGETX, &tx) < 0)
 
2080
          {
 
2081
            ulog (LOG_ERROR,
 
2082
                  "Can't disable hardware flow control: ioctl (TCGETX): %s",
 
2083
                  strerror (errno));
 
2084
            return FALSE;
 
2085
          }
 
2086
        tx.x_hflag &=~ (RTSXOFF | CTSXON);
 
2087
        if (ioctl (q->o, TCSETX, &tx) < 0)
 
2088
          {
 
2089
            ulog (LOG_ERROR,
 
2090
                  "Can't disable hardware flow control: ioctl (TCSETX): %s",
 
2091
                  strerror (errno));
 
2092
            return FALSE;
 
2093
          }
 
2094
      }
 
2095
#endif /* TCGETX */
 
2096
#endif /* HAVE_SYS_TERMIOX */
1934
2097
#endif /* ! HAVE_TXADDCD */
1935
2098
    }
1936
2099
#endif /* HAVE_HARDFLOW */
2321
2484
        }
2322
2485
 
2323
2486
      cwant -= cgot;
2324
 
      if (cgot >= cmin)
 
2487
      if ((size_t) cgot >= cmin)
2325
2488
        cmin = 0;
2326
2489
      else
2327
2490
        cmin -= cgot;
2377
2540
          else
2378
2541
            csleepchars = MAX_INPUT - 10;
2379
2542
 
2380
 
#ifndef BUG
2381
 
          if (q->ibaud) {
2382
 
            isleep = (int) (((long) csleepchars * 10000L) / q->ibaud);
2383
 
            isleep -= 10;
2384
 
          } else {
2385
 
            isleep = 1000; /* I hope, a second is right... */
2386
 
          }
2387
 
#else
2388
2543
          isleep = (int) (((long) csleepchars * 10000L) / q->ibaud);
2389
2544
          isleep -= 10;
2390
 
#endif
2391
2545
 
2392
2546
          if (isleep > 10)
2393
2547
            {
2778
2932
        {
2779
2933
#if HAVE_SELECT
2780
2934
          struct timeval stime;
2781
 
          int imask;
 
2935
#ifdef FD_ZERO
 
2936
          fd_set smask;
 
2937
#else
 
2938
          int smask;
 
2939
#endif
2782
2940
          int c;
2783
2941
 
2784
2942
          /* We didn't write any data.  Call select.  We use a timeout
2785
 
             long enough for 1024 bytes to be sent.
 
2943
             long enough for 1024 bytes to be sent.  But we don't wait
 
2944
             longer than the times it takes to receive cread bytes, in
 
2945
             case our read buffer is small.
2786
2946
               secs/kbyte == (1024 bytes/kbyte * 10 bits/byte) / baud bits/sec
2787
2947
               usecs/kbyte == (((1024 bytes/kbyte * 1000000 usecs/sec)
2788
2948
                                / baud bits/sec)
2789
2949
                               * 10 bits/byte)
 
2950
 
2790
2951
             */
2791
 
#ifndef BUG
2792
 
          if (q->ibaud) {
2793
 
            stime.tv_sec = (long) 10240 / q->ibaud;
2794
 
            stime.tv_usec = ((((long) 1024000000 / q->ibaud) * (long) 10)
2795
 
                             % (long) 1000000);
2796
 
          } else {
2797
 
            stime.tv_sec = 1;
2798
 
            stime.tv_usec = 0;
2799
 
          }
 
2952
          if (q->fterminal)
 
2953
            {
 
2954
              unsigned long cwait;
 
2955
 
 
2956
              cwait = 1024;
 
2957
              if (cwait > cread)
 
2958
                cwait = cread;
 
2959
              stime.tv_sec = (cwait * 10) / q->ibaud;
 
2960
              stime.tv_usec = ((((cwait * 1000000) / q->ibaud) * 10)
 
2961
                               % 1000000);
 
2962
            }
 
2963
          else
 
2964
            {
 
2965
              /* This is some sort of network connection.  We can't
 
2966
                 estimate how long it will take to write data.  It
 
2967
                 also doesn't matter as much, as most systems will
 
2968
                 buffer much more incoming network data than they will
 
2969
                 incoming serial data.  Sleep for a second, although
 
2970
                 normally the select will return sonner because we can
 
2971
                 write more data.  */
 
2972
              stime.tv_sec = 1;
 
2973
              stime.tv_usec = 0;
 
2974
            }
 
2975
 
 
2976
#ifdef FD_ZERO
 
2977
          FD_ZERO (&smask);
 
2978
          FD_SET (q->o, &smask);
2800
2979
#else
2801
 
          stime.tv_sec = (long) 10240 / q->ibaud;
2802
 
          stime.tv_usec = ((((long) 1024000000 / q->ibaud) * (long) 10)
2803
 
                           % (long) 1000000);
2804
 
#endif
2805
 
 
2806
 
          imask = 1 << q->o;
2807
 
          if (imask == 0)
 
2980
          smask = 1 << q->o;
 
2981
          if (smask == 0)
2808
2982
            ulog (LOG_FATAL, "fsysdep_conn_io: File descriptors too large");
 
2983
#endif
2809
2984
 
2810
2985
          /* If we've received a signal, don't continue.  */
2811
2986
          if (FGOT_QUIT_SIGNAL ())
2815
2990
 
2816
2991
          /* We don't bother to loop on EINTR.  If we get a signal, we
2817
2992
             just loop around and try the read and write again.  */
2818
 
          c = select (q->o + 1, (pointer) NULL, (pointer) &imask,
 
2993
          c = select (q->o + 1, (pointer) NULL, (pointer) &smask,
2819
2994
                      (pointer) NULL, &stime);
2820
2995
          if (c < 0 && errno == EINTR)
2821
2996
            {
2872
3047
                 we don't need to use the catch stuff, since we know
2873
3048
                 that HAVE_RESTARTABLE_SYSCALLS is 0.  */
2874
3049
              usset_signal (SIGALRM, usalarm, TRUE, (boolean *) NULL);
2875
 
#ifndef BUG
2876
 
              if (q->ibaud)
2877
 
                alarm ((int) ((long) 10240 / q->ibaud) + 1);
 
3050
              if (q->fterminal)
 
3051
                alarm ((int) ((long) 10240 / q->ibaud) + 1);
2878
3052
              else
2879
3053
                alarm (1);
2880
 
#else
2881
 
              alarm ((int) ((long) 10240 / q->ibaud) + 1);
2882
 
#endif
2883
3054
 
2884
3055
              /* There is a race condition here: on a severely loaded
2885
3056
                 system, we could get the alarm before we start the
3005
3176
{
3006
3177
  register struct ssysdep_conn *q;
3007
3178
  boolean fchanged, fdo;
3008
 
  int iset = 0;
3009
 
  int iclear = 0;
 
3179
  unsigned int iset = 0;
 
3180
  unsigned int iclear = 0;
3010
3181
 
3011
3182
  q = (struct ssysdep_conn *) qconn->psysdep;
3012
3183