Skip to content

Commit

Permalink
Fixed compile failed with enable-ringbuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Jun 9, 2014
1 parent 88a2de7 commit 3a60cb7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
20 changes: 12 additions & 8 deletions examples/proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
});
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions examples/proxy_sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 6 additions & 5 deletions src/network/Connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions swoole_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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次数

Expand Down

0 comments on commit 3a60cb7

Please sign in to comment.