public function __construct($config_data) { if (!isset($config_data['host']) || !isset($config_data['port']) || !isset($config_data['username']) || !isset($config_data['password'])) { throw new MonetraException(__('Monetra hostname, port, username and password must be provided.')); } if (!M_InitEngine()) { throw new MonetraException(__('Could not initialize engine.')); } $this->conn = M_InitConn(); if (!M_SetBlocking($this->conn, 1)) { throw new MonetraException(__('Could not set blocking mode.')); } if (!M_SetSSL($this->conn, $config_data['host'], $config_data['port'])) { throw new MonetraException(__('Could not set method to SSL.')); } $this->username = $config_data['username']; $this->password = $config_data['password']; }
if (!M_SetIP($conn, $MYHOST, $MYPORT)) { echo "Could not set method to IP\r\n"; /* Free memory associated with conn */ M_DestroyConn($conn); return; } } else { echo "Invalid method '" . $MYMETHOD . "' specified!\r\n"; /* Free memory associated with conn */ M_DestroyConn($conn); return; } } /* Set to blocking mode, means we do not have to * do a M_Monitor() loop, M_TransSend() will do this for us */ if (!M_SetBlocking($conn, 1)) { echo "Could not set non-blocking mode\r\n"; /* Free memory associated with conn */ M_DestroyConn($conn); return; } /* Set a timeout to be appended to each transaction * sent to Monetra */ if (!M_SetTimeout($conn, 30)) { echo "Could not set timeout\r\n"; /* Free memory associated with conn */ M_DestroyConn($conn); return; } echo "Connecting to {$MYHOST}:{$MYPORT} using {$MYMETHOD}..."; /* Connect to Monetra */
function MCVE_SetBlocking(&$conn, $tf) { return M_SetBlocking($conn, $tf); }
function M_verifyping(&$conn) { $max_ping_time = 5; $blocking = $conn['blocking']; M_SetBlocking($conn, false); $id = M_TransNew($conn); M_TransKeyVal($conn, $id, "action", "ping"); if (!M_TransSend($conn, $id)) { M_DeleteTrans($conn, $id); return false; } $lasttime = time(); while (M_CheckStatus($conn, $id) == M_PENDING && time() - $lasttime <= $max_ping_time) { $wait_time_ms = ($max_ping_time - (time() - $lasttime)) * 1000; if ($wait_time_ms < 0) { $wait_time_ms = 0; } if ($wait_time_ms > $max_ping_time * 1000) { $wait_time_ms = $max_ping_time * 1000; } if (!M_Monitor($conn, $wait_time_ms)) { break; } } M_SetBlocking($conn, $blocking); $status = M_CheckStatus($conn, $id); M_DeleteTrans($conn, $id); if ($status != M_DONE) { return false; } return true; }