#include <sys/filio.h>
#endif
+/* sys/time.h (for timeval) is required when using osx 10.3 (but not 10.4) */
+#ifdef __APPLE__
+#include <sys/time.h>
+#endif
+
/* This is a copy of System.IO.Ports.Handshake */
typedef enum {
NoneHandshake = 0,
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;
}
case Even: /* Even */
newtio.c_cflag &= ~(PARODD);
+ newtio.c_cflag |= (PARENB);
break;
case Mark: /* Mark */
return 1;
}
+void
+breakprop (int fd)
+{
+ tcsendbreak (fd, 0);
+}
+
gboolean
poll_serial (int fd, gint32 *error, int timeout)
{