lib/file: revamp `poll_in` to use in `FileReader`
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 27 Jul 2015 17:00:45 +0000 (13:00 -0400)
committeralexis laf <xymus@tolkien.info.uqam.ca>
Wed, 29 Jul 2015 17:05:36 +0000 (13:05 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/standard/file.nit

index 849b4e7..e5fc85b 100644 (file)
@@ -176,6 +176,20 @@ class FileReader
                        end_reached = true
                end
        end
+
+       redef fun poll_in
+       do
+               var res = native_poll_in(fd)
+               if res == -1 then
+                       last_error = new IOError(errno.to_s)
+                       return false
+               else return res > 0
+       end
+
+       private fun native_poll_in(fd: Int): Int `{
+               struct pollfd fds = {fd, POLLIN, 0};
+               return poll(&fds, 1, 0);
+       `}
 end
 
 # `Stream` that can write to a File
@@ -305,16 +319,6 @@ class Stdin
                path = "/dev/stdin"
                prepare_buffer(1)
        end
-
-       redef fun poll_in `{
-               struct pollfd fd = {0, POLLIN, 0};
-               int res = poll(&fd, 1, 0);
-               if (res == -1) {
-                       perror("Error poll stdin");
-                       exit(EXIT_FAILURE);
-               }
-               return res > 0;
-       `}
 end
 
 # Standard output stream.