Updated to 0.05 - cleaner, more informative error handling.

This commit is contained in:
Albert Zeyer
2011-04-14 13:02:23 +02:00
parent 6e1f784b41
commit 30eb1cc7ed
5 changed files with 40 additions and 36 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ You need the following installed:
Perl
Debian/Ubuntu users need:
libssl-dev libcrypt-openssl-rsa-perl libao2 libao-dev2 libio-socket-inet6-perl
libssl-dev libcrypt-openssl-rsa-perl libao2 libao-dev2 libio-socket-inet6-perl libwww-perl avahi-utils
Perl modules (install from CPAN if needed):
HTTP::Message
+1 -1
View File
@@ -1,4 +1,4 @@
CFLAGS = `pkg-config --cflags --libs ao openssl`
hairtunes: hairtunes.c alac.c
gcc hairtunes.c alac.c -D__i386 -lm $(CFLAGS) -o hairtunes
gcc hairtunes.c alac.c -lm $(CFLAGS) -o hairtunes
+9 -4
View File
@@ -1,7 +1,7 @@
Shairport v0.03
Shairport v0.05
==============
James Laird <jhl@mafipulation.org>
April 11, 2011
April 13, 2011
What it is
----------
@@ -42,5 +42,10 @@ Changelog
bugfix: libao compatibility
0.03 April 11, 2011
bugfix: ipv6 didn't work -
IO::Socket::INET6 is required too
IO::Socket::INET6 is required too
0.04 April 12, 2011
cross-platform count_leading_zeros under GCC -
will now compile cleanly on ARM and other platforms
0.05 April 13, 2011
error-handling cleanup in the Perl script
including more meaningful error messages, based on common problems seen
+2 -10
View File
@@ -218,18 +218,10 @@ static int count_leading_zeros(int32_t input)
}
return i;
}
#elif defined(__GNUC__) && (defined(_X86) || defined(__i386) || defined(i386))
/* for some reason the unrolled version (below) is
* actually faster than this. yay intel!
*/
#elif defined(__GNUC__)
static int count_leading_zeros(int input)
{
int output = 0;
if (!input) return 32;
__asm("bsr %1, %0\n"
: "=r" (output)
: "r" (input));
return (0x1f - output);
return __builtin_clz(input);
}
#elif defined(_MSC_VER) && defined(_M_IX86)
static int count_leading_zeros(int input)
+27 -20
View File
@@ -58,18 +58,11 @@ sub POPE {
$SIG{PIPE} = \&POPE;
my $avahi_publish = fork();
if ($avahi_publish==0) {
exec 'avahi-publish-service',
join('', map { sprintf "%02X", $_ } @hw_addr) . "\@$apname",
"_raop._tcp",
"5000",
"tp=UDP","sm=false","sv=false","ek=1","et=0,1","cn=0,1","ch=2","ss=16","sr=44100","pw=false","vn=3","txtvers=1";
}
our $avahi_publish;
sub REAP {
if ($avahi_publish == waitpid(-1, WNOHANG)) {
die("Avahi publishing failed!");
die("Avahi publishing failed! Do you have avahi-publish-service on your PATH?");
}
printf("***CHILD EXITED***\n");
$SIG{CHLD} = \&REAP;
@@ -81,8 +74,21 @@ my %conns;
$SIG{TERM} = $SIG{INT} = sub {
map { eval { kill $_->{decoder_pid} } } keys %conns;
kill 9, $avahi_publish;
exit(0);
exit 0;
};
$SIG{__DIE__} = sub {
map { eval { kill $_->{decoder_pid} } } keys %conns;
kill 9, $avahi_publish;
};
$avahi_publish = fork();
if ($avahi_publish==0) {
exec 'avahi-publish-service',
join('', map { sprintf "%02X", $_ } @hw_addr) . "\@$apname",
"_raop._tcp",
"5000",
"tp=UDP","sm=false","sv=false","ek=1","et=0,1","cn=0,1","ch=2","ss=16","sr=44100","pw=false","vn=3","txtvers=1";
}
my $airport_pem = join '', <DATA>;
my $rsa = Crypt::OpenSSL::RSA->new_private_key($airport_pem) || die;
@@ -90,23 +96,24 @@ my $rsa = Crypt::OpenSSL::RSA->new_private_key($airport_pem) || die;
my $listen;
{
eval {
$listen = new IO::Socket::INET6(Listen => 1,
local $SIG{__DIE__};
$listen = new IO::Socket::INET6(Listen => 1,
Domain => AF_INET6,
LocalPort => 5000,
ReuseAddr => 1,
Proto => 'tcp');
};
if ($@) {
print "**************************************\n\n",
"* IO::Socket::INET6 not present! *\n",
"* Install this if iTunes won't play. *\n",
"**************************************\n\n";
$listen = new IO::Socket::INET(Listen => 1,
LocalPort => 5000,
ReuseAddr => 1,
Proto => 'tcp');
print "**************************************\n",
"* IO::Socket::INET6 not present! *\n",
"* Install this if iTunes won't play. *\n",
"**************************************\n\n";
}
$listen ||= new IO::Socket::INET(Listen => 1,
LocalPort => 5000,
ReuseAddr => 1,
Proto => 'tcp');
}
die "Can't listen on port 5000: $!" unless $listen;