1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
| <!-- Used for CLI -->
#!C:\UniServer\usr\local\php\php.exe -q
<?php
// $test.php module example
$nmodule = 'module';
// client state
define ("STATE_BEGIN", 0);
define ("STATE_SESSION_OPEN", 1);
define ("STATE_TEST_MODULE", 2);
define ("STATE_TEST_SQL", 3);
define ("STATE_TEST_INSERT", 4);
define ("STATE_SESSION_CLOSE", 5);
define ("STATE_END", 6);
// The socket protocol
define ("NET_ADDR_UDP", 17);
define ("NET_ADDR_TCP", 6);
// The socket family
define ("NET_ADDR_UNSPEC", 0);
define ("NET_ADDR_UNIX", 1);
define ("NET_ADDR_INET", 2);
define ("NET_ADDR_INET6", 26);
/* module net client initialize */
$server_addr = "192.168.1.42";
$server_port = "5432";
$family = NET_ADDR_INET;
$protocol = NET_ADDR_UDP;
/* module nt client finalize */
$rval_net_client_finalize = 0;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional">
<html>
<head>
<title>module example</title>
<style>
*{font-family:verdana; font-size:12px;}
</style>
</head>
<body>
<?php
// Test if extension is loaded
function initialisation($nmodule)
{
if(!extension_loaded($nmodule))
{
die($nmodule . " extension is not available, please compile it.\n");
}
$functions = get_extension_funcs($nmodule);
echo "Functions available in the " . $nmodule . " extension :<br>";
foreach($functions as $func)
{
echo $func."<br>";
}
echo "<br>";
}
// Run a module test
function run_test($net_client)
{
$instance = 0;
$state = STATE_BEGIN;
$session_id = 0;
for(;;)
{
switch ($state)
{
case STATE_BEGIN:
echo "<br><br>>> BEGIN";
$state = STATE_SESSION_OPEN;
case STATE_SESSION_OPEN:
echo "<br>>> session_open";
$instance = module_session_open($net_client, NULL);
echo " - instance : " . $instance;
break;
case STATE_TEST_MODULE:
echo "<br>>> test_module";
$instance = module_test_module($net_client, NULL, 100);
echo " - instance : " . $instance;
break;
case STATE_TEST_SQL:
echo "<br>>> test_sql";
$instance = module_test_sql($net_client, NULL, "joe");
echo " - instance : " . $instance;
break;
case STATE_TEST_INSERT:
echo "<br>>> test_insert";
$instance = module_test_insert($net_client, NULL, 1, 2, "test");
echo " - instance : " . $instance;
break;
case STATE_SESSION_CLOSE:
echo "<br>>> session_close";
$instance = module_session_close($net_client, NULL);
echo " - instance : " . $instance;
break;
case STATE_END:
echo "<br>>> END";
break;
}
if ($state == STATE_END)
{
break;
}
$next = 0;
while ($next == 0)
{
module_net_client_update($net_client, 1);
switch ($state)
{
case STATE_BEGIN:
break;
case STATE_SESSION_OPEN:
{
echo "<br>";
$session_id = module_session_open_result($instance);
/*if ($session_id != 0)
{
echo "module_session_open_result = " . $session_id;
}*/
if (module_net_func_is_finished($instance) == TRUE)
{
}
$state = STATE_END;
$next = 1;
}
break;
case STATE_END:
$next = 1;
break;
}
}
module_net_client_end_function($net_client, $instance);
module_net_client_set_session_id($net_client, $session_id);
}
}
initialisation($nmodule);
/* module net client initialize */
echo "<br><b>Module net client initialize : </b>";
$net_client = module_net_client_initialize($server_addr, $server_port, $family, $protocol);
echo " - net_client : " . $net_client;
run_test($net_client);
/* module net client finalize */
echo "<br><br><b>Module net client finalize : </b>";
$rval_net_client_finalize = module_net_client_finalize($net_client);
echo $rval_net_client_finalize;
?>
</body>
</html> |
Partager