bugfix: read block

This commit is contained in:
云风
2012-08-08 12:20:52 +08:00
parent 06ecbd3458
commit 6d6c28c5eb
3 changed files with 26 additions and 0 deletions

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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)