[fuchsia] ipsock_fuchsia: switch to getSocketProvider
Test: CQ
Change-Id: I8b336904c3f9e175efd93653baac5212f571835c
diff --git a/src/net/ipsock_fuchsia.go b/src/net/ipsock_fuchsia.go
index 3532986..59d6110 100644
--- a/src/net/ipsock_fuchsia.go
+++ b/src/net/ipsock_fuchsia.go
@@ -8,12 +8,13 @@
"context"
"errors"
"os"
- "strconv"
"sync"
"syscall"
"syscall/zx"
"syscall/zx/fdio"
+ "syscall/zx/fidl"
"syscall/zx/mxnet"
+ zxnet "syscall/zx/net"
"syscall/zx/zxsocket"
"time"
)
@@ -61,26 +62,26 @@
return syscall.AF_INET6, false
}
-type netstackInfo struct {
+type socketProviderInfo struct {
mu sync.Mutex
h zx.Handle
}
-var netstack netstackInfo
+var socketProvider socketProviderInfo
-func getNetstack() zx.Handle {
- netstack.mu.Lock()
- defer netstack.mu.Unlock()
- if netstack.h == zx.HandleInvalid {
+func getSocketProvider() zx.Handle {
+ socketProvider.mu.Lock()
+ defer socketProvider.mu.Unlock()
+ if socketProvider.h == zx.HandleInvalid {
c0, c1, err := zx.NewChannel(0)
if err == nil {
- err = fdio.ServiceConnect("/svc/net.Netstack", zx.Handle(c0))
+ err = fdio.ServiceConnect("/svc/fuchsia.net.LegacySocketProvider", zx.Handle(c0))
if err == nil {
- netstack.h = zx.Handle(c1)
+ socketProvider.h = zx.Handle(c1)
}
}
}
- return netstack.h
+ return socketProvider.h
}
func dialFuchsia(ctx context.Context, net string, laddr, raddr sockaddr) (fd *netFD, err error) {
@@ -92,16 +93,16 @@
}
proto := syscall.IPPROTO_IP
- path := "socket-v2/" + strconv.Itoa(family) + "/" + strconv.Itoa(sotype) + "/" + strconv.Itoa(proto)
-
var m fdio.FDIO
// Wait for the network stack to publish the socket device.
// See similar logic in zircon/system/ulib/fdio/bsdsocket.c.
for i := 0; i < 40; i++ {
- ns := zx.Channel(getNetstack())
- if zx.Handle(ns) != zx.HandleInvalid {
- m, err = zxsocket.OpenHandle(ns, path, 0, 0644)
+ c := zx.Channel(getSocketProvider())
+ if c.Handle().IsValid() {
+ sp := zxnet.LegacySocketProviderInterface(fidl.Proxy{Channel: c})
+ sock, _, err := sp.OpenSocket(zxnet.SocketDomain(family), zxnet.SocketType(sotype), zxnet.SocketProtocol(proto))
if err == nil {
+ m, _ = zxsocket.NewSocket(*sock.Handle())
break
}
}