Skip to content

Commit

Permalink
fix windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
ruihe774 committed Sep 1, 2024
1 parent 9348ce2 commit 07c6235
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
13 changes: 13 additions & 0 deletions transport/internet/socket_activation_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build !unix
// +build !unix

package internet

import (
"fmt"
"github.com/v2fly/v2ray-core/v5/common/net"
)

func activate_socket(address string) (net.Listener, error) {
return nil, fmt.Errorf("socket activation is not supported on this platform")
}
22 changes: 22 additions & 0 deletions transport/internet/socket_activation_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build unix
// +build unix

package internet

import (
"os"
"strconv"
"syscall"

"github.com/v2fly/v2ray-core/v5/common/net"
)

func activate_socket(address string) (net.Listener, error) {
fd, err := strconv.Atoi(address[8:])
if err != nil {
return nil, err
}
// Ignore the fail of SetNonblock: it's merely an optimization so that Go can poll this fd.
_ = syscall.SetNonblock(fd, true)
return net.FileListener(os.NewFile(uintptr(fd), address))
}
8 changes: 2 additions & 6 deletions transport/internet/system_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,8 @@ func (dl *DefaultListener) Listen(ctx context.Context, addr net.Addr, sockopt *S
address = string(fullAddr)
}
} else if strings.HasPrefix(address, "/dev/fd/") {
fd, err := strconv.Atoi(address[8:])
if err != nil {
return nil, err
}
_ = syscall.SetNonblock(fd, true)
l, err = net.FileListener(os.NewFile(uintptr(fd), address))
// socket activation
l, err = activate_socket(address)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 07c6235

Please sign in to comment.