author | Chris Jones <chris@cjones.org> |
Sat, 09 Nov 2013 12:33:25 -0700 | |
changeset 180 | 3010996c1928 |
parent 167 | 7ce61108ed86 |
permissions | -rw-r--r-- |
143
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
1 |
// The lowest level of XMPP protocol, where TLS is applied after the |
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
2 |
// initial handshake. |
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
3 |
|
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
4 |
package xmpp |
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
5 |
|
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
6 |
import ( |
148
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
7 |
"crypto/tls" |
163
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
8 |
"fmt" |
143
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
9 |
"io" |
163
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
10 |
"log" |
145 | 11 |
"net" |
143
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
12 |
"time" |
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
13 |
) |
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
14 |
|
163
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
15 |
// If enabled, print all sent and received XML. |
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
16 |
var Debug = false |
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
17 |
|
148
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
18 |
var l1interval = time.Second |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
19 |
|
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
20 |
type layer1 struct { |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
21 |
sock net.Conn |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
22 |
recvSocks chan<- net.Conn |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
23 |
sendSocks chan net.Conn |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
24 |
} |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
25 |
|
163
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
26 |
func (cl *Client) startLayer1(sock net.Conn, recvWriter io.WriteCloser, |
153
bbd4166df95d
Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
148
diff
changeset
|
27 |
sendReader io.ReadCloser, status <-chan Status) *layer1 { |
148
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
28 |
l1 := layer1{sock: sock} |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
29 |
recvSocks := make(chan net.Conn) |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
30 |
l1.recvSocks = recvSocks |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
31 |
sendSocks := make(chan net.Conn, 1) |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
32 |
l1.sendSocks = sendSocks |
163
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
33 |
go cl.recvTransport(recvSocks, recvWriter, status) |
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
34 |
go cl.sendTransport(sendSocks, sendReader) |
148
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
35 |
recvSocks <- sock |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
36 |
sendSocks <- sock |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
37 |
return &l1 |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
38 |
} |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
39 |
|
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
40 |
func (l1 *layer1) startTls(conf *tls.Config) { |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
41 |
sendSockToSender := func(sock net.Conn) { |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
42 |
for { |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
43 |
select { |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
44 |
case <-l1.sendSocks: |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
45 |
case l1.sendSocks <- sock: |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
46 |
return |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
47 |
} |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
48 |
} |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
49 |
} |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
50 |
|
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
51 |
sendSockToSender(nil) |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
52 |
l1.recvSocks <- nil |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
53 |
l1.sock = tls.Client(l1.sock, conf) |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
54 |
sendSockToSender(l1.sock) |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
55 |
l1.recvSocks <- l1.sock |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
56 |
} |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
57 |
|
163
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
58 |
func (cl *Client) recvTransport(socks <-chan net.Conn, w io.WriteCloser, |
153
bbd4166df95d
Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
148
diff
changeset
|
59 |
status <-chan Status) { |
bbd4166df95d
Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
148
diff
changeset
|
60 |
|
143
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
61 |
defer w.Close() |
148
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
62 |
var sock net.Conn |
143
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
63 |
p := make([]byte, 1024) |
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
64 |
for { |
148
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
65 |
select { |
153
bbd4166df95d
Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
148
diff
changeset
|
66 |
case stat := <-status: |
167
7ce61108ed86
Expose the Status.Fatal function.
Chris Jones <chris@cjones.org>
parents:
163
diff
changeset
|
67 |
if stat.Fatal() { |
153
bbd4166df95d
Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
148
diff
changeset
|
68 |
return |
bbd4166df95d
Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
148
diff
changeset
|
69 |
} |
bbd4166df95d
Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
148
diff
changeset
|
70 |
|
148
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
71 |
case sock = <-socks: |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
72 |
default: |
143
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
73 |
} |
148
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
74 |
|
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
75 |
if sock == nil { |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
76 |
time.Sleep(l1interval) |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
77 |
} else { |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
78 |
sock.SetReadDeadline(time.Now().Add(l1interval)) |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
79 |
nr, err := sock.Read(p) |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
80 |
if nr == 0 { |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
81 |
if errno, ok := err.(*net.OpError); ok { |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
82 |
if errno.Timeout() { |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
83 |
continue |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
84 |
} |
143
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
85 |
} |
163
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
86 |
cl.setError(fmt.Errorf("recv: %v", err)) |
153
bbd4166df95d
Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
148
diff
changeset
|
87 |
return |
143
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
88 |
} |
163
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
89 |
if Debug { |
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
90 |
log.Printf("recv: %s", p[:nr]) |
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
91 |
} |
148
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
92 |
nw, err := w.Write(p[:nr]) |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
93 |
if nw < nr { |
163
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
94 |
cl.setError(fmt.Errorf("recv: %v", err)) |
153
bbd4166df95d
Simplified the API: There's only one constructor, and it does everything necessary to initiate the stream. StartSession() and Roster.Update() have both been eliminated.
Chris Jones <christian.jones@sri.com>
parents:
148
diff
changeset
|
95 |
return |
148
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
96 |
} |
143
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
97 |
} |
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
98 |
} |
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
99 |
} |
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
100 |
|
163
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
101 |
func (cl *Client) sendTransport(socks <-chan net.Conn, r io.Reader) { |
148
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
102 |
var sock net.Conn |
143
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
103 |
p := make([]byte, 1024) |
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
104 |
for { |
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
105 |
nr, err := r.Read(p) |
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
106 |
if nr == 0 { |
163
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
107 |
cl.setError(fmt.Errorf("send: %v", err)) |
143
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
108 |
break |
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
109 |
} |
163
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
110 |
if nr > 0 && Debug { |
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
111 |
log.Printf("send: %s", p[:nr]) |
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
112 |
} |
148
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
113 |
for nr > 0 { |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
114 |
select { |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
115 |
case sock = <-socks: |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
116 |
if sock != nil { |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
117 |
defer sock.Close() |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
118 |
} |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
119 |
default: |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
120 |
} |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
121 |
|
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
122 |
if sock == nil { |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
123 |
time.Sleep(l1interval) |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
124 |
} else { |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
125 |
nw, err := sock.Write(p[:nr]) |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
126 |
nr -= nw |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
127 |
if nr != 0 { |
163
3f891f7fe817
Removed the weirdo logging facility. There's now a Debug variable which can be set which replaces the former debug log. NewClient() will return an error if something goes wrong setting up the connection.
Chris Jones <chris@cjones.org>
parents:
153
diff
changeset
|
128 |
cl.setError(fmt.Errorf("send: %v", err)) |
148
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
129 |
break |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
130 |
} |
b1b4900eee5b
Made layers 1 and 3 more modular, shrinking the surface area of the coupling between them.
Chris Jones <christian.jones@sri.com>
parents:
147
diff
changeset
|
131 |
} |
143
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
132 |
} |
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
133 |
} |
62166e57800e
Split stream.go into layer1, layer2, layer3, and sasl.
Chris Jones <christian.jones@sri.com>
parents:
diff
changeset
|
134 |
} |