mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 12:20:41 +00:00
bugfix: read block
This commit is contained in:
17
README.md
17
README.md
@@ -16,3 +16,20 @@ Run these in different console
|
|||||||
./skynet config_log # Launch second skynet node (Global logger server)
|
./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.
|
./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
|
||||||
|
|||||||
@@ -296,6 +296,7 @@ _read_block(struct connection_pool * pool, struct connection *c, size_t * id) {
|
|||||||
assert(c->read_complete == 0);
|
assert(c->read_complete == 0);
|
||||||
int need_read = c->read_request - c->read_sz;
|
int need_read = c->read_request - c->read_sz;
|
||||||
if (need_read <= 0) {
|
if (need_read <= 0) {
|
||||||
|
c->yield_sz = c->read_request;
|
||||||
c->read_complete = 1;
|
c->read_complete = 1;
|
||||||
return 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);
|
int bytes = _read_buffer(pool,c);
|
||||||
if (bytes > 0) {
|
if (bytes > 0) {
|
||||||
if (c->read_request - c->read_sz <= 0) {
|
if (c->read_request - c->read_sz <= 0) {
|
||||||
|
c->yield_sz = c->read_request;
|
||||||
c->read_complete = 1;
|
c->read_complete = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,15 @@ print("connection",connection)
|
|||||||
|
|
||||||
skynet.start(function()
|
skynet.start(function()
|
||||||
local fd = skynet.call(".connection","CONNECT 127.0.0.1:8000")
|
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)
|
print("connect to ",fd)
|
||||||
skynet.send(".connection","WRITE "..fd.." Welcome\n")
|
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")
|
local line = skynet.call(".connection","READLINE "..fd .." \n")
|
||||||
skynet.send(".connection","WRITE "..fd.." "..line.."\n")
|
skynet.send(".connection","WRITE "..fd.." "..line.."\n")
|
||||||
skynet.send(".connection","CLOSE "..fd)
|
skynet.send(".connection","CLOSE "..fd)
|
||||||
|
|||||||
Reference in New Issue
Block a user