# HG changeset patch # User Chris Jones # Date 1379270569 21600 # Node ID aa9a0ae8f875c8b3058cb09c819d32dfc521ab77 # Parent 21a390dd35068d585722e4e2ca0c5a3ff4255c84 Changed the inputControl channel to send a custom type. diff -r 21a390dd3506 -r aa9a0ae8f875 TODO.txt --- a/TODO.txt Sun Sep 15 12:31:59 2013 -0600 +++ b/TODO.txt Sun Sep 15 12:42:49 2013 -0600 @@ -4,8 +4,6 @@ Maybe put auth-related stuff into its own structure inside Client, instead of at Client's top level. -Replace inputControl with something like an enum. - Add a way to broadcast status information as negotiation happens or disconnects occur. Possibly a new type of object that can be sent on Recv along with stanzas. Or use sync.Cond to protect a state diff -r 21a390dd3506 -r aa9a0ae8f875 xmpp/layer3.go --- a/xmpp/layer3.go Sun Sep 15 12:31:59 2013 -0600 +++ b/xmpp/layer3.go Sun Sep 15 12:42:49 2013 -0600 @@ -63,21 +63,19 @@ // with the server. The control channel controls this loop's // activity. func writeStream(srvOut chan<- interface{}, cliIn <-chan Stanza, - control <-chan int) { + control <-chan sendCmd) { defer close(srvOut) var input <-chan Stanza Loop: for { select { - case status := <-control: - switch status { - case 0: + case cmd := <-control: + switch cmd { + case sendDeny: input = nil - case 1: + case sendAllow: input = cliIn - case -1: - break Loop } case x, ok := <-input: if !ok { diff -r 21a390dd3506 -r aa9a0ae8f875 xmpp/xmpp.go --- a/xmpp/xmpp.go Sun Sep 15 12:31:59 2013 -0600 +++ b/xmpp/xmpp.go Sun Sep 15 12:42:49 2013 -0600 @@ -37,6 +37,15 @@ clientSrv = "xmpp-client" ) +// Flow control for preventing sending stanzas until negotiation has +// completed. +type sendCmd bool + +var ( + sendAllow sendCmd = true + sendDeny sendCmd = false +) + // A filter can modify the XMPP traffic to or from the remote // server. It's part of an Extension. The filter function will be // called in a new goroutine, so it doesn't need to return. The filter @@ -68,7 +77,7 @@ saslExpected string authDone bool handlers chan *callback - inputControl chan int + inputControl chan sendCmd // Incoming XMPP stanzas from the remote will be published on // this channel. Information which is used by this library to // set up the XMPP stream will not appear here. @@ -138,7 +147,7 @@ cl.Jid = *jid cl.socket = tcp cl.handlers = make(chan *callback, 100) - cl.inputControl = make(chan int) + cl.inputControl = make(chan sendCmd) cl.tlsConfig = tlsconf cl.sendFilterAdd = make(chan Filter) cl.recvFilterAdd = make(chan Filter) @@ -229,7 +238,7 @@ // the negotiations that precede it). Now we can start accepting // traffic from the app. func (cl *Client) bindDone() { - cl.inputControl <- 1 + cl.inputControl <- sendAllow } // Start an XMPP session. A typical XMPP client should call this