Revert 67496 as it makes running Paint.NET impossible
[mono.git] / support / serial.c
index dacd5979c58be15576136d66f249c684fe9f274f..34d3943142d064db85829fb41129aef88ee0092d 100644 (file)
 #include <string.h>
 #include <sys/poll.h>
 #include <sys/ioctl.h>
+#include <errno.h>
 
 #include <glib.h>
 
+/* This is for FIONREAD on solaris */
+#if defined(sun)
+#include <sys/filio.h>
+#endif
+
 /* This is a copy of System.IO.Ports.Handshake */
 typedef enum {
        NoneHandshake = 0,
@@ -113,13 +119,11 @@ discard_buffer (int fd, gboolean input)
 }
 
 gint32
-get_bytes_in_buffer (int fd, gboolean input, gint32 *error)
+get_bytes_in_buffer (int fd, gboolean input)
 {
        gint32 retval;
 
-       *error = 0;
        if (ioctl (fd, input ? FIONREAD : TIOCOUTQ, &retval) == -1) {
-               *error = -1;
                return -1;
        }
 
@@ -319,7 +323,7 @@ set_signal (int fd, MonoSerialSignal signal, gboolean value)
 }
 
 gboolean
-poll_serial (int fd, gint32 *error)
+poll_serial (int fd, gint32 *error, int timeout)
 {
        struct pollfd pinfo;
        
@@ -329,7 +333,10 @@ poll_serial (int fd, gint32 *error)
        pinfo.events = POLLIN;
        pinfo.revents = 0;
 
-       if (poll (&pinfo, 1, 0) == -1) {
+       if (poll (&pinfo, 1, timeout) == -1) {
+               /* EINTR is an OK condition, we should not throw in the upper layer an IOException */
+               if (errno == EINTR)
+                       return FALSE;
                *error = -1;
                return FALSE;
        }