* fhandler_serial.cc (fhandler_serial::open): Avoid extraneous setting of res.
* termios.cc (tcsetattr): Correctly record errno after tcsetattr call. * fhandler_serial.cc (fhandler_serial::tcsetattr): Add error-checking so that if any Win32 SetComm*() calls fail, errno gets set to EINVAL and tcsetattr() returns -1. Catch invalid bitrates, mostly. If baud rate setting is B0, just drop DTR and leave Win32 DCB bitrate as-is since 0 is not a valid Win32 setting. (fhandler_serial::tcgetattr): If DTR is low, populate the bitrate as B0, otherwise get it from the DCB.
This commit is contained in:
parent
aa0a224816
commit
b0a82a859d
|
@ -1,3 +1,20 @@
|
||||||
|
2003-01-31 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
|
* fhandler_serial.cc (fhandler_serial::open): Avoid extraneous setting
|
||||||
|
of res.
|
||||||
|
|
||||||
|
* termios.cc (tcsetattr): Correctly record errno after tcsetattr call.
|
||||||
|
|
||||||
|
2003-01-31 Troy Curtiss <troyc@usa.net>
|
||||||
|
|
||||||
|
* fhandler_serial.cc (fhandler_serial::tcsetattr): Add error-checking
|
||||||
|
so that if any Win32 SetComm*() calls fail, errno gets set to EINVAL
|
||||||
|
and tcsetattr() returns -1. Catch invalid bitrates, mostly. If baud
|
||||||
|
rate setting is B0, just drop DTR and leave Win32 DCB bitrate as-is
|
||||||
|
since 0 is not a valid Win32 setting.
|
||||||
|
(fhandler_serial::tcgetattr): If DTR is low, populate the bitrate as
|
||||||
|
B0, otherwise get it from the DCB.
|
||||||
|
|
||||||
2003-01-31 Christopher Faylor <cgf@redhat.com>
|
2003-01-31 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
* passwd.cc (pwdgrp::read_passwd): linebuf *must* be static (from
|
* passwd.cc (pwdgrp::read_passwd): linebuf *must* be static (from
|
||||||
|
|
|
@ -214,7 +214,7 @@ fhandler_serial::open (path_conv *, int flags, mode_t mode)
|
||||||
syscall_printf ("fhandler_serial::open (%s, %p, %p)",
|
syscall_printf ("fhandler_serial::open (%s, %p, %p)",
|
||||||
get_name (), flags, mode);
|
get_name (), flags, mode);
|
||||||
|
|
||||||
if (!(res = this->fhandler_base::open (NULL, flags, mode)))
|
if (!this->fhandler_base::open (NULL, flags, mode))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
res = 1;
|
res = 1;
|
||||||
|
@ -530,8 +530,8 @@ fhandler_serial::tcsetattr (int action, const struct termios *t)
|
||||||
COMMTIMEOUTS to;
|
COMMTIMEOUTS to;
|
||||||
DCB ostate, state;
|
DCB ostate, state;
|
||||||
unsigned int ovtime = vtime_, ovmin = vmin_;
|
unsigned int ovtime = vtime_, ovmin = vmin_;
|
||||||
int tmpDtr, tmpRts;
|
int tmpDtr, tmpRts, res;
|
||||||
tmpDtr = tmpRts = 0;
|
res = tmpDtr = tmpRts = 0;
|
||||||
|
|
||||||
termios_printf ("action %d", action);
|
termios_printf ("action %d", action);
|
||||||
if ((action == TCSADRAIN) || (action == TCSAFLUSH))
|
if ((action == TCSADRAIN) || (action == TCSAFLUSH))
|
||||||
|
@ -554,9 +554,10 @@ fhandler_serial::tcsetattr (int action, const struct termios *t)
|
||||||
|
|
||||||
switch (t->c_ospeed)
|
switch (t->c_ospeed)
|
||||||
{
|
{
|
||||||
case B0: /* drop DTR */
|
case B0:
|
||||||
|
/* Drop DTR - but leave DCB-resident bitrate as-is since
|
||||||
|
0 is an invalid bitrate in Win32 */
|
||||||
dropDTR = TRUE;
|
dropDTR = TRUE;
|
||||||
state.BaudRate = 0;
|
|
||||||
break;
|
break;
|
||||||
case B110:
|
case B110:
|
||||||
state.BaudRate = CBR_110;
|
state.BaudRate = CBR_110;
|
||||||
|
@ -725,8 +726,16 @@ fhandler_serial::tcsetattr (int action, const struct termios *t)
|
||||||
|
|
||||||
state.fAbortOnError = TRUE;
|
state.fAbortOnError = TRUE;
|
||||||
|
|
||||||
if (memcmp (&ostate, &state, sizeof (state)) != 0)
|
if ((memcmp (&ostate, &state, sizeof (state)) != 0)
|
||||||
SetCommState (get_handle (), &state);
|
&& !SetCommState (get_handle (), &state))
|
||||||
|
{
|
||||||
|
/* SetCommState() failed, usually due to invalid DCB param.
|
||||||
|
Keep track of this so we can set errno to EINVAL later
|
||||||
|
and return failure */
|
||||||
|
termios_printf ("SetCommState() failed, %E");
|
||||||
|
__seterrno ();
|
||||||
|
res = -1;
|
||||||
|
}
|
||||||
|
|
||||||
set_r_binary ((t->c_iflag & IGNCR) ? 0 : 1);
|
set_r_binary ((t->c_iflag & IGNCR) ? 0 : 1);
|
||||||
set_w_binary ((t->c_oflag & ONLCR) ? 0 : 1);
|
set_w_binary ((t->c_oflag & ONLCR) ? 0 : 1);
|
||||||
|
@ -750,8 +759,7 @@ fhandler_serial::tcsetattr (int action, const struct termios *t)
|
||||||
rts = tmpRts;
|
rts = tmpRts;
|
||||||
dtr = tmpDtr;
|
dtr = tmpDtr;
|
||||||
|
|
||||||
/*
|
/* The following documentation on was taken from "Linux Serial Programming
|
||||||
The following documentation on was taken from "Linux Serial Programming
|
|
||||||
HOWTO". It explains how MIN (t->c_cc[VMIN] || vmin_) and TIME
|
HOWTO". It explains how MIN (t->c_cc[VMIN] || vmin_) and TIME
|
||||||
(t->c_cc[VTIME] || vtime_) is to be used.
|
(t->c_cc[VTIME] || vtime_) is to be used.
|
||||||
|
|
||||||
|
@ -794,9 +802,8 @@ fhandler_serial::tcsetattr (int action, const struct termios *t)
|
||||||
|
|
||||||
debug_printf ("vtime %d, vmin %d", vtime_, vmin_);
|
debug_printf ("vtime %d, vmin %d", vtime_, vmin_);
|
||||||
|
|
||||||
if (ovmin == vmin_ && ovtime == vtime_)
|
if (ovmin != vmin_ || ovtime != vtime_)
|
||||||
return 0;
|
{
|
||||||
|
|
||||||
memset (&to, 0, sizeof (to));
|
memset (&to, 0, sizeof (to));
|
||||||
|
|
||||||
if ((vmin_ > 0) && (vtime_ == 0))
|
if ((vmin_ > 0) && (vtime_ == 0))
|
||||||
|
@ -828,15 +835,18 @@ fhandler_serial::tcsetattr (int action, const struct termios *t)
|
||||||
|
|
||||||
debug_printf ("ReadTotalTimeoutConstant %d, ReadIntervalTimeout %d, ReadTotalTimeoutMultiplier %d",
|
debug_printf ("ReadTotalTimeoutConstant %d, ReadIntervalTimeout %d, ReadTotalTimeoutMultiplier %d",
|
||||||
to.ReadTotalTimeoutConstant, to.ReadIntervalTimeout, to.ReadTotalTimeoutMultiplier);
|
to.ReadTotalTimeoutConstant, to.ReadIntervalTimeout, to.ReadTotalTimeoutMultiplier);
|
||||||
int res = SetCommTimeouts (get_handle (), &to);
|
|
||||||
if (!res)
|
if (!SetCommTimeouts(get_handle (), &to))
|
||||||
{
|
{
|
||||||
system_printf ("SetCommTimeout failed, %E");
|
/* SetCommTimeouts() failed. Keep track of this so we
|
||||||
|
can set errno to EINVAL later and return failure */
|
||||||
|
termios_printf ("SetCommTimeouts() failed, %E");
|
||||||
__seterrno ();
|
__seterrno ();
|
||||||
return -1;
|
res = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* tcgetattr: POSIX 7.2.1.1 */
|
/* tcgetattr: POSIX 7.2.1.1 */
|
||||||
|
@ -854,12 +864,12 @@ fhandler_serial::tcgetattr (struct termios *t)
|
||||||
|
|
||||||
/* -------------- Baud rate ------------------ */
|
/* -------------- Baud rate ------------------ */
|
||||||
|
|
||||||
|
/* If DTR is NOT set, return B0 as our speed */
|
||||||
|
if (dtr != TIOCM_DTR)
|
||||||
|
t->c_cflag = t->c_ospeed = t->c_ispeed = B0;
|
||||||
|
else
|
||||||
switch (state.BaudRate)
|
switch (state.BaudRate)
|
||||||
{
|
{
|
||||||
case 0:
|
|
||||||
/* FIXME: need to drop DTR */
|
|
||||||
t->c_cflag = t->c_ospeed = t->c_ispeed = B0;
|
|
||||||
break;
|
|
||||||
case CBR_110:
|
case CBR_110:
|
||||||
t->c_cflag = t->c_ospeed = t->c_ispeed = B110;
|
t->c_cflag = t->c_ospeed = t->c_ispeed = B110;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -144,7 +144,6 @@ tcsetattr (int fd, int a, const struct termios *t)
|
||||||
case bg_ok:
|
case bg_ok:
|
||||||
if (cfd.isopen ())
|
if (cfd.isopen ())
|
||||||
res = cfd->tcsetattr (a, t);
|
res = cfd->tcsetattr (a, t);
|
||||||
else
|
|
||||||
e = get_errno ();
|
e = get_errno ();
|
||||||
break;
|
break;
|
||||||
case bg_signalled:
|
case bg_signalled:
|
||||||
|
|
Loading…
Reference in New Issue