Skip to content

Commit

Permalink
close the underlying stream as early as possible and so notify the
Browse files Browse the repository at this point in the history
NET layer
  • Loading branch information
faizshukri committed Jun 1, 2012
1 parent ad60e18 commit 2c230fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
13 changes: 6 additions & 7 deletions ext/mysqlnd/mysqlnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1849,8 +1849,9 @@ MYSQLND_METHOD(mysqlnd_conn_data, send_close)(MYSQLND_CONN_DATA * const conn TSR
DBG_INF("Connection clean, sending COM_QUIT");
if (net_stream) {
ret = conn->m->simple_command(conn, COM_QUIT, NULL, 0, PROT_LAST, TRUE, TRUE TSRMLS_CC);
net->data->m.close_stream(net, conn->stats, conn->error_info TSRMLS_CC);
}
/* Do nothing */
CONN_SET_STATE(conn, CONN_QUIT_SENT);
break;
case CONN_SENDING_LOAD_DATA:
/*
Expand All @@ -1866,23 +1867,21 @@ MYSQLND_METHOD(mysqlnd_conn_data, send_close)(MYSQLND_CONN_DATA * const conn TSR
Do nothing, the connection will be brutally closed
and the server will catch it and free close from its side.
*/
/* Fall-through */
case CONN_ALLOCED:
/*
Allocated but not connected or there was failure when trying
to connect with pre-allocated connect.
Fall-through
*/
CONN_SET_STATE(conn, CONN_QUIT_SENT);
net->data->m.close_stream(net, conn->stats, conn->error_info TSRMLS_CC);
/* Fall-through */
case CONN_QUIT_SENT:
/* The user has killed its own connection */
break;
}
/*
We hold one reference, and every other object which needs the
connection does increase it by 1.
*/
CONN_SET_STATE(conn, CONN_QUIT_SENT);
net->data->m.close_stream(net, conn->stats, conn->error_info TSRMLS_CC);

DBG_RETURN(ret);
}
Expand Down
23 changes: 13 additions & 10 deletions ext/mysqlnd/mysqlnd_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,19 @@ MYSQLND_METHOD(mysqlnd_net, post_connect_set_opt)(MYSQLND_NET * const net,
{
php_stream * net_stream = net->data->m.get_stream(net TSRMLS_CC);
DBG_ENTER("mysqlnd_net::post_connect_set_opt");
if (net->data->options.timeout_read) {
struct timeval tv;
DBG_INF_FMT("setting %u as PHP_STREAM_OPTION_READ_TIMEOUT", net->data->options.timeout_read);
tv.tv_sec = net->data->options.timeout_read;
tv.tv_usec = 0;
php_stream_set_option(net_stream, PHP_STREAM_OPTION_READ_TIMEOUT, 0, &tv);
}
if (net_stream) {
if (net->data->options.timeout_read) {
struct timeval tv;
DBG_INF_FMT("setting %u as PHP_STREAM_OPTION_READ_TIMEOUT", net->data->options.timeout_read);
tv.tv_sec = net->data->options.timeout_read;
tv.tv_usec = 0;
php_stream_set_option(net_stream, PHP_STREAM_OPTION_READ_TIMEOUT, 0, &tv);
}

if (!memcmp(scheme, "tcp://", sizeof("tcp://") - 1)) {
/* TCP -> Set TCP_NODELAY */
mysqlnd_set_sock_no_delay(net_stream TSRMLS_CC);
if (!memcmp(scheme, "tcp://", sizeof("tcp://") - 1)) {
/* TCP -> Set TCP_NODELAY */
mysqlnd_set_sock_no_delay(net_stream TSRMLS_CC);
}
}

DBG_VOID_RETURN;
Expand Down Expand Up @@ -1051,6 +1053,7 @@ static php_stream *
MYSQLND_METHOD(mysqlnd_net, get_stream)(const MYSQLND_NET * const net TSRMLS_DC)
{
DBG_ENTER("mysqlnd_net::get_stream");
DBG_INF_FMT("%p", net? net->data->stream:NULL);
DBG_RETURN(net? net->data->stream:NULL);
}
/* }}} */
Expand Down

0 comments on commit 2c230fb

Please sign in to comment.