Date: Sat Feb 23 16:43:21 CET 2002
User: Derick Rethans
Directory: sapi_srm
Log Message:
[3.50]
- Clean up of SAPI module
- Add debug info to semaphores
- Update version number
Modified files:
sapi_srm/srm.c (version: 1.44)
[FILE: /sapi_srm/srm.c]
--- sapi_srm/srm.c:1.43 Thu Feb 21 19:30:49 2002 GMT
+++ sapi_srm/srm.c Sat Feb 23 14:43:20 2002 GMT
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: cvstemp,v 1.43 2002/02/21 20:30:49 derick Exp $ */
+/* $Id: cvstemp,v 1.44 2002/02/23 15:43:20 derick Exp $ */
#include "php.h"
#include "php_ini.h"
@@ -48,8 +48,8 @@
/* Version is defined here */
#define SRM_SAPI_MAJOR 0
-#define SRM_SAPI_MINOR 1
-#define SRM_SAPI_MICRO 0
+#define SRM_SAPI_MINOR 6
+#define SRM_SAPI_MICRO 1
static ZEND_API zend_op_array* (*old_compile_file)(zend_file_handle* file_handle, int type TSRMLS_DC);
static ZEND_API zend_op_array* srm_compile_file(zend_file_handle*, int TSRMLS_DC);
@@ -116,8 +116,6 @@
static zend_function_entry php_banana_class_functions[] = {
PHP_NAMED_FE(run, php_if_run, NULL)
-// PHP_NAMED_FE(get, php_if_get, NULL)
-// PHP_NAMED_FE(set, php_if_set, NULL)
{NULL, NULL, NULL}
};
@@ -157,7 +155,7 @@
NULL,
NULL,
php_info_srm,
- "0.0.1",
+ "0.6.1",
STANDARD_MODULE_PROPERTIES
};
/* }}} */
@@ -277,6 +275,44 @@
}
/* }}} */
+/* {{{ helper void save_result (handle, result) */
+static void save_result (int handle, srm_event_result *result)
+{
+ /* Cleaning Up */
+ srm_event_dtor (srmapp_pool.data[handle].event);
+
+ /* Added result to queue */
+ srmapp_pool.data[handle].res = result;
+
+ /* Signal that the result is available */
+ srm_fmt_message (LL_DATA, "Event", "%s:%d: /* Signal semaphore that the result available */", __FILE__, __LINE__);
+ sem_post(&srmapp_pool.data[handle].res_sem);
+}
+/* }}} */
+
+/* {{{ helper srm_value* exec_event (handle, event) */
+static srm_value* exec_event (int handle, srm_event *event)
+{
+ srm_value *res_val;
+
+ /* Add message to queue */
+ srmapp_pool.data[handle].event = event;
+ srm_fmt_message (LL_DATA, "Event", "%s:%d: /* Signal semaphore that a message is available */", __FILE__, __LINE__);
+ sem_post(&srmapp_pool.data[handle].msg_sem);
+
+ /* Wait for signal on result to be available */
+ srm_fmt_message (LL_DATA, "Event", "%s:%d: /* Wait for signal on result to be available */", __FILE__, __LINE__);
+ sem_wait(&srmapp_pool.data[handle].res_sem);
+ srm_fmt_message (LL_DATA, "Event", "%s:%d", __FILE__, __LINE__);
+
+ res_val = srmapp_pool.data[handle].res->data;
+ res_val->ref_count++;
+ srm_event_result_dtor(srmapp_pool.data[handle].res);
+
+ return res_val;
+}
+/* }}} */
+
/* {{{ void run (void)
This function is the event handler / dispatcher */
PHP_NAMED_FUNCTION(php_if_run)
@@ -308,11 +344,13 @@
goto abort;
}
+ result = malloc (sizeof (srm_event_result));
+ result->data = srm_value_init();
+
/* Check if we have a special function here */
if (strncmp ("banana_get", function, 11) == 0) {
property = params[0];
- result = malloc (sizeof (srm_event_result));
if (zend_hash_find(Z_OBJPROP_P(object), Z_STRVAL_P(property), Z_STRLEN_P(property) + 1, (void **) &value) == SUCCESS) {
/* Return data */
result->data = zval_to_srmval (*value);
@@ -322,27 +360,21 @@
memset(error_buf, 0, 256);
sprintf (error_buf, "banana::run(): property %s does not exist\n", Z_STRVAL_P(property));
- srm_fmt_message (LL_DATA, "Event", error_buf);
- result->data = srm_value_init();
- VALP_SET_STR(result->data);
- SRMVALP_STR(result->data) = strdup(error_buf);
+ srm_value_free (result->data);
+ SRMVALP_SET_BINSTR (result->data, error_buf, strlen(error_buf), 1);
VALP_SET_WARNING(result->data);
- result->data->value_length = strlen(error_buf);
+
+ srm_fmt_message (LL_DATA, "Event", error_buf);
}
} else if (strncmp ("banana_set", function, 11) == 0) {
property = params[0];
set_value = params[1];
- result = malloc (sizeof (srm_event_result));
- result->data = srm_value_init();
VALP_SET_BOOL(result->data);
+ SRMVALP_BOOL(result->data) =
+ (zend_hash_update(Z_OBJPROP_P(object), Z_STRVAL_P(property), Z_STRLEN_P(property) + 1, (void *) &set_value, sizeof (zval*), NULL) == SUCCESS);
- if (zend_hash_update(Z_OBJPROP_P(object), Z_STRVAL_P(property), Z_STRLEN_P(property) + 1, (void *) &set_value, sizeof (zval*), NULL) == SUCCESS) {
- SRMVALP_BOOL(result->data) = TRUE;
- } else {
- SRMVALP_BOOL(result->data) = FALSE;
- }
} else if (zend_hash_exists (&Z_OBJCE_P(object)->function_table, function, strlen(function) + 1)) {
/* Check if function exists in method table */
@@ -353,14 +385,13 @@
memcpy (Z_STRVAL_P(php_cmd), function, strlen(function));
Z_STRLEN_P(php_cmd) = strlen(function);
+ /* free data stub for result values */
+ srm_value_free (result->data);
+
/* Call the member function */
- result = malloc (sizeof (srm_event_result));
if (call_user_function (NULL, &object, php_cmd, &ret_val, argc, params TSRMLS_CC) == FAILURE) {
/* Add error to return queue */
- result->data = srm_value_init();
- VALP_SET_STR(result->data);
- SRMVALP_STR(result->data) = strdup("Error, screw you!");
- result->data->value_length = strlen("Error, screw you!");
+ SRMVALP_SET_BINSTR(result->data, "Error occured calling function", 30, 1);
srm_fmt_message (LL_DATA, "Event", "Error occured calling PHP function");
} else {
/* Add result to return queue */
@@ -380,15 +411,7 @@
SRMVALP_STR(result->data) = strdup(error_buf);
result->data->value_length = strlen(error_buf);
}
- srmapp_pool.data[handle].res = result;
- srm_fmt_message (LL_DATA, "Event", "%s:%d", __FILE__, __LINE__);
-
- /* Cleaning Up */
- srm_event_dtor (srmapp_pool.data[handle].event);
-
- /* Signal that the result is available */
- srm_fmt_message (LL_DATA, "Event", "%s:%d: /* Signal semaphore that the result available */", __FILE__, __LINE__);
- sem_post(&srmapp_pool.data[handle].res_sem);
+ save_result(handle, result);
}
abort:
result = malloc (sizeof (srm_event_result));
@@ -396,15 +419,7 @@
VALP_SET_BOOL(result->data);
SRMVALP_BOOL(result->data) = TRUE;
- /* Cleaning Up */
- srm_event_dtor (srmapp_pool.data[handle].event);
-
- /* Added result to queue */
- srmapp_pool.data[handle].res = result;
-
- /* Signal that the result is available */
- srm_fmt_message (LL_DATA, "Event", "%s:%d: /* Signal semaphore that the result available */", __FILE__, __LINE__);
- sem_post(&srmapp_pool.data[handle].res_sem);
+ save_result(handle, result);
}
/* }}} */
@@ -492,12 +507,17 @@
static void srmapp_handle_dtor (void *data)
{
srmapp_handle *h;
+ int i,j,k;
h = (srmapp_handle *) data;
/* Mark the slot as free again */
sem_wait (&srmapp_pool.mutex);
srmapp_pool.data[h->id].used = FALSE;
+ sem_getvalue (&srmapp_pool.data[h->id].lock, &i);
+ sem_getvalue (&srmapp_pool.data[h->id].msg_sem, &j);
+ sem_getvalue (&srmapp_pool.data[h->id].res_sem, &k);
+ srm_fmt_message (LL_DATA, "DBG", "Semaphore values: %d %d %d", i, j, k);
sem_destroy (&srmapp_pool.data[h->id].lock);
sem_destroy (&srmapp_pool.data[h->id].msg_sem);
sem_destroy (&srmapp_pool.data[h->id].res_sem);
@@ -535,7 +555,11 @@
zend_alter_ini_entry("max_execution_time", sizeof("max_execution_time"), strdup("0"), sizeof ("0")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
SET_VAR_LONG("__handle", h->id);
- php_execute_script(&file_handle TSRMLS_CC);
+ if (zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 1, &file_handle) == SUCCESS) {
+ srm_fmt_message (LL_DATA, "DBG", "Script ran succesfully");
+ } else {
+ srm_fmt_message (LL_DATA, "DBG", "Script ran UNsuccesfully");
+ }
efree (SG(server_context));
srm_sleep(1, 0); /* Give time to __abort to finish */
php_request_shutdown(NULL);
@@ -666,6 +690,8 @@
return pos;
}
/* }}} */
+
+
/* {{{ function php_function_callback (string command [, mixed param...])
This function is called then a PHP function in the library is requested */
SRM_FUNCTION(php_function_callback)
@@ -839,22 +865,9 @@
event->argc = argc > 2 ? argc - 2 : 0;
srm_fmt_message (LL_DATA, "Event", "%s:%d", __FILE__, __LINE__);
- /* Add message to queue */
- srmapp_pool.data[handle1].event = event;
- /* Signal semaphore that a message is available */
- srm_fmt_message (LL_DATA, "Event", "%s:%d: /* Signal semaphore that a message is available */", __FILE__, __LINE__);
- sem_post(&srmapp_pool.data[handle1].msg_sem);
-
- /* Wait for signal on result to be available */
- srm_fmt_message (LL_DATA, "Event", "%s:%d: /* Wait for signal on result to be available */", __FILE__, __LINE__);
- sem_wait(&srmapp_pool.data[handle1].res_sem);
+ res_val = exec_event (handle1, event);
- srm_fmt_message (LL_DATA, "Event", "%s:%d", __FILE__, __LINE__);
- res_val = srmapp_pool.data[handle1].res->data;
- res_val->ref_count++;
-
- srm_event_result_dtor(srmapp_pool.data[handle1].res);
srm_value_copy (output, res_val);
srm_fmt_message (LL_DATA, "Event", "%s:%d", __FILE__, __LINE__);
}
Received on Sat Feb 23 16:43:34 2002
This archive was generated by hypermail 2.1.8 : Tue Jan 06 2009 - 05:00:03 CET