Skip to content

Instantly share code, notes, and snippets.

@plicease
Last active August 29, 2015 14:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plicease/b51c70df4c516a89912d to your computer and use it in GitHub Desktop.
Save plicease/b51c70df4c516a89912d to your computer and use it in GitHub Desktop.
extract_uv_handle_type.pl
use strict;
use warnings;
use 5.010;
use Convert::Binary::C;
my $c = Convert::Binary::C->new;
$c->Include(qw(
/usr/include
/usr/include/x86_64-linux-gnu/
/usr/include/linux
));
$c->Define(qw( __x86_64__ __unix__ __POSIX__ ));
$c->parse('typedef unsigned long int size_t;');
$c->parse_file('uv.h');
foreach my $enum ($c->enum)
{
next unless defined $enum->{enumerators}->{UV_UNKNOWN_HANDLE};
foreach my $key (sort { $enum->{enumerators}->{$a} <=> $enum->{enumerators}->{$b} } keys %{ $enum->{enumerators} })
{
my $value = $enum->{enumerators}->{$key};
say "$key = $value";
}
}
@plicease
Copy link
Author

@jberger this extracts the uv_handle_type enum values. It uses Convert::Binary::C to parse the uv.h file pretty accurately. (CBC has one failing pod test). May need to adjust the includes and defines if you aren't on 64bit Debian. If you don't have the patiences to figure out the correct settings you can also crib off of the values that I got:

UV_UNKNOWN_HANDLE = 0
UV_ASYNC = 1
UV_CHECK = 2
UV_FS_EVENT = 3
UV_FS_POLL = 4
UV_HANDLE = 5
UV_IDLE = 6
UV_NAMED_PIPE = 7
UV_POLL = 8
UV_PREPARE = 9
UV_PROCESS = 10
UV_STREAM = 11
UV_TCP = 12
UV_TIMER = 13
UV_TTY = 14
UV_UDP = 15
UV_SIGNAL = 16
UV_FILE = 17
UV_HANDLE_TYPE_MAX = 18

@jberger
Copy link

jberger commented Jun 10, 2015

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment