Skip to content

Commit e6a5587

Browse files
committed
fix: getsockname if bind port == 0 (#706)
1 parent 70f0a8f commit e6a5587

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

event/hloop.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,10 @@ hio_t* hio_create_socket(hloop_t* loop, const char* host, int port, hio_type_e t
10361036
assert(io != NULL);
10371037
io->io_type = type;
10381038
if (side == HIO_SERVER_SIDE) {
1039+
if (port == 0) {
1040+
socklen_t addrlen = sizeof(sockaddr_u);
1041+
getsockname(sockfd, &addr.sa, &addrlen);
1042+
}
10391043
hio_set_localaddr(io, &addr.sa, sockaddr_len(&addr));
10401044
io->priority = HEVENT_HIGH_PRIORITY;
10411045
} else {

0 commit comments

Comments
 (0)