Yasuhiro MATSUMOTO has uploaded this change for review.
syscall: implement Unix Socket for Windows
Add implementation of AF_UNIX. This works only on Windows 10.
Closes #26072
Change-Id: I76a96a472385a17901885271622fbe55d66bb720
---
M src/syscall/syscall_windows.go
1 file changed, 47 insertions(+), 4 deletions(-)
diff --git a/src/syscall/syscall_windows.go b/src/syscall/syscall_windows.go
index 5cfdb76..c8c868a 100644
--- a/src/syscall/syscall_windows.go
+++ b/src/syscall/syscall_windows.go
@@ -626,7 +626,7 @@
type RawSockaddrAny struct {
Addr RawSockaddr
- Pad [96]int8
+ Pad [100]int8
}
type Sockaddr interface {
@@ -675,19 +675,62 @@
return unsafe.Pointer(&sa.raw), int32(unsafe.Sizeof(sa.raw)), nil
}
+type RawSockaddrUnix struct {
+ Family uint16
+ Path [108]int8
+}
+
type SockaddrUnix struct {
Name string
+ raw RawSockaddrUnix
}
func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, int32, error) {
- // TODO(brainman): implement SockaddrUnix.sockaddr()
- return nil, 0, EWINDOWS
+ name := sa.Name
+ n := len(name)
+ if n > len(sa.raw.Path) {
+ return nil, 0, EINVAL
+ }
+ if n == len(sa.raw.Path) && name[0] != '@' {
+ return nil, 0, EINVAL
+ }
+ sa.raw.Family = AF_UNIX
+ for i := 0; i < n; i++ {
+ sa.raw.Path[i] = int8(name[i])
+ }
+ // length is family (uint16), name, NUL.
+ sl := int32(2)
+ if n > 0 {
+ sl += int32(n) + 1
+ }
+ if sa.raw.Path[0] == '@' {
+ sa.raw.Path[0] = 0
+ // Don't count trailing NUL for abstract address.
+ sl--
+ }
+
+ return unsafe.Pointer(&sa.raw), sl, nil
}
func (rsa *RawSockaddrAny) Sockaddr() (Sockaddr, error) {
switch rsa.Addr.Family {
case AF_UNIX:
- return nil, EWINDOWS
+ pp := (*RawSockaddrUnix)(unsafe.Pointer(rsa))
+ sa := new(SockaddrUnix)
+ sa.raw.Family = AF_UNIX
+ copy(sa.raw.Path[:], pp.Path[:])
+ if len(pp.Path) > 0 {
+ var b [108]byte
+ var i int
+ for i = 0; i < len(pp.Path); i++ {
+ if pp.Path[i] == 0 {
+ break
+ }
+ b[i] = byte(pp.Path[i])
+ }
+ sa.Name = string(b[:i])
+ }
+ return sa, nil
case AF_INET:
pp := (*RawSockaddrInet4)(unsafe.Pointer(rsa))
To view, visit change 125456. To unsubscribe, or for help writing mail filters, visit settings.
Please take a look. Current implementation doesn't have tests since AF_UNIX was included in Fall Creators Update of Windows 10.
Thank you for doing this.
Alex
5 comments:
Patch Set #1, Line 7: syscall: implement Unix Socket for Windows
Not without some new tests. How do you expect reviewers to verify that this code actually work?
I would expect we already have some appropriate tests in net package, but they would be disabled. No?
Even if tests cannot be run without particular Windows 10 version, but we could check for appropriate Windows version before running the test.
If nothing else, we could enable these tests behind some test flag in net package. At least reviewers can run your test, if they want to.
Maybe add this link
https://blogs.msdn.microsoft.com/commandline/2017/12/19/af_unix-comes-to-windows/
here? Or even add the link somewhere in the code comment. It might be helpful for reviewers and people reading your code in the future.
Or any other links you find useful.
File src/syscall/syscall_windows.go:
Why are you changing 96 for 100?
Why 108? Where is that documented?
Patch Set #1, Line 721: copy(sa.raw.Path[:], pp.Path[:])
I can see that you have copied lines 689-712 from syscall_linux.go / SockaddrUnix.sockaddr function. But I do not see where you copied this code. I would expect you to copy appropriate part of syscall_linux.go / anyToSockaddr function, because according to https://blogs.msdn.microsoft.com/commandline/2017/12/19/af_unix-comes-to-windows - "... write a Windows unix socket winsock application as you would write any other unix socket application ...". What is going on here?
To view, visit change 125456. To unsubscribe, or for help writing mail filters, visit settings.
Yasuhiro MATSUMOTO uploaded patch set #2 to this change.
syscall: implement Unix Socket for Windows
Add implementation of AF_UNIX. This works only on Windows 10.
https://blogs.msdn.microsoft.com/commandline/2017/12/19/af_unix-comes-to-windows/
Closes #26072
Change-Id: I76a96a472385a17901885271622fbe55d66bb720
---
A src/net/unixsock_windows_test.go
M src/syscall/syscall_windows.go
2 files changed, 147 insertions(+), 4 deletions(-)
To view, visit change 125456. To unsubscribe, or for help writing mail filters, visit settings.
Thanks your reviewing.
5 comments:
Patch Set #1, Line 7: syscall: implement Unix Socket for Windows
Not without some new tests. How do you expect reviewers to verify that this code actually work? […]
I didn't notice how to check whether Fall Creators Update 2018. I noticed way to check this with reading registry.
Maybe add this link […]
added this URL. I only referred Go codes.
File src/syscall/syscall_windows.go:
Why are you changing 96 for 100?
Sorry, I can't explain why this value is required. When I tried with 96, Accept crash with invalid pointer. But bigger size doesn't.
I attempted to reduce this size little by little. And I figure out that the minimum value that did not crash was 100.
Why 108? Where is that documented?
This is defined in afunix.h
#define UNIX_PATH_MAX 108
typedef struct sockaddr_un
{
ADDRESS_FAMILY sun_family; /* AF_UNIX */
char sun_path[UNIX_PATH_MAX]; /* pathname */
} SOCKADDR_UN, *PSOCKADDR_UN;
Patch Set #1, Line 721: // "Abstract" Unix domain socket.
I can see that you have copied lines 689-712 from syscall_linux.go / SockaddrUnix.sockaddr function. […]
I didn't copied from any where since I did not notice it is already implemented in syscall_linux.go. Just had implemented to fill all of fields from pp to sa. Then, I updated code to copy this from syscall_linux.go .
To view, visit change 125456. To unsubscribe, or for help writing mail filters, visit settings.
4 comments:
Patch Set #2, Line 13: Closes
s/Closes/Fixes/
File src/net/unixsock_windows_test.go:
Patch Set #2, Line 35: func TestUnixConnLocalWindows(t *testing.T) {
I believe we already have appropriate tests in unixsock_posix.go. Why don't you enable those tests instead? And see what breaks.
File src/syscall/syscall_windows.go:
Sorry, I can't explain why this value is required. […]
Fair enough. I do not know what this value should be. Perhaps UNIX_PATH_MAX? But we should get it right first time. We do not want to break syscall API twice. Mikio, do you know what this value should be?
This is defined in afunix.h […]
Than add (perhaps put it into types_windows.go)
const UNIX_PATH_MAX 108 // defined in afunix.h
and use it everywhere.
To view, visit change 125456. To unsubscribe, or for help writing mail filters, visit settings.
Yasuhiro MATSUMOTO uploaded patch set #3 to this change.
syscall: implement Unix Socket for Windows
Add implementation of AF_UNIX. This works only on Windows 10.
https://blogs.msdn.microsoft.com/commandline/2017/12/19/af_unix-comes-to-windows/
Fixes #26072
Change-Id: I76a96a472385a17901885271622fbe55d66bb720
---
A src/net/unixsock_windows_test.go
M src/syscall/syscall_windows.go
M src/syscall/types_windows.go
3 files changed, 149 insertions(+), 4 deletions(-)
To view, visit change 125456. To unsubscribe, or for help writing mail filters, visit settings.
1 comment:
Patch Set #2, Line 35: func TestUnixConnLocalWindows(t *testing.T) {
I believe we already have appropriate tests in unixsock_posix.go. […]
SOCK_DGRAM still not be supported on Windows10.
To view, visit change 125456. To unsubscribe, or for help writing mail filters, visit settings.
Patch set 3:Run-TryBot +1
1 comment:
File src/syscall/syscall_windows.go:
Should we use UNIX_PATH_MAX here too?
s/100/UNIX_PATH_MAX/
To view, visit change 125456. To unsubscribe, or for help writing mail filters, visit settings.
Build is still in progress...
This change failed on linux-amd64:
See https://storage.googleapis.com/go-build-log/9bf0e208/linux-amd64_01edff14.log
Consult https://build.golang.org/ to see whether it's a new failure. Other builds still in progress; subsequent failure notices suppressed until final report.
Patch Set 3:
Build is still in progress...
This change failed on linux-amd64:
See https://storage.googleapis.com/go-build-log/9bf0e208/linux-amd64_01edff14.logConsult https://build.golang.org/ to see whether it's a new failure. Other builds still in progress; subsequent failure notices suppressed until final report.
##### API check
Error running API checker: exit status 1
+pkg syscall (windows-386), const UNIX_PATH_MAX = 108
+pkg syscall (windows-386), const UNIX_PATH_MAX ideal-int
+pkg syscall (windows-386), type RawSockaddrAny struct, Pad [100]int8
-pkg syscall (windows-386), type RawSockaddrAny struct, Pad [96]int8
+pkg syscall (windows-386), type RawSockaddrUnix struct, Family uint16
+pkg syscall (windows-386), type RawSockaddrUnix struct, Path [108]int8
+pkg syscall (windows-amd64), const UNIX_PATH_MAX = 108
+pkg syscall (windows-amd64), const UNIX_PATH_MAX ideal-int
+pkg syscall (windows-amd64), type RawSockaddrAny struct, Pad [100]int8
-pkg syscall (windows-amd64), type RawSockaddrAny struct, Pad [96]int8
+pkg syscall (windows-amd64), type RawSockaddrUnix struct, Family uint16
+pkg syscall (windows-amd64), type RawSockaddrUnix struct, Path [108]int8
+pkg syscall, type RawSockaddrUnix struct
exit status 1
2018/08/12 07:37:19 Failed: exit status 1
2018/08/12 07:37:19 FAILED
mattn, you have to adjust API file.
Alex
1 of 19 TryBots failed:
Failed on linux-amd64: https://storage.googleapis.com/go-build-log/9bf0e208/linux-amd64_01edff14.log
Consult https://build.golang.org/ to see whether they are new failures.
Patch set 3:TryBot-Result -1
Yasuhiro MATSUMOTO uploaded patch set #4 to this change.
syscall: implement Unix Socket for Windows
Add implementation of AF_UNIX. This works only on Windows 10.
https://blogs.msdn.microsoft.com/commandline/2017/12/19/af_unix-comes-to-windows/
Fixes #26072
Change-Id: I76a96a472385a17901885271622fbe55d66bb720
---
M api/except.txt
A src/net/unixsock_windows_test.go
M src/syscall/syscall_windows.go
M src/syscall/types_windows.go
4 files changed, 159 insertions(+), 4 deletions(-)
To view, visit change 125456. To unsubscribe, or for help writing mail filters, visit settings.
Patch set 4:Run-TryBot +1
Build is still in progress...
This change failed on linux-amd64:
See https://storage.googleapis.com/go-build-log/6bb392db/linux-amd64_ff5842fe.log
Consult https://build.golang.org/ to see whether it's a new failure. Other builds still in progress; subsequent failure notices suppressed until final report.
1 of 19 TryBots failed:
Failed on linux-amd64: https://storage.googleapis.com/go-build-log/6bb392db/linux-amd64_ff5842fe.log
Consult https://build.golang.org/ to see whether they are new failures.
Patch set 4:TryBot-Result -1
Patch Set 4: TryBot-Result-1
1 of 19 TryBots failed:
Failed on linux-amd64: https://storage.googleapis.com/go-build-log/6bb392db/linux-amd64_ff5842fe.logConsult https://build.golang.org/ to see whether they are new failures.
Please, fix the failure.
Thank you.
Alex
Patch Set 4:
Patch Set 4: TryBot-Result-1
1 of 19 TryBots failed:
Failed on linux-amd64: https://storage.googleapis.com/go-build-log/6bb392db/linux-amd64_ff5842fe.logConsult https://build.golang.org/ to see whether they are new failures.
Please, fix the failure.
Thank you.
Alex
Sorry, How can I test this on local?
Sorry, How can I test this on local?
You can run
all.bat
or
make.bat
go tool dist test -no-rebuild -run=api
Alex
Also, please, rebase to the tip. There would be many new changes that might affect your CL. We do not want trouble when submitting this.
To view, visit change 125456. To unsubscribe, or for help writing mail filters, visit settings.
Yasuhiro MATSUMOTO uploaded patch set #5 to this change.
syscall: implement Unix Socket for Windows
Add implementation of AF_UNIX. This works only on Windows 10.
https://blogs.msdn.microsoft.com/commandline/2017/12/19/af_unix-comes-to-windows/
Fixes #26072
Change-Id: I76a96a472385a17901885271622fbe55d66bb720
---
A src/net/unixsock_windows_test.go
M src/syscall/syscall_windows.go
M src/syscall/types_windows.go
3 files changed, 149 insertions(+), 4 deletions(-)
To view, visit change 125456. To unsubscribe, or for help writing mail filters, visit settings.
Patch Set 4:
Also, please, rebase to the tip. There would be many new changes that might affect your CL. We do not want trouble when submitting this.
Thank you.
Alex
Thank you. I rebased to the tip. And reverted changes for api on my branch. Sorry, I still have problem. I don't know why there are below's error that don't depend on my CL.
##### Testing packages.
ok cmd/api (cached)
##### API check
Error running API checker: exit status 1
+pkg debug/pe, const IMAGE_FILE_MACHINE_ARMNT = 452
+pkg debug/pe, const IMAGE_FILE_MACHINE_ARMNT ideal-int
+pkg net/http, method (*Client) CloseIdleConnections()
+pkg reflect, method (*MapIter) Key() Value
+pkg reflect, method (*MapIter) Next() bool
+pkg reflect, method (*MapIter) Value() Value
+pkg reflect, method (Value) MapRange() *MapIter
+pkg reflect, type MapIter struct
+pkg strings, method (*Builder) Cap() int
+pkg syscall (freebsd-386), const S_IRWXG = 56
+pkg syscall (freebsd-386), const S_IRWXG ideal-int
+pkg syscall (freebsd-386), const S_IRWXO = 7
+pkg syscall (freebsd-386), const S_IRWXO ideal-int
+pkg syscall (freebsd-386-cgo), const S_IRWXG = 56
+pkg syscall (freebsd-386-cgo), const S_IRWXG ideal-int
+pkg syscall (freebsd-386-cgo), const S_IRWXO = 7
+pkg syscall (freebsd-386-cgo), const S_IRWXO ideal-int
+pkg syscall (freebsd-amd64), const S_IRWXG = 56
+pkg syscall (freebsd-amd64), const S_IRWXG ideal-int
+pkg syscall (freebsd-amd64), const S_IRWXO = 7
+pkg syscall (freebsd-amd64), const S_IRWXO ideal-int
+pkg syscall (freebsd-amd64-cgo), const S_IRWXG = 56
+pkg syscall (freebsd-amd64-cgo), const S_IRWXG ideal-int
+pkg syscall (freebsd-amd64-cgo), const S_IRWXO = 7
+pkg syscall (freebsd-amd64-cgo), const S_IRWXO ideal-int
+pkg syscall (freebsd-arm), const S_IRWXG = 56
+pkg syscall (freebsd-arm), const S_IRWXG ideal-int
+pkg syscall (freebsd-arm), const S_IRWXO = 7
+pkg syscall (freebsd-arm), const S_IRWXO ideal-int
+pkg syscall (freebsd-arm-cgo), const S_IRWXG = 56
+pkg syscall (freebsd-arm-cgo), const S_IRWXG ideal-int
+pkg syscall (freebsd-arm-cgo), const S_IRWXO = 7
+pkg syscall (freebsd-arm-cgo), const S_IRWXO ideal-int
+pkg syscall (openbsd-386), const S_IRWXG = 56
+pkg syscall (openbsd-386), const S_IRWXG ideal-int
+pkg syscall (openbsd-386), const S_IRWXO = 7
+pkg syscall (openbsd-386), const S_IRWXO ideal-int
+pkg syscall (openbsd-386-cgo), const S_IRWXG = 56
+pkg syscall (openbsd-386-cgo), const S_IRWXG ideal-int
+pkg syscall (openbsd-386-cgo), const S_IRWXO = 7
+pkg syscall (openbsd-386-cgo), const S_IRWXO ideal-int
+pkg syscall (openbsd-amd64), const S_IRWXG = 56
+pkg syscall (openbsd-amd64), const S_IRWXG ideal-int
+pkg syscall (openbsd-amd64), const S_IRWXO = 7
+pkg syscall (openbsd-amd64), const S_IRWXO ideal-int
+pkg syscall (openbsd-amd64-cgo), const S_IRWXG = 56
+pkg syscall (openbsd-amd64-cgo), const S_IRWXG ideal-int
+pkg syscall (openbsd-amd64-cgo), const S_IRWXO = 7
+pkg syscall (openbsd-amd64-cgo), const S_IRWXO ideal-int
-pkg syscall (windows-386), type RawSockaddrAny struct, Pad [96]int8
-pkg syscall (windows-amd64), type RawSockaddrAny struct, Pad [96]int8
exit status 1
2018/08/27 18:19:42 Failed: exit status 1
2018/08/27 18:19:43 FAILED
Patch Set 4:
You won't need to care about the additions here (whether they come from this CL or others) as the tree is no longer locked down. It should be sufficient to add the changed RawSockaddrAny parts to api/except.txt, i.e.
diff --git a/api/except.txt b/api/except.txt
index 46dbb458923c..850724196d24 100644
--- a/api/except.txt
+++ b/api/except.txt
@@ -370,6 +370,7 @@ pkg syscall (windows-386), type CertContext struct, CertInfo uintptr
pkg syscall (windows-386), type CertRevocationInfo struct, CrlInfo uintptr
pkg syscall (windows-386), type CertRevocationInfo struct, OidSpecificInfo uintptr
pkg syscall (windows-386), type CertSimpleChain struct, TrustListInfo uintptr
+pkg syscall (windows-386), type RawSockaddrAny struct, Pad [96]int8
pkg syscall (windows-amd64), const TOKEN_ALL_ACCESS = 983295
pkg syscall (windows-amd64), type AddrinfoW struct, Addr uintptr
pkg syscall (windows-amd64), type CertChainPolicyPara struct, ExtraPolicyPara uintptr
@@ -378,3 +379,4 @@ pkg syscall (windows-amd64), type CertContext struct, CertInfo uintptr
pkg syscall (windows-amd64), type CertRevocationInfo struct, CrlInfo uintptr
pkg syscall (windows-amd64), type CertRevocationInfo struct, OidSpecificInfo uintptr
pkg syscall (windows-amd64), type CertSimpleChain struct, TrustListInfo uintptr
+pkg syscall (windows-amd64), type RawSockaddrAny struct, Pad [96]int8
Yasuhiro MATSUMOTO uploaded patch set #6 to this change.
syscall: implement Unix Socket for Windows
Add implementation of AF_UNIX. This works only on Windows 10.
https://blogs.msdn.microsoft.com/commandline/2017/12/19/af_unix-comes-to-windows/
Fixes #26072
Change-Id: I76a96a472385a17901885271622fbe55d66bb720
---
M api/except.txt
A src/net/unixsock_windows_test.go
M src/syscall/syscall_windows.go
M src/syscall/types_windows.go
4 files changed, 151 insertions(+), 4 deletions(-)
To view, visit change 125456. To unsubscribe, or for help writing mail filters, visit settings.
Patch Set 5:
Thank you
Patch set 6:Run-TryBot +1
TryBots beginning. Status page: https://farmer.golang.org/try?commit=9ab0f4a6
TryBots are happy.
Patch set 6:TryBot-Result +1
Leaving to Alex for the review. Thanks.
LGTM
Thank you everyone for pushing this along.
Alex
RELNOTE=yes
Patch set 6:Code-Review +2
Alex Brainman merged this change.
syscall: implement Unix Socket for Windows
Add implementation of AF_UNIX. This works only on Windows 10.
https://blogs.msdn.microsoft.com/commandline/2017/12/19/af_unix-comes-to-windows/
Fixes #26072
Change-Id: I76a96a472385a17901885271622fbe55d66bb720
Reviewed-on: https://go-review.googlesource.com/125456
Run-TryBot: Tobias Klauser <tobias....@gmail.com>
TryBot-Result: Gobot Gobot <go...@golang.org>
Reviewed-by: Alex Brainman <alex.b...@gmail.com>
---
M api/except.txt
A src/net/unixsock_windows_test.go
M src/syscall/syscall_windows.go
M src/syscall/types_windows.go
4 files changed, 151 insertions(+), 4 deletions(-)
diff --git a/api/except.txt b/api/except.txt
index 46dbb45..8507241 100644
--- a/api/except.txt
+++ b/api/except.txt
@@ -370,6 +370,7 @@
pkg syscall (windows-386), type CertRevocationInfo struct, CrlInfo uintptr
pkg syscall (windows-386), type CertRevocationInfo struct, OidSpecificInfo uintptr
pkg syscall (windows-386), type CertSimpleChain struct, TrustListInfo uintptr
+pkg syscall (windows-386), type RawSockaddrAny struct, Pad [96]int8
pkg syscall (windows-amd64), const TOKEN_ALL_ACCESS = 983295
pkg syscall (windows-amd64), type AddrinfoW struct, Addr uintptr
pkg syscall (windows-amd64), type CertChainPolicyPara struct, ExtraPolicyPara uintptr
@@ -378,3 +379,4 @@
pkg syscall (windows-amd64), type CertRevocationInfo struct, CrlInfo uintptr
pkg syscall (windows-amd64), type CertRevocationInfo struct, OidSpecificInfo uintptr
pkg syscall (windows-amd64), type CertSimpleChain struct, TrustListInfo uintptr
+pkg syscall (windows-amd64), type RawSockaddrAny struct, Pad [96]int8
diff --git a/src/net/unixsock_windows_test.go b/src/net/unixsock_windows_test.go
new file mode 100644
index 0000000..a1da5d4
--- /dev/null
+++ b/src/net/unixsock_windows_test.go
@@ -0,0 +1,93 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build windows
+
+package net
+
+import (
+ "internal/syscall/windows/registry"
+ "os"
+ "reflect"
+ "strconv"
+ "testing"
+)
+
+func isBuild17063() bool {
+ k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.READ)
+ if err != nil {
+ return false
+ }
+ defer k.Close()
+
+ s, _, err := k.GetStringValue("CurrentBuild")
+ if err != nil {
+ return false
+ }
+ ver, err := strconv.Atoi(s)
+ if err != nil {
+ return false
+ }
+ return ver >= 17063
+}
+
+func TestUnixConnLocalWindows(t *testing.T) {
+ if !isBuild17063() {
+ t.Skip("unix test")
+ }
+
+ handler := func(ls *localServer, ln Listener) {}
+ for _, laddr := range []string{"", testUnixAddr()} {
+ laddr := laddr
+ taddr := testUnixAddr()
+ ta, err := ResolveUnixAddr("unix", taddr)
+ if err != nil {
+ t.Fatal(err)
+ }
+ ln, err := ListenUnix("unix", ta)
+ if err != nil {
+ t.Fatal(err)
+ }
+ ls, err := (&streamListener{Listener: ln}).newLocalServer()
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer ls.teardown()
+ if err := ls.buildup(handler); err != nil {
+ t.Fatal(err)
+ }
+
+ la, err := ResolveUnixAddr("unix", laddr)
+ if err != nil {
+ t.Fatal(err)
+ }
+ c, err := DialUnix("unix", la, ta)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer func() {
+ c.Close()
+ if la != nil {
+ defer os.Remove(laddr)
+ }
+ }()
+ if _, err := c.Write([]byte("UNIXCONN LOCAL AND REMOTE NAME TEST")); err != nil {
+ t.Fatal(err)
+ }
+
+ if laddr == "" {
+ laddr = "@"
+ }
+ var connAddrs = [3]struct{ got, want Addr }{
+ {ln.Addr(), ta},
+ {c.LocalAddr(), &UnixAddr{Name: laddr, Net: "unix"}},
+ {c.RemoteAddr(), ta},
+ }
+ for _, ca := range connAddrs {
+ if !reflect.DeepEqual(ca.got, ca.want) {
+ t.Fatalf("got %#v, expected %#v", ca.got, ca.want)
+ }
+ }
+ }
+}
diff --git a/src/syscall/syscall_windows.go b/src/syscall/syscall_windows.go
index 638a818..528ef4f 100644
--- a/src/syscall/syscall_windows.go
+++ b/src/syscall/syscall_windows.go
@@ -634,7 +634,7 @@
type RawSockaddrAny struct {
Addr RawSockaddr
- Pad [96]int8
+ Pad [100]int8
}
type Sockaddr interface {
@@ -683,19 +683,69 @@
return unsafe.Pointer(&sa.raw), int32(unsafe.Sizeof(sa.raw)), nil
}
+type RawSockaddrUnix struct {
+ Family uint16
+ Path [UNIX_PATH_MAX]int8
+}
+
type SockaddrUnix struct {
Name string
+ raw RawSockaddrUnix
}
func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, int32, error) {
- // TODO(brainman): implement SockaddrUnix.sockaddr()
- return nil, 0, EWINDOWS
+ name := sa.Name
+ n := len(name)
+ if n > len(sa.raw.Path) {
+ return nil, 0, EINVAL
+ }
+ if n == len(sa.raw.Path) && name[0] != '@' {
+ return nil, 0, EINVAL
+ }
+ sa.raw.Family = AF_UNIX
+ for i := 0; i < n; i++ {
+ sa.raw.Path[i] = int8(name[i])
+ }
+ // length is family (uint16), name, NUL.
+ sl := int32(2)
+ if n > 0 {
+ sl += int32(n) + 1
+ }
+ if sa.raw.Path[0] == '@' {
+ sa.raw.Path[0] = 0
+ // Don't count trailing NUL for abstract address.
+ sl--
+ }
+
+ return unsafe.Pointer(&sa.raw), sl, nil
}
func (rsa *RawSockaddrAny) Sockaddr() (Sockaddr, error) {
switch rsa.Addr.Family {
case AF_UNIX:
- return nil, EWINDOWS
+ pp := (*RawSockaddrUnix)(unsafe.Pointer(rsa))
+ sa := new(SockaddrUnix)
+ if pp.Path[0] == 0 {
+ // "Abstract" Unix domain socket.
+ // Rewrite leading NUL as @ for textual display.
+ // (This is the standard convention.)
+ // Not friendly to overwrite in place,
+ // but the callers below don't care.
+ pp.Path[0] = '@'
+ }
+
+ // Assume path ends at NUL.
+ // This is not technically the Linux semantics for
+ // abstract Unix domain sockets--they are supposed
+ // to be uninterpreted fixed-size binary blobs--but
+ // everyone uses this convention.
+ n := 0
+ for n < len(pp.Path) && pp.Path[n] != 0 {
+ n++
+ }
+ bytes := (*[10000]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
+ sa.Name = string(bytes)
+ return sa, nil
case AF_INET:
pp := (*RawSockaddrInet4)(unsafe.Pointer(rsa))
diff --git a/src/syscall/types_windows.go b/src/syscall/types_windows.go
index 6911fe5..0b83933 100644
--- a/src/syscall/types_windows.go
+++ b/src/syscall/types_windows.go
@@ -1139,3 +1139,5 @@
SYMBOLIC_LINK_FLAG_DIRECTORY = 0x1
_SYMLINK_FLAG_RELATIVE = 1
)
+
+const UNIX_PATH_MAX = 108 // defined in afunix.h
To view, visit change 125456. To unsubscribe, or for help writing mail filters, visit settings.