Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add read & write timeouts

  • Loading branch information...
commit 05ff9d9de5bb1f33ba7b9b0d9ae312458c98cafa 1 parent ad9066b
@tony2001 authored
Showing with 69 additions and 1 deletion.
  1. +10 −0 amqp.c
  2. +56 −0 amqp_connection.c
  3. +2 −0  amqp_connection.h
  4. +1 −1  php_amqp.h
View
10 amqp.c
@@ -93,6 +93,14 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setVhost, ZEND_SEND_BY_VAL,
ZEND_ARG_INFO(0, vhost)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setReadTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
+ ZEND_ARG_INFO(0, timeout_msec)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setWriteTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
+ ZEND_ARG_INFO(0, timeout_msec)
+ZEND_END_ARG_INFO()
+
/* amqp_queue_class ARG_INFO definition */
ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class__construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
ZEND_ARG_INFO(0, amqp_connection)
@@ -183,6 +191,8 @@ zend_function_entry amqp_connection_class_functions[] = {
PHP_ME(amqp_connection_class, setHost, arginfo_amqp_connection_class_setHost, ZEND_ACC_PUBLIC)
PHP_ME(amqp_connection_class, setPort, arginfo_amqp_connection_class_setPort, ZEND_ACC_PUBLIC)
PHP_ME(amqp_connection_class, setVhost, arginfo_amqp_connection_class_setVhost, ZEND_ACC_PUBLIC)
+ PHP_ME(amqp_connection_class, setReadTimeout, arginfo_amqp_connection_class_setReadTimeout, ZEND_ACC_PUBLIC)
+ PHP_ME(amqp_connection_class, setWriteTimeout, arginfo_amqp_connection_class_setWriteTimeout, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL} /* Must be the last line in amqp_functions[] */
};
View
56 amqp_connection.c
@@ -306,6 +306,62 @@ PHP_METHOD(amqp_connection_class, connect)
/* }}} */
+/* {{{ proto amqp::setReadTimeout()
+set read timeout for the connection */
+PHP_METHOD(amqp_connection_class, setReadTimeout)
+{
+ zval *id;
+ amqp_connection_object *amqp_connection;
+ long timeout = 0;
+ int ret;
+
+ /* Try to pull amqp object out of method params */
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l", &id, amqp_connection_class_entry, &timeout) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ /* Get the connection object out of the store */
+ amqp_connection = (amqp_connection_object *)zend_object_store_get_object(id TSRMLS_CC);
+
+ if (amqp_connection->conn) {
+ ret = amqp_socket_set_read_timeout(amqp_get_sockfd(amqp_connection->conn), timeout);
+ if (!ret) {
+ RETURN_TRUE;
+ }
+ }
+ RETURN_FALSE;
+}
+
+/* }}} */
+
+/* {{{ proto amqp::setWriteTimeout()
+set write timeout for the connection */
+PHP_METHOD(amqp_connection_class, setWriteTimeout)
+{
+ zval *id;
+ amqp_connection_object *amqp_connection;
+ long timeout = 0;
+ int ret;
+
+ /* Try to pull amqp object out of method params */
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l", &id, amqp_connection_class_entry, &timeout) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ /* Get the connection object out of the store */
+ amqp_connection = (amqp_connection_object *)zend_object_store_get_object(id TSRMLS_CC);
+
+ if (amqp_connection->conn) {
+ ret = amqp_socket_set_write_timeout(amqp_get_sockfd(amqp_connection->conn), timeout);
+ if (!ret) {
+ RETURN_TRUE;
+ }
+ }
+ RETURN_FALSE;
+}
+
+/* }}} */
+
/* {{{ proto amqp::disconnect()
destroy amqp connection */
PHP_METHOD(amqp_connection_class, disconnect)
View
2  amqp_connection.h
@@ -42,6 +42,8 @@ PHP_METHOD(amqp_connection_class, setPassword);
PHP_METHOD(amqp_connection_class, setHost);
PHP_METHOD(amqp_connection_class, setPort);
PHP_METHOD(amqp_connection_class, setVhost);
+PHP_METHOD(amqp_connection_class, setReadTimeout);
+PHP_METHOD(amqp_connection_class, setWriteTimeout);
/*
View
2  php_amqp.h
@@ -24,7 +24,7 @@
#ifndef PHP_AMQP_H
#define PHP_AMQP_H
-
+#include <amqp.h>
/* Add pseudo refcount macros for PHP version < 5.3 */
#ifndef Z_REFCOUNT_PP
Please sign in to comment.
Something went wrong with that request. Please try again.