tweak timeouts

This commit is contained in:
Isaac Connor 2018-01-31 15:51:12 -05:00
parent b390633f70
commit a610d564d1
1 changed files with 9 additions and 6 deletions

View File

@ -3,19 +3,19 @@
$start_time = time(); $start_time = time();
define( 'MSG_TIMEOUT', ZM_WEB_AJAX_TIMEOUT ); define( 'MSG_TIMEOUT', ZM_WEB_AJAX_TIMEOUT/2 );
define( 'MSG_DATA_SIZE', 4+256 ); define( 'MSG_DATA_SIZE', 4+256 );
if ( !($_REQUEST['connkey'] && $_REQUEST['command']) ) { if ( !($_REQUEST['connkey'] && $_REQUEST['command']) ) {
ajaxError( "Unexpected received message type '$type'" ); ajaxError( "Unexpected received message type '$type'" );
} }
if ( !($socket = @socket_create( AF_UNIX, SOCK_DGRAM, 0 )) ) {
ajaxError( 'socket_create() failed: '.socket_strerror(socket_last_error()) );
}
$key = ftok(ZM_PATH_SOCKS.'/zms-'.sprintf("%06d",$_REQUEST['connkey']).'w.lock', 'Z'); $key = ftok(ZM_PATH_SOCKS.'/zms-'.sprintf("%06d",$_REQUEST['connkey']).'w.lock', 'Z');
$semaphore = sem_get($key,1); $semaphore = sem_get($key,1);
if ( sem_acquire($semaphore,1) !== false ) { if ( sem_acquire($semaphore,1) !== false ) {
if ( !($socket = @socket_create( AF_UNIX, SOCK_DGRAM, 0 )) ) {
ajaxError( 'socket_create() failed: '.socket_strerror(socket_last_error()) );
}
$localSocketFile = ZM_PATH_SOCKS.'/zms-'.sprintf('%06d',$_REQUEST['connkey']).'w.sock'; $localSocketFile = ZM_PATH_SOCKS.'/zms-'.sprintf('%06d',$_REQUEST['connkey']).'w.sock';
if ( file_exists( $localSocketFile ) ) { if ( file_exists( $localSocketFile ) ) {
@ -59,9 +59,12 @@ if ( sem_acquire($semaphore,1) !== false ) {
$remSockFile = ZM_PATH_SOCKS.'/zms-'.sprintf('%06d',$_REQUEST['connkey']).'s.sock'; $remSockFile = ZM_PATH_SOCKS.'/zms-'.sprintf('%06d',$_REQUEST['connkey']).'s.sock';
$max_socket_tries = 10; $max_socket_tries = 10;
// FIXME This should not exceed web_ajax_timeout // FIXME This should not exceed web_ajax_timeout
while ( !file_exists($remSockFile) && $max_socket_tries-- ) { //sometimes we are too fast for our own good, if it hasn't been setup yet give it a second. while ( !file_exists($remSockFile) && $max_socket_tries-- ) { //sometimes we are too fast for our own good, if it hasn't been setup yet give it a second.
// WHY? We will just send another one...
// ANSWER: Because otherwise we get a log of errors logged
//Logger::Debug("$remSockFile does not exist, waiting, current " . (time() - $start_time) . ' seconds' ); //Logger::Debug("$remSockFile does not exist, waiting, current " . (time() - $start_time) . ' seconds' );
usleep(200000); usleep(1000);
} }
if ( !file_exists($remSockFile) ) { if ( !file_exists($remSockFile) ) {