@@ -587,7 +587,7 @@ pub fn new_tcp_socket(family AddrFamily) !TcpSocket {
587587 // use the non-blocking socket option instead please :)
588588
589589 // Some options need to be set before the connection is established, otherwise they will not work.
590- s.set_default_options ()!
590+ s.set_default_options (family )!
591591
592592 // Set the desired "blocking/non-blocking" mode before the connection is established,
593593 // and do not change it once the connection is successful.
@@ -608,7 +608,8 @@ fn tcp_socket_from_handle(sockfd int) !TcpSocket {
608608 s.set_dualstack (true ) or {
609609 // Not ipv6, we dont care
610610 }
611- s.set_default_options ()!
611+ addr := addr_from_socket_handle (sockfd)
612+ s.set_default_options (addr.family ())!
612613
613614 return s
614615}
@@ -649,7 +650,7 @@ pub fn (mut s TcpSocket) set_dualstack(on bool) ! {
649650 s.set_option (C.IPPROTO_IPV6 , int (SocketOption.ipv6_ only), x)!
650651}
651652
652- fn (mut s TcpSocket) set_default_options () ! {
653+ fn (mut s TcpSocket) set_default_options (af AddrFamily ) ! {
653654 s.set_option_int (.reuse_addr, 1 )!
654655
655656 // At the socket level to ignore the exception signal (usually SIGNPIPE).
@@ -660,7 +661,9 @@ fn (mut s TcpSocket) set_default_options() ! {
660661 }
661662
662663 // Enable the NODELAY option by default.
663- s.set_option (C.IPPROTO_TCP, C.TCP_NODELAY, 1 )!
664+ if af != .unix {
665+ s.set_option (C.IPPROTO_TCP, C.TCP_NODELAY, 1 )!
666+ }
664667}
665668
666669// bind a local rddress for TcpSocket
0 commit comments