Major changes to webserver backend. All socket functions are abstracted to allow support for stream_* which seems to be both more widely supported and better at handling blocking and timeouts, at the cost of a small bit of speed. Keep-Alive times out properly and thanks to a bit of IPC code from stream_create_pair(), zombie children are mostly eliminated by proper pcntl_wait() being called when a child shuts down normally, and children die within 0.2sec if the parent receives a SIGTERM or SIGINT, even if the children are waiting on the socket.
/**
* Volume widget presentation code
*
* Greyhound - real web management for Amarok
* Copyright (C) 2008 Dan Fuhry
*
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
*/
var current_volume = 0;
function set_volume_fill(amount)
{
amount = 10 * ( Math.round(amount / 10) );
if ( amount == 0 )
amount = -10;
for ( var i = 0; i <= amount; i += 10 )
{
if ( !$('volbtn_' + i).hasClass('volume_button_active') )
{
$('volbtn_' + i).addClass('volume_button_active');
}
}
for ( ; i <= 100; i += 10 )
{
if ( $('volbtn_' + i).hasClass('volume_button_active') )
{
$('volbtn_' + i).rmClass('volume_button_active');
}
}
}
function volume_over(amount)
{
set_volume_fill(amount);
}
function volume_out()
{
set_volume_fill(current_volume);
}
function set_volume(level)
{
setAjaxLoading();
if ( level == current_volume )
return false;
ajaxGet('/action.json/volume/' + level, function()
{
if ( ajax.readyState == 4 && ajax.status == 200 )
{
unsetAjaxLoading();
var response = (' ' + ajax.responseText).substr(1);
// quickie JSON parser :)
response = eval('(' + response + ')');
// update volume
if ( response.volume != current_volume )
{
set_volume_fill(response.volume);
current_volume = response.volume;
}
}
});
}