2
私はnet.Pipe()
を試しています。私は"haha"
文字列を書いて、それを読み返すことが良い実験かもしれないと思った。`net.Pipe()`の `Read`と` Write`を正しく書く方法
ここは私の最初のバージョンです。また、私はそれが動作ゴルーチン
func TestNetPipe(t *testing.T) {
out1 := make([]byte, 10)
c1, c2 := net.Pipe()
go func() {
c1.Write([]byte("haha"))
}()
fmt.Printf("%v\n", out1)
c2.Read(out1)
fmt.Printf("%v\n", out1)
}
を使用しようとしたWrite
func TestNetPipe(t *testing.T) {
out1 := make([]byte, 10)
c1, c2 := net.Pipe()
c1.Write([]byte("haha"))
c2.Read(out1)
}
上のブロック。しかしRead
が"haha"
文字列全体を読むという保証はないと感じました。それは"hah"
部分のみを読むかもしれません。
パッケージio/ioutil
からnet.Pipe()