2012-11-21 08:03:38 +01:00
|
|
|
// Copyright 2012 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.
|
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
// This file implements API tests across platforms and will never have a build
|
|
|
|
// tag.
|
|
|
|
|
|
|
|
package net
|
2012-11-21 08:03:38 +01:00
|
|
|
|
|
|
|
import (
|
2013-07-16 08:54:42 +02:00
|
|
|
"io/ioutil"
|
2012-11-21 08:03:38 +01:00
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
// testUnixAddr uses ioutil.TempFile to get a name that is unique. It
|
|
|
|
// also uses /tmp directory in case it is prohibited to create UNIX
|
|
|
|
// sockets in TMPDIR.
|
|
|
|
func testUnixAddr() string {
|
2014-07-19 10:53:52 +02:00
|
|
|
f, err := ioutil.TempFile("", "nettest")
|
2013-07-16 08:54:42 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
addr := f.Name()
|
|
|
|
f.Close()
|
|
|
|
os.Remove(addr)
|
|
|
|
return addr
|
|
|
|
}
|
|
|
|
|
|
|
|
var condFatalf = func() func(*testing.T, string, ...interface{}) {
|
2012-11-21 08:03:38 +01:00
|
|
|
// A few APIs are not implemented yet on both Plan 9 and Windows.
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "plan9", "windows":
|
|
|
|
return (*testing.T).Logf
|
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
return (*testing.T).Fatalf
|
2012-11-21 08:03:38 +01:00
|
|
|
}()
|
|
|
|
|
|
|
|
func TestTCPListenerSpecificMethods(t *testing.T) {
|
2013-07-16 08:54:42 +02:00
|
|
|
switch runtime.GOOS {
|
|
|
|
case "plan9":
|
|
|
|
t.Skipf("skipping test on %q", runtime.GOOS)
|
|
|
|
}
|
|
|
|
|
|
|
|
la, err := ResolveTCPAddr("tcp4", "127.0.0.1:0")
|
2012-11-21 08:03:38 +01:00
|
|
|
if err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("ResolveTCPAddr failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
ln, err := ListenTCP("tcp4", la)
|
2012-11-21 08:03:38 +01:00
|
|
|
if err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("ListenTCP failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
defer ln.Close()
|
2012-11-21 08:03:38 +01:00
|
|
|
ln.Addr()
|
|
|
|
ln.SetDeadline(time.Now().Add(30 * time.Nanosecond))
|
|
|
|
|
|
|
|
if c, err := ln.Accept(); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
if !err.(Error).Timeout() {
|
|
|
|
t.Fatalf("TCPListener.Accept failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
c.Close()
|
|
|
|
}
|
|
|
|
if c, err := ln.AcceptTCP(); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
if !err.(Error).Timeout() {
|
|
|
|
t.Fatalf("TCPListener.AcceptTCP failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
c.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
if f, err := ln.File(); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
condFatalf(t, "TCPListener.File failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
} else {
|
|
|
|
f.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTCPConnSpecificMethods(t *testing.T) {
|
2013-07-16 08:54:42 +02:00
|
|
|
la, err := ResolveTCPAddr("tcp4", "127.0.0.1:0")
|
2012-11-21 08:03:38 +01:00
|
|
|
if err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("ResolveTCPAddr failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
ln, err := ListenTCP("tcp4", la)
|
2012-11-21 08:03:38 +01:00
|
|
|
if err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("ListenTCP failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
defer ln.Close()
|
2013-07-16 08:54:42 +02:00
|
|
|
ln.Addr()
|
2012-11-21 08:03:38 +01:00
|
|
|
|
|
|
|
done := make(chan int)
|
|
|
|
go transponder(t, ln, done)
|
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
ra, err := ResolveTCPAddr("tcp4", ln.Addr().String())
|
2012-11-21 08:03:38 +01:00
|
|
|
if err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("ResolveTCPAddr failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
c, err := DialTCP("tcp4", nil, ra)
|
2012-11-21 08:03:38 +01:00
|
|
|
if err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("DialTCP failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
defer c.Close()
|
2012-11-21 08:03:38 +01:00
|
|
|
c.SetKeepAlive(false)
|
2013-11-06 20:49:01 +01:00
|
|
|
c.SetKeepAlivePeriod(3 * time.Second)
|
2012-11-21 08:03:38 +01:00
|
|
|
c.SetLinger(0)
|
|
|
|
c.SetNoDelay(false)
|
|
|
|
c.LocalAddr()
|
|
|
|
c.RemoteAddr()
|
2013-07-16 08:54:42 +02:00
|
|
|
c.SetDeadline(time.Now().Add(someTimeout))
|
|
|
|
c.SetReadDeadline(time.Now().Add(someTimeout))
|
|
|
|
c.SetWriteDeadline(time.Now().Add(someTimeout))
|
2012-11-21 08:03:38 +01:00
|
|
|
|
|
|
|
if _, err := c.Write([]byte("TCPCONN TEST")); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("TCPConn.Write failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
rb := make([]byte, 128)
|
|
|
|
if _, err := c.Read(rb); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("TCPConn.Read failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
<-done
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUDPConnSpecificMethods(t *testing.T) {
|
2013-07-16 08:54:42 +02:00
|
|
|
la, err := ResolveUDPAddr("udp4", "127.0.0.1:0")
|
2012-11-21 08:03:38 +01:00
|
|
|
if err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("ResolveUDPAddr failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
c, err := ListenUDP("udp4", la)
|
2012-11-21 08:03:38 +01:00
|
|
|
if err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("ListenUDP failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
defer c.Close()
|
2012-11-21 08:03:38 +01:00
|
|
|
c.LocalAddr()
|
|
|
|
c.RemoteAddr()
|
2013-07-16 08:54:42 +02:00
|
|
|
c.SetDeadline(time.Now().Add(someTimeout))
|
|
|
|
c.SetReadDeadline(time.Now().Add(someTimeout))
|
|
|
|
c.SetWriteDeadline(time.Now().Add(someTimeout))
|
2012-11-21 08:03:38 +01:00
|
|
|
c.SetReadBuffer(2048)
|
|
|
|
c.SetWriteBuffer(2048)
|
|
|
|
|
|
|
|
wb := []byte("UDPCONN TEST")
|
|
|
|
rb := make([]byte, 128)
|
2013-07-16 08:54:42 +02:00
|
|
|
if _, err := c.WriteToUDP(wb, c.LocalAddr().(*UDPAddr)); err != nil {
|
|
|
|
t.Fatalf("UDPConn.WriteToUDP failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
if _, _, err := c.ReadFromUDP(rb); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("UDPConn.ReadFromUDP failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
if _, _, err := c.WriteMsgUDP(wb, nil, c.LocalAddr().(*UDPAddr)); err != nil {
|
|
|
|
condFatalf(t, "UDPConn.WriteMsgUDP failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
if _, _, _, _, err := c.ReadMsgUDP(rb, nil); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
condFatalf(t, "UDPConn.ReadMsgUDP failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if f, err := c.File(); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
condFatalf(t, "UDPConn.File failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
} else {
|
|
|
|
f.Close()
|
|
|
|
}
|
2013-11-06 20:49:01 +01:00
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if p := recover(); p != nil {
|
|
|
|
t.Fatalf("UDPConn.WriteToUDP or WriteMsgUDP panicked: %v", p)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
c.WriteToUDP(wb, nil)
|
|
|
|
c.WriteMsgUDP(wb, nil, nil)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestIPConnSpecificMethods(t *testing.T) {
|
2013-11-06 20:49:01 +01:00
|
|
|
if skip, skipmsg := skipRawSocketTest(t); skip {
|
|
|
|
t.Skip(skipmsg)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
la, err := ResolveIPAddr("ip4", "127.0.0.1")
|
2012-11-21 08:03:38 +01:00
|
|
|
if err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("ResolveIPAddr failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
c, err := ListenIP("ip4:icmp", la)
|
2012-11-21 08:03:38 +01:00
|
|
|
if err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("ListenIP failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
defer c.Close()
|
2012-11-21 08:03:38 +01:00
|
|
|
c.LocalAddr()
|
|
|
|
c.RemoteAddr()
|
2013-07-16 08:54:42 +02:00
|
|
|
c.SetDeadline(time.Now().Add(someTimeout))
|
|
|
|
c.SetReadDeadline(time.Now().Add(someTimeout))
|
|
|
|
c.SetWriteDeadline(time.Now().Add(someTimeout))
|
2012-11-21 08:03:38 +01:00
|
|
|
c.SetReadBuffer(2048)
|
|
|
|
c.SetWriteBuffer(2048)
|
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
wb, err := (&icmpMessage{
|
|
|
|
Type: icmpv4EchoRequest, Code: 0,
|
|
|
|
Body: &icmpEcho{
|
|
|
|
ID: os.Getpid() & 0xffff, Seq: 1,
|
|
|
|
Data: []byte("IPCONN TEST "),
|
|
|
|
},
|
|
|
|
}).Marshal()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("icmpMessage.Marshal failed: %v", err)
|
|
|
|
}
|
2013-11-06 20:49:01 +01:00
|
|
|
rb := make([]byte, 20+len(wb))
|
2013-07-16 08:54:42 +02:00
|
|
|
if _, err := c.WriteToIP(wb, c.LocalAddr().(*IPAddr)); err != nil {
|
|
|
|
t.Fatalf("IPConn.WriteToIP failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
if _, _, err := c.ReadFromIP(rb); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("IPConn.ReadFromIP failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
if _, _, err := c.WriteMsgIP(wb, nil, c.LocalAddr().(*IPAddr)); err != nil {
|
|
|
|
condFatalf(t, "IPConn.WriteMsgIP failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
if _, _, _, _, err := c.ReadMsgIP(rb, nil); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
condFatalf(t, "IPConn.ReadMsgIP failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if f, err := c.File(); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
condFatalf(t, "IPConn.File failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
} else {
|
|
|
|
f.Close()
|
|
|
|
}
|
2013-11-06 20:49:01 +01:00
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if p := recover(); p != nil {
|
|
|
|
t.Fatalf("IPConn.WriteToIP or WriteMsgIP panicked: %v", p)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
c.WriteToIP(wb, nil)
|
|
|
|
c.WriteMsgIP(wb, nil, nil)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnixListenerSpecificMethods(t *testing.T) {
|
|
|
|
switch runtime.GOOS {
|
2014-07-19 10:53:52 +02:00
|
|
|
case "nacl", "plan9", "windows":
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Skipf("skipping test on %q", runtime.GOOS)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
addr := testUnixAddr()
|
|
|
|
la, err := ResolveUnixAddr("unix", addr)
|
2012-11-21 08:03:38 +01:00
|
|
|
if err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("ResolveUnixAddr failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
ln, err := ListenUnix("unix", la)
|
2012-11-21 08:03:38 +01:00
|
|
|
if err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("ListenUnix failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
defer ln.Close()
|
|
|
|
defer os.Remove(addr)
|
2012-11-21 08:03:38 +01:00
|
|
|
ln.Addr()
|
|
|
|
ln.SetDeadline(time.Now().Add(30 * time.Nanosecond))
|
|
|
|
|
|
|
|
if c, err := ln.Accept(); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
if !err.(Error).Timeout() {
|
|
|
|
t.Fatalf("UnixListener.Accept failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
c.Close()
|
|
|
|
}
|
|
|
|
if c, err := ln.AcceptUnix(); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
if !err.(Error).Timeout() {
|
|
|
|
t.Fatalf("UnixListener.AcceptUnix failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
c.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
if f, err := ln.File(); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("UnixListener.File failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
} else {
|
|
|
|
f.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnixConnSpecificMethods(t *testing.T) {
|
|
|
|
switch runtime.GOOS {
|
2014-07-19 10:53:52 +02:00
|
|
|
case "nacl", "plan9", "windows":
|
2013-01-29 21:52:43 +01:00
|
|
|
t.Skipf("skipping test on %q", runtime.GOOS)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
addr1, addr2, addr3 := testUnixAddr(), testUnixAddr(), testUnixAddr()
|
2012-11-21 08:03:38 +01:00
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
a1, err := ResolveUnixAddr("unixgram", addr1)
|
2012-11-21 08:03:38 +01:00
|
|
|
if err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("ResolveUnixAddr failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
c1, err := DialUnix("unixgram", a1, nil)
|
2012-11-21 08:03:38 +01:00
|
|
|
if err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("DialUnix failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
defer c1.Close()
|
|
|
|
defer os.Remove(addr1)
|
2012-11-21 08:03:38 +01:00
|
|
|
c1.LocalAddr()
|
|
|
|
c1.RemoteAddr()
|
2013-07-16 08:54:42 +02:00
|
|
|
c1.SetDeadline(time.Now().Add(someTimeout))
|
|
|
|
c1.SetReadDeadline(time.Now().Add(someTimeout))
|
|
|
|
c1.SetWriteDeadline(time.Now().Add(someTimeout))
|
2012-11-21 08:03:38 +01:00
|
|
|
c1.SetReadBuffer(2048)
|
|
|
|
c1.SetWriteBuffer(2048)
|
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
a2, err := ResolveUnixAddr("unixgram", addr2)
|
2012-11-21 08:03:38 +01:00
|
|
|
if err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("ResolveUnixAddr failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
c2, err := DialUnix("unixgram", a2, nil)
|
2012-11-21 08:03:38 +01:00
|
|
|
if err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("DialUnix failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
defer c2.Close()
|
|
|
|
defer os.Remove(addr2)
|
2012-11-21 08:03:38 +01:00
|
|
|
c2.LocalAddr()
|
|
|
|
c2.RemoteAddr()
|
2013-07-16 08:54:42 +02:00
|
|
|
c2.SetDeadline(time.Now().Add(someTimeout))
|
|
|
|
c2.SetReadDeadline(time.Now().Add(someTimeout))
|
|
|
|
c2.SetWriteDeadline(time.Now().Add(someTimeout))
|
2012-11-21 08:03:38 +01:00
|
|
|
c2.SetReadBuffer(2048)
|
|
|
|
c2.SetWriteBuffer(2048)
|
|
|
|
|
2013-07-16 08:54:42 +02:00
|
|
|
a3, err := ResolveUnixAddr("unixgram", addr3)
|
2012-12-22 02:15:33 +01:00
|
|
|
if err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("ResolveUnixAddr failed: %v", err)
|
2012-12-22 02:15:33 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
c3, err := ListenUnixgram("unixgram", a3)
|
2012-12-22 02:15:33 +01:00
|
|
|
if err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("ListenUnixgram failed: %v", err)
|
2012-12-22 02:15:33 +01:00
|
|
|
}
|
2013-07-16 08:54:42 +02:00
|
|
|
defer c3.Close()
|
|
|
|
defer os.Remove(addr3)
|
2012-12-22 02:15:33 +01:00
|
|
|
c3.LocalAddr()
|
|
|
|
c3.RemoteAddr()
|
2013-07-16 08:54:42 +02:00
|
|
|
c3.SetDeadline(time.Now().Add(someTimeout))
|
|
|
|
c3.SetReadDeadline(time.Now().Add(someTimeout))
|
|
|
|
c3.SetWriteDeadline(time.Now().Add(someTimeout))
|
2012-12-22 02:15:33 +01:00
|
|
|
c3.SetReadBuffer(2048)
|
|
|
|
c3.SetWriteBuffer(2048)
|
|
|
|
|
2012-11-21 08:03:38 +01:00
|
|
|
wb := []byte("UNIXCONN TEST")
|
|
|
|
rb1 := make([]byte, 128)
|
|
|
|
rb2 := make([]byte, 128)
|
2012-12-22 02:15:33 +01:00
|
|
|
rb3 := make([]byte, 128)
|
2012-11-21 08:03:38 +01:00
|
|
|
if _, _, err := c1.WriteMsgUnix(wb, nil, a2); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("UnixConn.WriteMsgUnix failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
if _, _, _, _, err := c2.ReadMsgUnix(rb2, nil); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("UnixConn.ReadMsgUnix failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
if _, err := c2.WriteToUnix(wb, a1); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("UnixConn.WriteToUnix failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
|
|
|
if _, _, err := c1.ReadFromUnix(rb1); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("UnixConn.ReadFromUnix failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|
2012-12-22 02:15:33 +01:00
|
|
|
if _, err := c3.WriteToUnix(wb, a1); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("UnixConn.WriteToUnix failed: %v", err)
|
2012-12-22 02:15:33 +01:00
|
|
|
}
|
|
|
|
if _, _, err := c1.ReadFromUnix(rb1); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("UnixConn.ReadFromUnix failed: %v", err)
|
2012-12-22 02:15:33 +01:00
|
|
|
}
|
|
|
|
if _, err := c2.WriteToUnix(wb, a3); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("UnixConn.WriteToUnix failed: %v", err)
|
2012-12-22 02:15:33 +01:00
|
|
|
}
|
|
|
|
if _, _, err := c3.ReadFromUnix(rb3); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("UnixConn.ReadFromUnix failed: %v", err)
|
2012-12-22 02:15:33 +01:00
|
|
|
}
|
2012-11-21 08:03:38 +01:00
|
|
|
|
|
|
|
if f, err := c1.File(); err != nil {
|
2013-07-16 08:54:42 +02:00
|
|
|
t.Fatalf("UnixConn.File failed: %v", err)
|
2012-11-21 08:03:38 +01:00
|
|
|
} else {
|
|
|
|
f.Close()
|
|
|
|
}
|
2013-11-06 20:49:01 +01:00
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if p := recover(); p != nil {
|
|
|
|
t.Fatalf("UnixConn.WriteToUnix or WriteMsgUnix panicked: %v", p)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
c1.WriteToUnix(wb, nil)
|
|
|
|
c1.WriteMsgUnix(wb, nil, nil)
|
|
|
|
c3.WriteToUnix(wb, nil)
|
|
|
|
c3.WriteMsgUnix(wb, nil, nil)
|
2012-11-21 08:03:38 +01:00
|
|
|
}
|