forked from docker/go-connections
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement AF_UNIX sockets on Windows
See moby/moby#36442 Signed-off-by: Marat Radchenko <[email protected]>
- Loading branch information
1 parent
58542c7
commit c430aa9
Showing
9 changed files
with
103 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package sockets | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
"testing" | ||
) | ||
|
||
func createTestUnixSocket(t *testing.T) (listener net.Listener, path string) { | ||
uid, gid := os.Getuid(), os.Getgid() | ||
perms := os.FileMode(0660) | ||
path = "/tmp/test.sock" | ||
echoStr := "hello" | ||
l, err := NewUnixSocketWithOpts(path, WithChown(uid, gid), WithChmod(perms)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
p, err := os.Stat(path) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if p.Mode().Perm() != perms { | ||
t.Fatalf("unexpected file permissions: expected: %#o, got: %#o", perms, p.Mode().Perm()) | ||
} | ||
if stat, ok := p.Sys().(*syscall.Stat_t); ok { | ||
if stat.Uid != uint32(uid) || stat.Gid != uint32(gid) { | ||
t.Fatalf("unexpected file ownership: expected: %d:%d, got: %d:%d", uid, gid, stat.Uid, stat.Gid) | ||
} | ||
} | ||
return l, path | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package sockets | ||
|
||
import ( | ||
"io/ioutil" | ||
"net" | ||
"testing" | ||
) | ||
|
||
func testSocketPath() string { | ||
file, err := ioutil.TempFile("", "test*.sock") | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer file.Close() | ||
return file.Name() | ||
} | ||
|
||
func createTestUnixSocket(t *testing.T) (listener net.Listener, path string) { | ||
path = testSocketPath() | ||
l, err := NewUnixSocketWithOpts(path) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return l, path | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package sockets | ||
|
||
import "syscall" | ||
|
||
func umask(newmask int) (oldmask int) { | ||
return syscall.Umask(0777) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package sockets | ||
|
||
func umask(newmask int) (oldmask int) { | ||
return newmask | ||
} |