Skip to content

Commit

Permalink
Fix socket timeout error when connecting over high-latency network
Browse files Browse the repository at this point in the history
  • Loading branch information
pinepain committed Apr 11, 2014
1 parent 5448b7d commit 3317a1b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions amqp_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int php_amqp_connect(amqp_connection_object *connection, int persistent TSRMLS_D
#endif
amqp_rpc_reply_t x;
struct timeval tv = {0};

struct timeval *tv_ptr = &tv;

/* Clean up old memory allocations which are now invalid (new connection) */
if (connection->connection_resource) {
Expand Down Expand Up @@ -176,10 +176,12 @@ int php_amqp_connect(amqp_connection_object *connection, int persistent TSRMLS_D
if (connection->connect_timeout > 0) {
tv.tv_sec = (long int) connection->connect_timeout;
tv.tv_usec = (long int) ((connection->connect_timeout - tv.tv_sec) * 1000000);
} else {
tv_ptr = NULL;
}

/* Try to connect and verify that no error occurred */
if (amqp_socket_open_noblock(connection->connection_resource->socket, connection->host, connection->port, &tv)) {
if (amqp_socket_open_noblock(connection->connection_resource->socket, connection->host, connection->port, tv_ptr)) {
#ifndef PHP_WIN32
/* Start ignoring SIGPIPE */
old_handler = signal(SIGPIPE, SIG_IGN);
Expand Down

0 comments on commit 3317a1b

Please sign in to comment.