core :: Sys :: intern_poll
private fun intern_poll(in_fds: Array[Int], out_fds: Array[Int]): nullable Int
import Array[Int].length, Array[Int].[], Int.as(nullable Int) `{
#ifndef _WIN32
// FIXME use a higher level abstraction to support WIN32
int in_len, out_len, total_len;
struct pollfd *c_fds;
int i;
int first_polled_fd = -1;
int result;
in_len = (int)Array_of_Int_length( in_fds );
out_len = (int)Array_of_Int_length( out_fds );
total_len = in_len + out_len;
c_fds = malloc( sizeof(struct pollfd) * total_len );
/* input streams */
for ( i=0; i<in_len; i ++ ) {
int fd = (int)Array_of_Int__index( in_fds, i );
c_fds[i].fd = fd;
c_fds[i].events = POLLIN;
}
/* output streams */
for ( i=0; i<out_len; i ++ ) {
int fd = (int)Array_of_Int__index( out_fds, i );
c_fds[i].fd = fd;
c_fds[i].events = POLLOUT;
}
/* poll all fds, unlimited timeout */
result = poll( c_fds, total_len, -1 );
if ( result > 0 ) {
/* analyse results */
for ( i=0; i<total_len; i++ )
if ( c_fds[i].revents & c_fds[i].events || /* awaited event */
c_fds[i].revents & POLLHUP ) /* closed */
{
first_polled_fd = c_fds[i].fd;
break;
}
return Int_as_nullable( first_polled_fd );
}
else if ( result < 0 )
fprintf( stderr, "Error in Stream:poll: %s\n", strerror( errno ) );
#endif
return null_Int();
`}
lib/core/file.nit:1633,2--1685,3