Skip to content

Commit

Permalink
Fixbug #15
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Dec 24, 2013
1 parent 2ca6e73 commit b7e56c6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
22 changes: 17 additions & 5 deletions swoole.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ PHP_FUNCTION(swoole_version)
RETURN_STRING(swoole_version, 1);
}


#ifdef SW_ASYNC_MYSQL
PHP_FUNCTION(swoole_get_mysqli_sock)
{
Expand All @@ -373,8 +372,17 @@ PHP_FUNCTION(swoole_get_mysqli_sock)
return;
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
if (SUCCESS != php_stream_cast(mysql->mysql->data->net->stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL,
(void*)&sock, 1) && sock >= 0)

php_stream *stream;

#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 4
stream = mysql->mysql->data->net->data->m.get_stream(mysql->mysql->data->net TSRMLS_CC);
#else
stream = mysql->mysql->data->net->stream;
#endif

if (SUCCESS != php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void* )&sock, 1)
&& sock >= 0)
{
RETURN_FALSE;
}
Expand Down Expand Up @@ -416,8 +424,12 @@ PHP_FUNCTION(swoole_server_create)
serv->factory_mode = serv_mode;
swTrace("Create host=%s,port=%ld,mode=%d\n", serv_host, serv_port, serv->factory_mode);

//线程安全
TSRMLS_SET_CTX(sw_thread_ctx);
#ifdef ZTS
if(sw_thread_ctx == NULL)
{
TSRMLS_SET_CTX(sw_thread_ctx);
}
#endif

bzero(php_sw_callback, sizeof(zval*)*PHP_SERVER_CALLBACK_NUM);

Expand Down
14 changes: 14 additions & 0 deletions swoole_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,13 @@ PHP_FUNCTION(swoole_event_add)
return;
}

#ifdef ZTS
if(sw_thread_ctx == NULL)
{
TSRMLS_SET_CTX(sw_thread_ctx);
}
#endif

int socket_fd = swoole_convert_to_fd(fd);
if(socket_fd < 0)
{
Expand Down Expand Up @@ -413,6 +420,13 @@ PHP_METHOD(swoole_client, __construct)
RETURN_FALSE;
}

#ifdef ZTS
if(sw_thread_ctx == NULL)
{
TSRMLS_SET_CTX(sw_thread_ctx);
}
#endif

swClient *cli = (swClient*) emalloc(sizeof(swClient));
if (swClient_create(cli, type, async) < 0)
{
Expand Down
7 changes: 7 additions & 0 deletions swoole_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ PHP_METHOD(swoole_lock, __construct)
int filelock_len = 0;
int ret;

#ifdef ZTS
if(sw_thread_ctx == NULL)
{
TSRMLS_SET_CTX(sw_thread_ctx);
}
#endif

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ls", &type, &filelock, &filelock_len) == FAILURE)
{
RETURN_FALSE;
Expand Down

0 comments on commit b7e56c6

Please sign in to comment.