xmpp/layer1.go
changeset 163 3f891f7fe817
parent 153 bbd4166df95d
child 167 7ce61108ed86
--- a/xmpp/layer1.go	Mon Sep 30 18:59:37 2013 -0600
+++ b/xmpp/layer1.go	Mon Sep 30 20:31:25 2013 -0600
@@ -5,11 +5,16 @@
 
 import (
 	"crypto/tls"
+	"fmt"
 	"io"
+	"log"
 	"net"
 	"time"
 )
 
+// If enabled, print all sent and received XML.
+var Debug = false
+
 var l1interval = time.Second
 
 type layer1 struct {
@@ -18,15 +23,15 @@
 	sendSocks chan net.Conn
 }
 
-func startLayer1(sock net.Conn, recvWriter io.WriteCloser,
+func (cl *Client) startLayer1(sock net.Conn, recvWriter io.WriteCloser,
 	sendReader io.ReadCloser, status <-chan Status) *layer1 {
 	l1 := layer1{sock: sock}
 	recvSocks := make(chan net.Conn)
 	l1.recvSocks = recvSocks
 	sendSocks := make(chan net.Conn, 1)
 	l1.sendSocks = sendSocks
-	go recvTransport(recvSocks, recvWriter, status)
-	go sendTransport(sendSocks, sendReader)
+	go cl.recvTransport(recvSocks, recvWriter, status)
+	go cl.sendTransport(sendSocks, sendReader)
 	recvSocks <- sock
 	sendSocks <- sock
 	return &l1
@@ -50,7 +55,7 @@
 	l1.recvSocks <- l1.sock
 }
 
-func recvTransport(socks <-chan net.Conn, w io.WriteCloser,
+func (cl *Client) recvTransport(socks <-chan net.Conn, w io.WriteCloser,
 	status <-chan Status) {
 
 	defer w.Close()
@@ -59,7 +64,7 @@
 	for {
 		select {
 		case stat := <-status:
-			if stat == StatusShutdown {
+			if stat.fatal() {
 				return
 			}