diff options
author | Andrey Hristov <andrey@php.net> | 2009-12-15 17:33:06 +0000 |
---|---|---|
committer | Andrey Hristov <andrey@php.net> | 2009-12-15 17:33:06 +0000 |
commit | c101f7f542c3fa3a4af0acdd4ac084a6d56c562b (patch) | |
tree | 6fc25403464224908e38b6b73586194df2e96be9 /ext/mysqlnd/mysqlnd.c | |
parent | 70690e1163c8886cfabca92e6bd8baa0fea807e9 (diff) | |
download | php-git-c101f7f542c3fa3a4af0acdd4ac084a6d56c562b.tar.gz |
Move code out of mysqlnd_conn::connect to mysqlnd_net::connect.
Thus mysqlnd_conn::connect() does less of what it should not do - think
about the transport level.
Diffstat (limited to 'ext/mysqlnd/mysqlnd.c')
-rw-r--r-- | ext/mysqlnd/mysqlnd.c | 81 |
1 files changed, 5 insertions, 76 deletions
diff --git a/ext/mysqlnd/mysqlnd.c b/ext/mysqlnd/mysqlnd.c index b63209dfec..86afee7dd6 100644 --- a/ext/mysqlnd/mysqlnd.c +++ b/ext/mysqlnd/mysqlnd.c @@ -450,12 +450,8 @@ MYSQLND_METHOD(mysqlnd_conn, connect)(MYSQLND *conn, TSRMLS_DC) { char *transport = NULL, *errstr = NULL; - char *hashed_details = NULL; - int transport_len, hashed_details_len, errcode = 0, host_len; - unsigned int streams_options = ENFORCE_SAFE_MODE; - unsigned int streams_flags = STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT; + int transport_len, errcode = 0, host_len; zend_bool self_alloced = FALSE; - struct timeval tv; zend_bool unix_socket = FALSE; const MYSQLND_CHARSET * charset; zend_bool reconnect = FALSE; @@ -535,88 +531,21 @@ MYSQLND_METHOD(mysqlnd_conn, connect)(MYSQLND *conn, PACKET_INIT(auth_packet, PROT_AUTH_PACKET, php_mysql_packet_auth *, FALSE); PACKET_INIT_ALLOCA(ok_packet, PROT_OK_PACKET); - if (conn->persistent) { - hashed_details_len = spprintf(&hashed_details, 0, "%p", conn); - DBG_INF_FMT("hashed_details=%s", hashed_details); - } - CONN_SET_STATE(conn, CONN_ALLOCED); - conn->net->packet_no = conn->net->compressed_envelope_packet_no = 0; - if (conn->net->options.timeout_connect) { - tv.tv_sec = conn->net->options.timeout_connect; - tv.tv_usec = 0; - } if (conn->persistent) { conn->scheme = pestrndup(transport, transport_len, 1); mnd_efree(transport); } else { conn->scheme = transport; } - conn->scheme_len = strlen(conn->scheme); + conn->scheme_len = transport_len; DBG_INF(conn->scheme); - conn->net->stream = php_stream_xport_create(conn->scheme, transport_len, streams_options, streams_flags, - hashed_details, - (conn->net->options.timeout_connect) ? &tv : NULL, - NULL /*ctx*/, &errstr, &errcode); - DBG_INF_FMT("stream=%p", conn->net->stream); - - if (errstr || !conn->net->stream) { - if (hashed_details) { - mnd_efree(hashed_details); - } - errcode = CR_CONNECTION_ERROR; - goto err; - } - - if (hashed_details) { - /* - If persistent, the streams register it in EG(persistent_list). - This is unwanted. ext/mysql or ext/mysqli are responsible to clean, - whatever they have to. - */ - zend_rsrc_list_entry *le; - - if (zend_hash_find(&EG(persistent_list), hashed_details, hashed_details_len + 1, - (void*) &le) == SUCCESS) { - /* - in_free will let streams code skip destructing - big HACK, - but STREAMS suck big time regarding persistent streams. - Just not compatible for extensions that need persistency. - */ - conn->net->stream->in_free = 1; - zend_hash_del(&EG(persistent_list), hashed_details, hashed_details_len + 1); - conn->net->stream->in_free = 0; - } -#if ZEND_DEBUG - /* Shut-up the streams, they don't know what they are doing */ - conn->net->stream->__exposed = 1; -#endif - mnd_efree(hashed_details); - } - - if (!conn->net->options.timeout_read) { - /* should always happen because read_timeout cannot be set via API */ - conn->net->options.timeout_read = (unsigned int) MYSQLND_G(net_read_timeout); - } - if (conn->net->options.timeout_read) - { - tv.tv_sec = conn->net->options.timeout_read; - tv.tv_usec = 0; - php_stream_set_option(conn->net->stream, PHP_STREAM_OPTION_READ_TIMEOUT, 0, &tv); - } - - if (!unix_socket) { - /* Set TCP_NODELAY */ - mysqlnd_set_sock_no_delay(conn->net->stream); - } - - { - unsigned int buf_size; - buf_size = MYSQLND_G(net_read_buffer_size); /* this is long, cast to unsigned int*/ - conn->m->set_client_option(conn, MYSQLND_OPT_NET_READ_BUFFER_SIZE, (char *)&buf_size TSRMLS_CC); + if (FAIL == conn->net->m.connect(conn->net, conn->scheme, transport_len, conn->persistent, &errstr, &errcode TSRMLS_CC)) { + goto err; } + DBG_INF_FMT("stream=%p", conn->net->stream); if (FAIL == PACKET_READ_ALLOCA(greet_packet, conn)) { DBG_ERR("Error while reading greeting packet"); |