mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
Revert "Update the return values of socket.listen, also return the real port bind to zero (#1638)"
This reverts commit c1eeba215d.
This commit is contained in:
@@ -488,14 +488,13 @@ llisten(lua_State *L) {
|
||||
int port = luaL_checkinteger(L,2);
|
||||
int backlog = luaL_optinteger(L,3,BACKLOG);
|
||||
struct skynet_context * ctx = lua_touserdata(L, lua_upvalueindex(1));
|
||||
int id = skynet_socket_listen(ctx, host, &port, backlog);
|
||||
int id = skynet_socket_listen(ctx, host,port,backlog);
|
||||
if (id < 0) {
|
||||
return luaL_error(L, "Listen error");
|
||||
}
|
||||
|
||||
lua_pushinteger(L,id);
|
||||
lua_pushinteger(L,port);
|
||||
return 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static size_t
|
||||
|
||||
@@ -77,9 +77,9 @@ end
|
||||
|
||||
function cluster.open(port)
|
||||
if type(port) == "string" then
|
||||
return skynet.call(clusterd, "lua", "listen", port)
|
||||
skynet.call(clusterd, "lua", "listen", port)
|
||||
else
|
||||
return skynet.call(clusterd, "lua", "listen", "0.0.0.0", port)
|
||||
skynet.call(clusterd, "lua", "listen", "0.0.0.0", port)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -41,10 +41,10 @@ function gateserver.start(handler)
|
||||
maxclient = conf.maxclient or 1024
|
||||
nodelay = conf.nodelay
|
||||
skynet.error(string.format("Listen on %s:%d", address, port))
|
||||
socket, port = socketdriver.listen(address, port)
|
||||
socket = socketdriver.listen(address, port)
|
||||
socketdriver.start(socket)
|
||||
if handler.open then
|
||||
return handler.open(source, conf, port)
|
||||
return handler.open(source, conf)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -331,7 +331,7 @@ start_listen(struct gate *g, char * listen_addr) {
|
||||
portstr[0] = '\0';
|
||||
host = listen_addr;
|
||||
}
|
||||
g->listen_id = skynet_socket_listen(ctx, host, &port, BACKLOG);
|
||||
g->listen_id = skynet_socket_listen(ctx, host, port, BACKLOG);
|
||||
if (g->listen_id < 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -148,9 +148,8 @@ function command.listen(source, addr, port)
|
||||
local address = assert(node_address[addr], addr .. " is down")
|
||||
addr, port = string.match(address, "([^:]+):(.*)$")
|
||||
end
|
||||
|
||||
local param = { address = addr, port = port }
|
||||
skynet.ret(skynet.pack(skynet.call(gate, "lua", "open", param)))
|
||||
skynet.call(gate, "lua", "open", { address = addr, port = port })
|
||||
skynet.ret(skynet.pack(nil))
|
||||
end
|
||||
|
||||
function command.sender(source, node)
|
||||
|
||||
@@ -11,9 +11,8 @@ skynet.register_protocol {
|
||||
|
||||
local handler = {}
|
||||
|
||||
function handler.open(source, conf, port)
|
||||
function handler.open(source, conf)
|
||||
watchdog = conf.watchdog or source
|
||||
return port
|
||||
end
|
||||
|
||||
function handler.message(fd, msg, sz)
|
||||
|
||||
@@ -127,7 +127,7 @@ skynet_socket_sendbuffer_lowpriority(struct skynet_context *ctx, struct socket_s
|
||||
}
|
||||
|
||||
int
|
||||
skynet_socket_listen(struct skynet_context *ctx, const char *host, int *port, int backlog) {
|
||||
skynet_socket_listen(struct skynet_context *ctx, const char *host, int port, int backlog) {
|
||||
uint32_t source = skynet_context_handle(ctx);
|
||||
return socket_server_listen(SOCKET_SERVER, source, host, port, backlog);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ void skynet_socket_updatetime();
|
||||
|
||||
int skynet_socket_sendbuffer(struct skynet_context *ctx, struct socket_sendbuffer *buffer);
|
||||
int skynet_socket_sendbuffer_lowpriority(struct skynet_context *ctx, struct socket_sendbuffer *buffer);
|
||||
int skynet_socket_listen(struct skynet_context *ctx, const char *host, int *port, int backlog);
|
||||
int skynet_socket_listen(struct skynet_context *ctx, const char *host, int port, int backlog);
|
||||
int skynet_socket_connect(struct skynet_context *ctx, const char *host, int port);
|
||||
int skynet_socket_bind(struct skynet_context *ctx, int fd);
|
||||
void skynet_socket_close(struct skynet_context *ctx, int id);
|
||||
|
||||
@@ -1936,7 +1936,7 @@ socket_server_shutdown(struct socket_server *ss, uintptr_t opaque, int id) {
|
||||
// return -1 means failed
|
||||
// or return AF_INET or AF_INET6
|
||||
static int
|
||||
do_bind(const char *host, int *port, int protocol, int *family) {
|
||||
do_bind(const char *host, int port, int protocol, int *family) {
|
||||
int fd;
|
||||
int status;
|
||||
int reuse = 1;
|
||||
@@ -1946,7 +1946,7 @@ do_bind(const char *host, int *port, int protocol, int *family) {
|
||||
if (host == NULL || host[0] == 0) {
|
||||
host = "0.0.0.0"; // INADDR_ANY
|
||||
}
|
||||
sprintf(portstr, "%d", *port);
|
||||
sprintf(portstr, "%d", port);
|
||||
memset( &ai_hints, 0, sizeof( ai_hints ) );
|
||||
ai_hints.ai_family = AF_UNSPEC;
|
||||
if (protocol == IPPROTO_TCP) {
|
||||
@@ -1973,15 +1973,6 @@ do_bind(const char *host, int *port, int protocol, int *family) {
|
||||
if (status != 0)
|
||||
goto _failed;
|
||||
|
||||
if (*port == 0) {
|
||||
union sockaddr_all sa;
|
||||
socklen_t len = sizeof(sa);
|
||||
|
||||
if (getsockname(fd, (struct sockaddr *)&sa, &len) == 0) {
|
||||
*port = ntohs((*family == AF_INET) ? sa.v4.sin_port : sa.v6.sin6_port);
|
||||
}
|
||||
}
|
||||
|
||||
freeaddrinfo( ai_list );
|
||||
return fd;
|
||||
_failed:
|
||||
@@ -1992,7 +1983,7 @@ _failed_fd:
|
||||
}
|
||||
|
||||
static int
|
||||
do_listen(const char * host, int *port, int backlog) {
|
||||
do_listen(const char * host, int port, int backlog) {
|
||||
int family = 0;
|
||||
int listen_fd = do_bind(host, port, IPPROTO_TCP, &family);
|
||||
if (listen_fd < 0) {
|
||||
@@ -2005,8 +1996,8 @@ do_listen(const char * host, int *port, int backlog) {
|
||||
return listen_fd;
|
||||
}
|
||||
|
||||
int
|
||||
socket_server_listen(struct socket_server *ss, uintptr_t opaque, const char * addr, int *port, int backlog) {
|
||||
int
|
||||
socket_server_listen(struct socket_server *ss, uintptr_t opaque, const char * addr, int port, int backlog) {
|
||||
int fd = do_listen(addr, port, backlog);
|
||||
if (fd < 0) {
|
||||
return -1;
|
||||
|
||||
@@ -43,7 +43,7 @@ int socket_server_send(struct socket_server *, struct socket_sendbuffer *buffer)
|
||||
int socket_server_send_lowpriority(struct socket_server *, struct socket_sendbuffer *buffer);
|
||||
|
||||
// ctrl command below returns id
|
||||
int socket_server_listen(struct socket_server *, uintptr_t opaque, const char * addr, int *port, int backlog);
|
||||
int socket_server_listen(struct socket_server *, uintptr_t opaque, const char * addr, int port, int backlog);
|
||||
int socket_server_connect(struct socket_server *, uintptr_t opaque, const char * addr, int port);
|
||||
int socket_server_bind(struct socket_server *, uintptr_t opaque, int fd);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user