bugfix : connection

This commit is contained in:
云风
2012-08-30 16:30:52 +08:00
parent 1791becd09
commit 51ef283887
8 changed files with 34 additions and 20 deletions

View File

@@ -65,6 +65,7 @@ _write(lua_State *L) {
case EINTR:
continue;
}
return 0;
}
assert(err == sz);
return 0;
@@ -104,6 +105,7 @@ _writeblock(lua_State *L) {
case EINTR:
continue;
}
return 0;
}
assert(err == sz +2);
return 0;

View File

@@ -95,6 +95,7 @@ _del(struct connection_server * server, int fd) {
static void
_poll(struct connection_server * server) {
int timeout = 100;
void * buffer = NULL;
for (;;) {
struct connection * c = connection_poll(server->pool, timeout);
if (c==NULL) {
@@ -103,7 +104,9 @@ _poll(struct connection_server * server) {
}
timeout = 0;
void * buffer = malloc(DEFAULT_BUFFER_SIZE);
if (buffer == NULL) {
buffer = malloc(DEFAULT_BUFFER_SIZE);
}
int size = recv(c->fd, buffer, DEFAULT_BUFFER_SIZE, MSG_DONTWAIT);
if (size < 0) {
@@ -112,9 +115,11 @@ _poll(struct connection_server * server) {
if (size == 0) {
connection_del(server->pool, c->fd);
free(buffer);
buffer = NULL;
skynet_send(server->ctx, 0, c->address, SESSION_CLIENT, NULL, 0, DONTCOPY);
} else {
skynet_send(server->ctx, 0, c->address, SESSION_CLIENT, buffer, size, DONTCOPY);
buffer = NULL;
}
}
}
@@ -137,8 +142,8 @@ _main(struct skynet_context * ctx, void * ud, int session, uint32_t source, cons
char addr [addr_sz];
memcpy(addr, endptr+1, addr_sz-1);
addr[addr_sz-1] = '\0';
uint32_t address = strtoul(addr, NULL, 16);
if (address != 0) {
uint32_t address = strtoul(addr+1, NULL, 16);
if (address == 0) {
skynet_error(ctx, "[connection] Invalid ADD command from %x (session = %d)", source, session);
return 0;
}