From 6d6c28c5eb1a065ee2ffbc31dce172cfddd3ab9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E9=A3=8E?= Date: Wed, 8 Aug 2012 12:20:52 +0800 Subject: [PATCH] bugfix: read block --- README.md | 17 +++++++++++++++++ connection/connection.c | 2 ++ testconn.lua | 7 +++++++ 3 files changed, 26 insertions(+) diff --git a/README.md b/README.md index 3f4c70dd..e38b9479 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,20 @@ Run these in different console ./skynet config_log # Launch second skynet node (Global logger server) ./clinet 127.0.0.1 8888 # Launch a client, and try to input some words. ``` + +## Test connection server + +``` +./skynet-master # Launch master server first +./skynet # Launch first skynet node +./nc -l 8000 # Listen on port 8000 +``` + +And then , type 'snlua testconn.lua' in skynet console to launch connection server and a test program. + +You can type something in nc console. + +## Blog (in Chinese) + +http://blog.codingnow.com/2012/08/skynet.html +http://blog.codingnow.com/2012/08/skynet_harbor_rpc.html diff --git a/connection/connection.c b/connection/connection.c index 447de049..abaa7afb 100644 --- a/connection/connection.c +++ b/connection/connection.c @@ -296,6 +296,7 @@ _read_block(struct connection_pool * pool, struct connection *c, size_t * id) { assert(c->read_complete == 0); int need_read = c->read_request - c->read_sz; if (need_read <= 0) { + c->yield_sz = c->read_request; c->read_complete = 1; return 1; } @@ -304,6 +305,7 @@ _read_block(struct connection_pool * pool, struct connection *c, size_t * id) { int bytes = _read_buffer(pool,c); if (bytes > 0) { if (c->read_request - c->read_sz <= 0) { + c->yield_sz = c->read_request; c->read_complete = 1; return 1; } diff --git a/testconn.lua b/testconn.lua index 116e3cbb..306b140c 100644 --- a/testconn.lua +++ b/testconn.lua @@ -8,8 +8,15 @@ print("connection",connection) skynet.start(function() local fd = skynet.call(".connection","CONNECT 127.0.0.1:8000") + if fd == nil then + print("Connect failed") + skynet.exit() + return + end print("connect to ",fd) skynet.send(".connection","WRITE "..fd.." Welcome\n") + local four = skynet.call(".connection","READ "..fd .." 4") + print("READ 4", four) local line = skynet.call(".connection","READLINE "..fd .." \n") skynet.send(".connection","WRITE "..fd.." "..line.."\n") skynet.send(".connection","CLOSE "..fd)