1
0
Эх сурвалжийг харах

fix: getsockname if bind port == 0 (#706)

ithewei 8 сар өмнө
parent
commit
e6a5587126
1 өөрчлөгдсөн 4 нэмэгдсэн , 0 устгасан
  1. 4 0
      event/hloop.c

+ 4 - 0
event/hloop.c

@@ -1036,6 +1036,10 @@ hio_t* hio_create_socket(hloop_t* loop, const char* host, int port, hio_type_e t
     assert(io != NULL);
     assert(io != NULL);
     io->io_type = type;
     io->io_type = type;
     if (side == HIO_SERVER_SIDE) {
     if (side == HIO_SERVER_SIDE) {
+        if (port == 0) {
+            socklen_t addrlen = sizeof(sockaddr_u);
+            getsockname(sockfd, &addr.sa, &addrlen);
+        }
         hio_set_localaddr(io, &addr.sa, sockaddr_len(&addr));
         hio_set_localaddr(io, &addr.sa, sockaddr_len(&addr));
         io->priority = HEVENT_HIGH_PRIORITY;
         io->priority = HEVENT_HIGH_PRIORITY;
     } else {
     } else {