Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Select {
- use NativeCall;
- class Timeval is repr('CStruct') {
- has int64 $.seconds;
- has int64 $.microseconds;
- }
- multi sub select(int64, CArray[int8], Pointer, Pointer, Timeval) is native returns int { * }
- multi sub select (Int $fd, Numeric $timeout = 0) is export {
- my int64 $nfds = $fd;
- my CArray[int8] $readfds = CArray[int8].new;
- $readfds[0] = 0x1 +< ($fd - 1);
- my $tv = Timeval.new(seconds => $timeout.Int, microseconds => 0);
- my $res = select($nfds, $readfds, Pointer, Pointer, $tv);
- return $res;
- }
- }
- ###
- use Test;
- use Select;
- my $fd = 1;
- my $timeout = 5;
- ok(my $res = select($fd, $timeout), 'Called Select');
- warn $res;
Add Comment
Please, Sign In to add comment