3 /* Copyright (C) 2002 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
18 // Needed for bzero, implicitly used by FD_ZERO on IRIX 5.2
22 //#include <gcj/cni.h>
23 #include <gnu/java/nio/SelectorImpl.h>
24 #include <java/io/IOException.h>
27 helper_put_filedescriptors (jintArray java_fd_array
, fd_set
& fds
, int& max_fd
)
32 java_fds
= elements (java_fd_array
);
34 for (counter
= 0; counter
< JvGetArrayLength (java_fd_array
); counter
++)
36 FD_SET (java_fds
[counter
], &fds
);
38 if (java_fds
[counter
] > max_fd
)
40 max_fd
= java_fds
[counter
];
46 helper_get_filedescriptors (jintArray
& java_fd_array
, fd_set fds
)
51 jintArray new_array_fds
;
55 java_fds
= elements (java_fd_array
);
57 for (counter
= 0; counter
< JvGetArrayLength (java_fd_array
); counter
++)
59 if (FD_ISSET (java_fds
[counter
], &fds
))
65 new_array_fds
= JvNewIntArray (counter_fds
);
66 new_data_fds
= elements (new_array_fds
);
68 for (counter
= 0; counter
< JvGetArrayLength (java_fd_array
); counter
++)
70 if (FD_ISSET (java_fds
[counter
], &fds
))
72 new_data_fds
[counter
] = java_fds
[counter
];
76 java_fd_array
= new_array_fds
;
80 gnu::java::nio::SelectorImpl::java_do_select (jintArray read
, jintArray write
,
81 jintArray except
, jlong timeout
)
88 struct timeval real_time_data
;
89 struct timeval
*time_data
= NULL
;
91 real_time_data
.tv_sec
= 0;
92 real_time_data
.tv_usec
= timeout
;
94 // If not legal timeout value is given, use NULL.
95 // This means an infinite timeout.
98 time_data
= &real_time_data
;
101 // Reset all fd_set structures
103 FD_ZERO (&write_fds
);
104 FD_ZERO (&except_fds
);
106 // Fill the fd_set data structures for the _Jv_select() call.
107 helper_put_filedescriptors (read
, read_fds
, max_fd
);
108 helper_put_filedescriptors (write
, write_fds
, max_fd
);
109 helper_put_filedescriptors (except
, except_fds
, max_fd
);
111 // Actually do the select
112 result
= _Jv_select (max_fd
+ 1, &read_fds
, &write_fds
, &except_fds
, time_data
);
116 char* strerr
= strerror (errno
);
117 throw new ::java::io::IOException (JvNewStringUTF (strerr
));
120 // Set the file descriptors according to the values returned from select().
121 helper_get_filedescriptors (read
, read_fds
);
122 helper_get_filedescriptors (write
, write_fds
);
123 helper_get_filedescriptors (except
, except_fds
);