--- sourceforge.net/trunk/rdesktop/serial.c 2004/11/06 15:29:38 798 +++ sourceforge.net/trunk/rdesktop/serial.c 2005/02/20 19:38:34 816 @@ -121,9 +121,12 @@ /* FIONREAD should really do the same thing as TIOCINQ, where it is * not available */ -#ifndef TIOCINQ +#if !defined(TIOCINQ) && defined(FIONREAD) #define TIOCINQ FIONREAD #endif +#if !defined(TIOCOUTQ) && defined(FIONWRITE) +#define TIOCOUTQ FIONWRITE +#endif extern RDPDR_DEVICE g_rdpdr_device[]; @@ -395,16 +398,16 @@ break; } -#if 0 +#ifdef CBAUD + ptermios->c_cflag &= ~CBAUD; + ptermios->c_cflag |= speed; +#else /* on systems with separate ispeed and ospeed, we can remember the speed in ispeed while changing DTR with ospeed */ cfsetispeed(pser_inf->ptermios, speed); cfsetospeed(pser_inf->ptermios, pser_inf->dtr ? speed : 0); #endif - ptermios->c_cflag &= ~CBAUD; - ptermios->c_cflag |= speed; - ptermios->c_cflag &= ~(CSTOPB | PARENB | PARODD | CSIZE | CRTSCTS); switch (pser_inf->stop_bits) { @@ -565,7 +568,7 @@ pser_inf->ptermios->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); pser_inf->ptermios->c_oflag &= ~OPOST; - pser_inf->ptermios->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN | XCASE); + pser_inf->ptermios->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); pser_inf->ptermios->c_cflag &= ~(CSIZE | PARENB); pser_inf->ptermios->c_cflag |= CS8; @@ -643,7 +646,7 @@ } tcsetattr(handle, TCSANOW, ptermios); -#ifdef WITH_DEBUG_SERIAL +#if defined(WITH_DEBUG_SERIAL) && defined(TIOCINQ) ioctl(handle, TIOCINQ, &bytes_inqueue); DEBUG_SERIAL(("serial_read inqueue: %d expected %d\n", bytes_inqueue, length)); #endif @@ -700,25 +703,26 @@ case SERIAL_SET_BAUD_RATE: in_uint32_le(in, pser_inf->baud_rate); set_termios(pser_inf, handle); - DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_BAUD_RATE %d\n", pser_inf->baud_rate)); + DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_BAUD_RATE %d\n", + pser_inf->baud_rate)); break; case SERIAL_GET_BAUD_RATE: out_uint32_le(out, pser_inf->baud_rate); - DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_BAUD_RATE %d\n", pser_inf->baud_rate)); + DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_BAUD_RATE %d\n", + pser_inf->baud_rate)); break; case SERIAL_SET_QUEUE_SIZE: in_uint32_le(in, pser_inf->queue_in_size); in_uint32_le(in, pser_inf->queue_out_size); DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_QUEUE_SIZE in %d out %d\n", - pser_inf->queue_in_size, pser_inf->queue_out_size)); + pser_inf->queue_in_size, pser_inf->queue_out_size)); break; case SERIAL_SET_LINE_CONTROL: in_uint8(in, pser_inf->stop_bits); in_uint8(in, pser_inf->parity); in_uint8(in, pser_inf->word_length); set_termios(pser_inf, handle); - DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_LINE_CONTROL stop %d parity %d word %d\n", - pser_inf->stop_bits, pser_inf->parity, pser_inf->word_length)); + DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_LINE_CONTROL stop %d parity %d word %d\n", pser_inf->stop_bits, pser_inf->parity, pser_inf->word_length)); break; case SERIAL_GET_LINE_CONTROL: DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_LINE_CONTROL\n")); @@ -761,8 +765,8 @@ in_uint32_le(in, pser_inf->onlimit); in_uint32_le(in, pser_inf->offlimit); DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_HANDFLOW %x %x %x %x\n", - pser_inf->control, pser_inf->xonoff, pser_inf->onlimit, - pser_inf->onlimit)); + pser_inf->control, pser_inf->xonoff, pser_inf->onlimit, + pser_inf->onlimit)); set_termios(pser_inf, handle); break; case SERIAL_SET_TIMEOUTS: @@ -772,15 +776,15 @@ in_uint32(in, pser_inf->write_total_timeout_multiplier); in_uint32(in, pser_inf->write_total_timeout_constant); DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_TIMEOUTS read timeout %d %d %d\n", - pser_inf->read_interval_timeout, - pser_inf->read_total_timeout_multiplier, - pser_inf->read_total_timeout_constant)); + pser_inf->read_interval_timeout, + pser_inf->read_total_timeout_multiplier, + pser_inf->read_total_timeout_constant)); break; case SERIAL_GET_TIMEOUTS: DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_TIMEOUTS read timeout %d %d %d\n", - pser_inf->read_interval_timeout, - pser_inf->read_total_timeout_multiplier, - pser_inf->read_total_timeout_constant)); + pser_inf->read_interval_timeout, + pser_inf->read_total_timeout_multiplier, + pser_inf->read_total_timeout_constant)); out_uint32(out, pser_inf->read_interval_timeout); out_uint32(out, pser_inf->read_total_timeout_multiplier); @@ -789,12 +793,14 @@ out_uint32(out, pser_inf->write_total_timeout_constant); break; case SERIAL_GET_WAIT_MASK: - DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_WAIT_MASK %X\n", pser_inf->wait_mask); - out_uint32(out, pser_inf->wait_mask)); + DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_WAIT_MASK %X\n", + pser_inf->wait_mask)); + out_uint32(out, pser_inf->wait_mask); break; case SERIAL_SET_WAIT_MASK: in_uint32(in, pser_inf->wait_mask); - DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_WAIT_MASK %X\n", pser_inf->wait_mask)); + DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_WAIT_MASK %X\n", + pser_inf->wait_mask)); break; case SERIAL_SET_DTR: DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_DTR\n")); @@ -849,13 +855,18 @@ out_uint32_le(out, 0); /* Hold reasons */ result = 0; +#ifdef TIOCINQ ioctl(handle, TIOCINQ, &result); +#endif out_uint32_le(out, result); /* Amount in in queue */ if (result) - DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_COMMSTATUS in queue %d\n", result)); + DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_COMMSTATUS in queue %d\n", + result)); result = 0; +#ifdef TIOCOUTQ ioctl(handle, TIOCOUTQ, &result); +#endif out_uint32_le(out, result); /* Amount in out queue */ if (result) DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_COMMSTATUS out queue %d\n", result)); @@ -879,7 +890,8 @@ rdpdr_abort_io(handle, 3, STATUS_CANCELLED); break; case SERIAL_WAIT_ON_MASK: - DEBUG_SERIAL(("serial_ioctl -> SERIAL_WAIT_ON_MASK %X\n", pser_inf->wait_mask)); + DEBUG_SERIAL(("serial_ioctl -> SERIAL_WAIT_ON_MASK %X\n", + pser_inf->wait_mask)); pser_inf->event_pending = 1; if (serial_get_event(handle, &result)) { @@ -927,9 +939,9 @@ if (index < 0) return False; +#ifdef TIOCINQ pser_inf = (SERIAL_DEVICE *) g_rdpdr_device[index].pdevice_data; - ioctl(handle, TIOCINQ, &bytes); if (bytes > 0) @@ -965,8 +977,9 @@ { pser_inf->event_rlsd = 0; } +#endif - +#ifdef TIOCOUTQ ioctl(handle, TIOCOUTQ, &bytes); if ((bytes == 0) && (pser_inf->event_txempty > 0) && (pser_inf->wait_mask & SERIAL_EV_TXEMPTY)) @@ -977,7 +990,7 @@ ret = True; } pser_inf->event_txempty = bytes; - +#endif ioctl(handle, TIOCMGET, &bytes); if ((bytes & TIOCM_DSR) != pser_inf->event_dsr) @@ -985,7 +998,8 @@ pser_inf->event_dsr = bytes & TIOCM_DSR; if (pser_inf->wait_mask & SERIAL_EV_DSR) { - DEBUG_SERIAL(("event -> SERIAL_EV_DSR %s\n", (bytes & TIOCM_DSR) ? "ON" : "OFF")); + DEBUG_SERIAL(("event -> SERIAL_EV_DSR %s\n", + (bytes & TIOCM_DSR) ? "ON" : "OFF")); *result |= SERIAL_EV_DSR; ret = True; } @@ -996,7 +1010,8 @@ pser_inf->event_cts = bytes & TIOCM_CTS; if (pser_inf->wait_mask & SERIAL_EV_CTS) { - DEBUG_SERIAL((" EVENT-> SERIAL_EV_CTS %s\n", (bytes & TIOCM_CTS) ? "ON" : "OFF")); + DEBUG_SERIAL((" EVENT-> SERIAL_EV_CTS %s\n", + (bytes & TIOCM_CTS) ? "ON" : "OFF")); *result |= SERIAL_EV_CTS; ret = True; }