Last active
March 1, 2018 02:16
-
-
Save tehmoon/9f60e21e1442d390d52c2bde25e97365 to your computer and use it in GitHub Desktop.
Tests with socketpair in go
This file contains hidden or 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
package main | |
import ( | |
"io" | |
"syscall" | |
"os" | |
"errors" | |
) | |
func main() { | |
fd, err := syscall.Socketpair(syscall.AF_LOCAL, syscall.SOCK_STREAM, 0) | |
if err != nil { | |
panic(err) | |
} | |
server := os.NewFile(uintptr(fd[0]), "server") | |
client := os.NewFile(uintptr(fd[1]), "client") | |
if server == nil || client == nil { | |
panic(errors.New("Fail to create new file from fd")) | |
} | |
go func() { | |
io.Copy(server, os.Stdin) | |
}() | |
go func() { | |
io.Copy(os.Stdout, client) | |
}() | |
select{} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment