socket read all data once

This commit is contained in:
云风
2013-06-28 19:02:50 +08:00
parent 67610a9614
commit 40c77e7739
2 changed files with 29 additions and 27 deletions

View File

@@ -215,9 +215,7 @@ _cb(struct skynet_context * ctx, void * ud, int type, int session, uint32_t sour
assert(type == PTYPE_RESPONSE);
struct mread_pool * m = g->pool;
int connection_id = mread_poll(m,100); // timeout : 100ms
if (connection_id < 0) {
skynet_command(ctx, "TIMEOUT", "1");
} else {
if (connection_id >= 0) {
int id = g->map[connection_id].uid;
if (id == 0) {
id = _gen_id(g, connection_id);
@@ -254,9 +252,9 @@ _cb(struct skynet_context * ctx, void * ud, int type, int session, uint32_t sour
_forward(ctx, g, id, data, len);
mread_yield(m);
}
_break:
skynet_command(ctx, "TIMEOUT", "0");
}
return 0;
}

View File

@@ -234,6 +234,7 @@ parser(const char * msg, int sz, char * buffer, int *id) {
static void
forward(struct skynet_context * context, struct socket *s, struct socket_pool *p) {
for (;;) {
int * buffer = malloc(READ_BUFFER + sizeof(int));
*buffer = s->id; // convert endian ?
int r = 0;
@@ -261,6 +262,9 @@ forward(struct skynet_context * context, struct socket *s, struct socket_pool *p
} else {
skynet_send(context, 0, s->source, PTYPE_CLIENT | PTYPE_TAG_DONTCOPY, 0, buffer, r + 4);
}
if (r < READ_BUFFER)
return;
}
}
static void
@@ -391,7 +395,7 @@ _cb(struct skynet_context * context, void * ud, int type, int session, uint32_t
}
}
}
skynet_command(context, "TIMEOUT", n == MAX_EVENT ? "0" : "1");
skynet_command(context, "TIMEOUT", "0");
return 0;
}