From 3a60cb7ae7bb92120ca0425d3365897ceed3fc9a Mon Sep 17 00:00:00 2001 From: matyhtf Date: Mon, 9 Jun 2014 20:22:26 +0800 Subject: [PATCH] Fixed compile failed with enable-ringbuffer --- examples/proxy.php | 20 ++++++++++++-------- examples/proxy_sync.php | 8 ++++---- src/network/Connection.c | 11 ++++++----- swoole_config.h | 2 ++ 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/examples/proxy.php b/examples/proxy.php index 8bfc030ca13..90f773cc46b 100644 --- a/examples/proxy.php +++ b/examples/proxy.php @@ -61,13 +61,7 @@ function onConnect($serv, $fd, $from_id) { $socket = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC); echo microtime() . ": Client[$fd] backend-sock[{$socket->sock}]: Connect.\n"; - $this->backends[$socket->sock] = array( - 'client_fd' => $fd, - 'socket' => $socket, - ); - $this->clients[$fd] = array( - 'socket' => $socket, - ); + $socket->on('connect', function (swoole_client $socket) { echo "connect to backend server success\n"; }); @@ -87,7 +81,17 @@ function onConnect($serv, $fd, $from_id) //可以修改为类静态变量 $this->serv->send($this->backends[$socket->sock]['client_fd'], $data); }); - $socket->connect('127.0.0.1', 80, 0.2); + + if ($socket->connect('127.0.0.1', 80, 0.2)) + { + $this->backends[$socket->sock] = array( + 'client_fd' => $fd, + 'socket' => $socket, + ); + $this->clients[$fd] = array( + 'socket' => $socket, + ); + } } function onReceive($serv, $fd, $from_id, $data) diff --git a/examples/proxy_sync.php b/examples/proxy_sync.php index 1494f787654..6b718d668a7 100644 --- a/examples/proxy_sync.php +++ b/examples/proxy_sync.php @@ -51,12 +51,12 @@ function onConnect($serv, $fd, $from_id) function onReceive($serv, $fd, $from_id, $data) { - $socket = new swoole_client(SWOOLE_SOCK_TCP); + $socket = new swoole_client(SWOOLE_SOCK_TCP); if($socket->connect('127.0.0.1', 80, 0.5)) { - $socket->send($data); - $serv->send($fd, $socket->recv(8192, 0)); - } + $socket->send($data); + $serv->send($fd, $socket->recv(8192, 0)); + } unset($socket); $serv->close($fd); } diff --git a/src/network/Connection.c b/src/network/Connection.c index 0019ab03c3f..cabb1831d42 100644 --- a/src/network/Connection.c +++ b/src/network/Connection.c @@ -294,14 +294,18 @@ SWINLINE void swConnection_clear_string_buffer(swConnection *conn) int swConnection_send_in_buffer(swConnection *conn) { + swServer *serv = SwooleG.serv; swFactory *factory = SwooleG.factory; swEventData _send; _send.info.fd = conn->fd; _send.info.from_id = conn->from_id; + swBuffer *buffer = conn->in_buffer; + swBuffer_trunk *trunk = swBuffer_get_trunk(buffer); + #ifdef SW_USE_RINGBUFFER - swServer *serv = SwooleG.serv; + swMemoryPool *pool = serv->reactor_threads[conn->from_id].pool; swPackage package; @@ -322,7 +326,7 @@ int swConnection_send_in_buffer(swConnection *conn) while (trunk != NULL) { _send.info.len = trunk->length; - memcpy(package.data + package.length , trunk->data, trunk->length); + memcpy(package.data + package.length , trunk->store.ptr, trunk->length); package.length += trunk->length; swBuffer_pop_trunk(buffer, trunk); @@ -335,9 +339,6 @@ int swConnection_send_in_buffer(swConnection *conn) #else - swBuffer *buffer = conn->in_buffer; - swBuffer_trunk *trunk = swBuffer_get_trunk(buffer); - int ret; _send.info.type = SW_EVENT_PACKAGE_START; diff --git a/swoole_config.h b/swoole_config.h index 84dd201f276..e6ca78bf9f9 100644 --- a/swoole_config.h +++ b/swoole_config.h @@ -97,6 +97,8 @@ #define SW_USE_FIXED_BUFFER +//#define SW_USE_RINGBUFFER + #define SW_ACCEPT_AGAIN 1 //是否循环accept,可以一次性处理完全部的listen队列,用于大量并发连接的场景 #define SW_ACCEPT_MAX_COUNT 64 //一次循环的最大accept次数