diff --git a/html/lib/sysVcom.php b/html/lib/sysVcom.php new file mode 100644 index 0000000..c4e1c2d --- /dev/null +++ b/html/lib/sysVcom.php @@ -0,0 +1,227 @@ +0 for a specific message ID. + */ +function IPC_rcv( $queue, $rqd_msg_id, &$msgArr, $bBlock = true ){ + + $message = ''; + $received_message_type = 0; + + while(true){ + + global $g_max_rcv; + + $flags = 0; + if(!$bBlock){ + $flags = MSG_IPC_NOWAIT; + } + if( FALSE === msg_receive( $queue, $rqd_msg_id, $received_message_type, $g_max_rcv, $message, true, $flags, $error_code ) ){ + if(!$bBlock && $error_code==MSG_ENOMSG){ + return 0; + } + //code 7 when g_max_rcv is too small + throw new Exception("Failed to rcv message err = $error_code"); + } + + //echo "Got msg part " . substr( $message, 0, 20 ) . "\n\n"; + + $d_meta = substr( $message, 0, 2 ); + $message = substr( $message, 2 ); + + if( $msgArr!=null && array_key_exists( $received_message_type, $msgArr) ){ + $msgArr[ $received_message_type ]['msg'] .= $message; + + }else{ + $msgArr=array(); + $msgArr[ $received_message_type ] = array( 'final' => false, 'msg' => $message ); + } + + if($d_meta=='f:'){ + // final message part + $msgArr[ $received_message_type ]['final'] = true; + break; + } + + } + + return $received_message_type; + +} + + +/** + * Send a data string of any length. + * + * */ +function IPC_send( $queue, $caller_id, $str_data ){ + + //print_r( msg_stat_queue($queue) ); + + global $procName; + global $g_k_caller; + global $g_k_reply; + global $g_max_data; + + $d_meta = null; + $chunk_cnt = 0; + + if( strlen($str_data) > $g_max_data ){ + //split the data into chunks + $chunk_cnt = intdiv( strlen($str_data), $g_max_data ); + $d_meta = "p:"; //partial data - many calls + } + + $str_chunk = null; + while( $chunk_cnt>=0 ){ + + if($chunk_cnt>0){ + $str_chunk = substr( $str_data, 0, $g_max_data ); + $str_data = substr( $str_data, $g_max_data ); + }else{ + $d_meta = "f:"; //'final' part of data + $str_chunk = $str_data; + } + + //echo "send($caller_id) len = ".strlen($d_meta.$str_chunk)."\n"; + + $error_code = 0; + if( FALSE === msg_send( $queue, $caller_id, $d_meta.$str_chunk, true, true, $error_code ) ){ + //code 22 when the message is too large + throw new Exception("Failed to send message err = $error_code"); + } + $chunk_cnt--; + if($chunk_cnt==0){ + $d_meta = "f:"; //final data chunk + } + } + +} + +?> diff --git a/html/lib/time.php b/html/lib/time.php new file mode 100644 index 0000000..644a8cd --- /dev/null +++ b/html/lib/time.php @@ -0,0 +1,18 @@ +