-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathdoc.go
61 lines (60 loc) · 1.78 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2014 Mikio Hara. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package tcp implements TCP-level socket options.
//
// The package provides TCP-level socket options that allow
// manipulation of TCP connection facilities.
//
//
// Monitoring a TCP connection
//
// For now only Linux and FreeBSD kernels support the TCP information
// option. A custom net.Dial function that hooks up an underlying
// transport connection must be prepared before monitoring.
//
// func dialWithTCPConnMonitor(network, address string) (net.Conn, error) {
// d := net.Dialer{}
// c, err := d.Dial(network, address)
// if err != nil {
// return nil, err
// }
// tc, err := tcp.NewConn(c)
// if err != nil {
// c.Close()
// return nil, err
// }
// go tcpConnMonitor(tc) // launch a TCP connection monitor goroutine
// return &tc.TCPConn, nil
// }
//
// Also an application needs to construct a custom client such as a
// HTTP client containing a custom net.Dial function and get into a
// HTTP over TLS over TCP conversation.
//
// tr := &http.Transport{
// Dial: dialWithTCPConnMonitor,
// TLSClientConfig: &tls.Config{ServerName: host},
// }
// client := http.Client{Transport: tr}
// resp, err := client.Get(url)
// if err != nil {
// // error handling
// }
//
// When the underlying transport connection is established, your
// monitor goroutine can start monitoring the TCP connection by using
// the Info method of tcp.Conn.
//
// func tcpConnMonitor(c *tcp.Conn) {
// for {
// ti, err := c.Info() // fetch TCP connection information
// if err != nil {
// // error handling
// }
// text, err := json.Marshal(ti)
// if err != nil {
// // error handling
// }
// fmt.Println(text)
package tcp