From 35b0f28fcc4c228501995270dbea2f735a083817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E9=A3=8E?= Date: Thu, 22 Aug 2013 18:58:52 +0800 Subject: [PATCH] socket accept can do more than once for transfer --- lualib/socket.lua | 10 ++++++++++ skynet-src/socket_server.c | 10 ++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) 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;