Patch amqp_timeout.patch for amqp Bug #61389
Patch version 2012-09-26 10:58 UTC
Return to Bug #61389 |
Download this patch
Patch Revisions:
Developer: mitallast@gmail.com
diff -r -u amqp-1.0.7/amqp-1.0.7/amqp.c amqp-1.0.7-patched/amqp-1.0.7/amqp.c
--- amqp-1.0.7/amqp-1.0.7/amqp.c 2012-09-10 19:56:30.000000000 +0400
+++ amqp-1.0.7-patched/amqp-1.0.7/amqp.c 2012-09-26 14:18:41.000000000 +0400
@@ -115,6 +115,14 @@
ZEND_ARG_INFO(0, port)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
+ ZEND_ARG_INFO(0, port)
+ZEND_END_ARG_INFO()
+
+
ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getVhost, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
ZEND_END_ARG_INFO()
@@ -386,6 +394,9 @@
PHP_ME(amqp_connection_class, getPort, arginfo_amqp_connection_class_getPort, ZEND_ACC_PUBLIC)
PHP_ME(amqp_connection_class, setPort, arginfo_amqp_connection_class_setPort, ZEND_ACC_PUBLIC)
+
+ PHP_ME(amqp_connection_class, getTimeout, arginfo_amqp_connection_class_getTimeout, ZEND_ACC_PUBLIC)
+ PHP_ME(amqp_connection_class, setTimeout, arginfo_amqp_connection_class_setTimeout, ZEND_ACC_PUBLIC)
PHP_ME(amqp_connection_class, getVhost, arginfo_amqp_connection_class_getVhost, ZEND_ACC_PUBLIC)
PHP_ME(amqp_connection_class, setVhost, arginfo_amqp_connection_class_setVhost, ZEND_ACC_PUBLIC)
@@ -659,6 +670,7 @@
PHP_INI_ENTRY("amqp.host", DEFAULT_HOST, PHP_INI_ALL, NULL)
PHP_INI_ENTRY("amqp.vhost", DEFAULT_VHOST, PHP_INI_ALL, NULL)
PHP_INI_ENTRY("amqp.port", DEFAULT_PORT, PHP_INI_ALL, NULL)
+ PHP_INI_ENTRY("amqp.timeout", DEFAULT_TIMEOUT, PHP_INI_ALL, NULL)
PHP_INI_ENTRY("amqp.login", DEFAULT_LOGIN, PHP_INI_ALL, NULL)
PHP_INI_ENTRY("amqp.password", DEFAULT_PASSWORD, PHP_INI_ALL, NULL)
PHP_INI_ENTRY("amqp.auto_ack", DEFAULT_AUTOACK, PHP_INI_ALL, NULL)
diff -r -u amqp-1.0.7/amqp-1.0.7/amqp_connection.c amqp-1.0.7-patched/amqp-1.0.7/amqp_connection.c
--- amqp-1.0.7/amqp-1.0.7/amqp_connection.c 2012-09-10 19:56:30.000000000 +0400
+++ amqp-1.0.7-patched/amqp-1.0.7/amqp_connection.c 2012-09-26 14:38:20.000000000 +0400
@@ -148,6 +148,14 @@
}
amqp_set_sockfd(connection->connection_resource->connection_state, connection->connection_resource->fd);
+
+ if(connection->timeout > 0){
+ struct timeval tv;
+ tv.tv_sec = connection->timeout;
+ tv.tv_usec = 0;
+ setsockopt(connection->connection_resource->fd, SOL_SOCKET, SO_RCVTIMEO, (void *)&tv, sizeof(struct timeval));
+ }
+
amqp_rpc_reply_t x = amqp_login(
connection->connection_resource->connection_state,
@@ -372,7 +380,7 @@
/* {{{ proto AMQPConnection::__construct([array optional])
- * The array can contain 'host', 'port', 'login', 'password', 'vhost' indexes
+ * The array can contain 'host', 'port', 'login', 'password', 'vhost', 'timeout' indexes
*/
PHP_METHOD(amqp_connection_class, __construct)
{
@@ -465,6 +473,13 @@
convert_to_long(*zdata);
connection->port = (size_t)Z_LVAL_PP(zdata);
}
+
+ connection->timeout = INI_INT("amqp.timeout");
+
+ if (iniArr && SUCCESS == zend_hash_find(HASH_OF (iniArr), "timeout", sizeof("timeout"), (void*)&zdata)) {
+ convert_to_long(*zdata);
+ connection->timeout = (size_t)Z_LVAL_PP(zdata);
+ }
}
/* }}} */
@@ -935,6 +950,72 @@
}
/* }}} */
+/* {{{ proto amqp::getPort()
+get the timeout in seconds*/
+PHP_METHOD(amqp_connection_class, getTimeout)
+{
+ zval *id;
+ amqp_connection_object *connection;
+
+ /* Get the port from the method params */
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &id, amqp_connection_class_entry) == FAILURE) {
+ return;
+ }
+
+ /* Get the connection object out of the store */
+ connection = (amqp_connection_object *)zend_object_store_get_object(id TSRMLS_CC);
+
+ /* Copy the port to the amqp object */
+ RETURN_LONG(connection->timeout);
+}
+/* }}} */
+
+
+/* {{{ proto amqp::setPort(int timeout)
+set the timeout in seconds*/
+PHP_METHOD(amqp_connection_class, setTimeout)
+{
+ zval *id;
+ amqp_connection_object *connection;
+ zval *zvalTimeout;
+ int timeout;
+
+ /* Get the port from the method params */
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oz", &id, amqp_connection_class_entry, &zvalTimeout) == FAILURE) {
+ return;
+ }
+
+ /* Parse out the port*/
+ switch (Z_TYPE_P(zvalTimeout)) {
+ case IS_DOUBLE:
+ timeout = (int)Z_DVAL_P(zvalTimeout);
+ break;
+ case IS_LONG:
+ timeout = (int)Z_LVAL_P(zvalTimeout);
+ break;
+ case IS_STRING:
+ convert_to_long(zvalTimeout);
+ timeout = (int)Z_LVAL_P(zvalTimeout);
+ break;
+ default:
+ timeout = 0;
+ }
+
+ /* Check the port value */
+ if (timeout < 0 ) {
+ zend_throw_exception(amqp_connection_exception_class_entry, "Invalid timeout given. Value must be equals or greather than 0.", 0 TSRMLS_CC);
+ return;
+ }
+
+ /* Get the connection object out of the store */
+ connection = (amqp_connection_object *)zend_object_store_get_object(id TSRMLS_CC);
+
+ /* Copy the port to the amqp object */
+ connection->timeout = timeout;
+
+ RETURN_TRUE;
+}
+/* }}} */
/*
*Local variables:
diff -r -u amqp-1.0.7/amqp-1.0.7/amqp_connection.h amqp-1.0.7-patched/amqp-1.0.7/amqp_connection.h
--- amqp-1.0.7/amqp-1.0.7/amqp_connection.h 2012-09-10 19:56:30.000000000 +0400
+++ amqp-1.0.7-patched/amqp-1.0.7/amqp_connection.h 2012-09-26 14:02:18.000000000 +0400
@@ -57,6 +57,8 @@
PHP_METHOD(amqp_connection_class, getVhost);
PHP_METHOD(amqp_connection_class, setVhost);
+PHP_METHOD(amqp_connection_class, getTimeout);
+PHP_METHOD(amqp_connection_class, setTimeout);
/*
*Local variables:
Only in amqp-1.0.7-patched/amqp-1.0.7: nbproject
diff -r -u amqp-1.0.7/amqp-1.0.7/php_amqp.h amqp-1.0.7-patched/amqp-1.0.7/php_amqp.h
--- amqp-1.0.7/amqp-1.0.7/php_amqp.h 2012-09-10 19:56:30.000000000 +0400
+++ amqp-1.0.7-patched/amqp-1.0.7/php_amqp.h 2012-09-26 14:16:57.000000000 +0400
@@ -174,6 +174,7 @@
#define DEFAULT_NUM_CONNECTION_CHANNELS 255
#define DEFAULT_PORT "5672" /* default AMQP port */
+#define DEFAULT_TIMEOUT "0" /* default AMQP timeout */
#define DEFAULT_HOST "localhost"
#define DEFAULT_VHOST "/"
#define DEFAULT_LOGIN "guest"
@@ -305,6 +306,7 @@
char *vhost;
int vhost_len;
int port;
+ int timeout;
amqp_connection_resource *connection_resource;
} amqp_connection_object;
Only in amqp-1.0.7-patched/amqp-1.0.7/tests: amqpconnection_getTimeout_int.phpt
Only in amqp-1.0.7-patched/amqp-1.0.7/tests: amqpconnection_setTimeout_int.phpt
|