socket accept report addr:port

This commit is contained in:
Cloud Wu
2014-09-29 14:42:42 +08:00
parent c8775ee6f5
commit aab65a2728
2 changed files with 5 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ local gate
local agent = {}
function SOCKET.open(fd, addr)
skynet.error("New client from : " .. addr)
agent[fd] = skynet.newservice("agent")
skynet.call(agent[fd], "lua", "start", gate, fd, proto)
end

View File

@@ -831,7 +831,10 @@ report_accept(struct socket_server *ss, struct socket *s, struct socket_message
result->data = NULL;
void * sin_addr = (u.s.sa_family == AF_INET) ? (void*)&u.v4.sin_addr : (void *)&u.v6.sin6_addr;
if (inet_ntop(u.s.sa_family, sin_addr, ss->buffer, sizeof(ss->buffer))) {
int sin_port = ntohs((u.s.sa_family == AF_INET) ? u.v4.sin_port : u.v6.sin6_port);
char tmp[INET6_ADDRSTRLEN];
if (inet_ntop(u.s.sa_family, sin_addr, tmp, sizeof(tmp))) {
snprintf(ss->buffer, sizeof(ss->buffer), "%s:%d", tmp, sin_port);
result->data = ss->buffer;
}