X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=support%2Fserial.c;h=c0708a11929529d77ef8ae79abbbce521a10e8b7;hb=e698ebe6355598c0a4a52338dd5cacfce2a2d9d7;hp=cfa6ce1672ff106e12623678f81562a8a3a4eb3e;hpb=1dae9b68281fc771df70d35ea15d67a32dd6c7fb;p=mono.git diff --git a/support/serial.c b/support/serial.c index cfa6ce1672f..c0708a11929 100644 --- a/support/serial.c +++ b/support/serial.c @@ -91,38 +91,35 @@ read_serial (int fd, guchar *buffer, int offset, int count) int write_serial (int fd, guchar *buffer, int offset, int count, int timeout) { - struct timeval tmval; - fd_set writefs; + struct pollfd pinfo; guint32 n; - n = count - offset; + pinfo.fd = fd; + pinfo.events = POLLOUT; + pinfo.revents = POLLOUT; + + n = count; - FD_SET(fd, &writefs); - tmval.tv_sec = timeout / 1000; - tmval.tv_usec = (timeout - tmval.tv_sec) * 1000; - while (n > 0) { size_t t; - if (timeout > 0) - { - if (select(fd+1, NULL, &writefs, NULL, &tmval) <= 0 && errno != EINTR) - { + if (timeout != 0) { + int c; + + while ((c = poll (&pinfo, 1, timeout)) == -1 && errno == EINTR) + ; + if (c == -1) return -1; - } } - t = write(fd, buffer + offset, count); - - if (timeout > 0) - { - if (select(fd+1, NULL, &writefs, NULL, &tmval) <= 0 && errno != EINTR) - { - return -1; - } - } + do { + t = write (fd, buffer + offset, n); + } while (t == -1 && errno == EINTR); + if (t < 0) + return -1; + offset += t; n -= t; } @@ -272,6 +269,7 @@ set_attributes (int fd, int baud_rate, MonoParity parity, int dataBits, MonoStop case Even: /* Even */ newtio.c_cflag &= ~(PARODD); + newtio.c_cflag |= (PARENB); break; case Mark: /* Mark */ @@ -399,6 +397,12 @@ set_signal (int fd, MonoSerialSignal signal, gboolean value) return 1; } +void +breakprop (int fd) +{ + tcsendbreak (fd, 0); +} + gboolean poll_serial (int fd, gint32 *error, int timeout) {