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.
// The lowest level of XMPP protocol, where TLS is applied after the// initial handshake.packagexmppimport("crypto/tls""fmt""io""log""net""time")// If enabled, print all sent and received XML.varDebug=falsevarl1interval=time.Secondtypelayer1struct{socknet.ConnrecvSockschan<-net.ConnsendSockschannet.Conn}func(cl*Client)startLayer1(socknet.Conn,recvWriterio.WriteCloser,sendReaderio.ReadCloser,status<-chanStatus)*layer1{l1:=layer1{sock:sock}recvSocks:=make(channet.Conn)l1.recvSocks=recvSockssendSocks:=make(channet.Conn,1)l1.sendSocks=sendSocksgocl.recvTransport(recvSocks,recvWriter,status)gocl.sendTransport(sendSocks,sendReader)recvSocks<-socksendSocks<-sockreturn&l1}func(l1*layer1)startTls(conf*tls.Config){sendSockToSender:=func(socknet.Conn){for{select{case<-l1.sendSocks:casel1.sendSocks<-sock:return}}}sendSockToSender(nil)l1.recvSocks<-nill1.sock=tls.Client(l1.sock,conf)sendSockToSender(l1.sock)l1.recvSocks<-l1.sock}func(cl*Client)recvTransport(socks<-channet.Conn,wio.WriteCloser,status<-chanStatus){deferw.Close()varsocknet.Connp:=make([]byte,1024)for{select{casestat:=<-status:ifstat.fatal(){return}casesock=<-socks:default:}ifsock==nil{time.Sleep(l1interval)}else{sock.SetReadDeadline(time.Now().Add(l1interval))nr,err:=sock.Read(p)ifnr==0{iferrno,ok:=err.(*net.OpError);ok{iferrno.Timeout(){continue}}cl.setError(fmt.Errorf("recv: %v",err))return}ifDebug{log.Printf("recv: %s",p[:nr])}nw,err:=w.Write(p[:nr])ifnw<nr{cl.setError(fmt.Errorf("recv: %v",err))return}}}}func(cl*Client)sendTransport(socks<-channet.Conn,rio.Reader){varsocknet.Connp:=make([]byte,1024)for{nr,err:=r.Read(p)ifnr==0{cl.setError(fmt.Errorf("send: %v",err))break}ifnr>0&&Debug{log.Printf("send: %s",p[:nr])}fornr>0{select{casesock=<-socks:ifsock!=nil{defersock.Close()}default:}ifsock==nil{time.Sleep(l1interval)}else{nw,err:=sock.Write(p[:nr])nr-=nwifnr!=0{cl.setError(fmt.Errorf("send: %v",err))break}}}}}