diff --git a/lualib/socket.lua b/lualib/socket.lua index 8ba000ca..db0bcba2 100644 --- a/lualib/socket.lua +++ b/lualib/socket.lua @@ -265,4 +265,14 @@ function socket.unlock(id) until skynet.wakeup(co) end +-- abandon use to forward socket id to other service +-- you must call socket.accept(id) later in other service +function socket.abandon(id) + local s = socket_pool[id] + if s and s.buffer then + driver.clear(s.buffer) + end + socket_pool[id] = nil +end + return socket diff --git a/skynet-src/socket_server.c b/skynet-src/socket_server.c index 0e02ffa0..25db4b6f 100644 --- a/skynet-src/socket_server.c +++ b/skynet-src/socket_server.c @@ -498,12 +498,14 @@ accept_socket(struct socket_server *ss, struct request_accept *request, struct s result->ud = 0; result->data = NULL; struct socket *s = &ss->slot[id % MAX_SOCKET]; - if (s->type != SOCKET_TYPE_NOTACCEPT || s->id !=id) { + if (s->type == SOCKET_TYPE_INVALID || s->id !=id) { return SOCKET_ERROR; } - if (sp_add(ss->event_fd, s->fd, s)) { - s->type = SOCKET_TYPE_INVALID; - return SOCKET_ERROR; + if (s->type == SOCKET_TYPE_NOTACCEPT) { + if (sp_add(ss->event_fd, s->fd, s)) { + s->type = SOCKET_TYPE_INVALID; + return SOCKET_ERROR; + } } s->type = SOCKET_TYPE_CONNECTED; s->opaque = request->opaque;