# HG changeset patch # User Chris Jones # Date 1380589177 21600 # Node ID 7b5586a5e109dac32bf5ffd46c7c959bc79535cd # Parent 6570a6a9683b79174aaf615218cea0286fe9a3c5 Added a Close() function and fixed a couple of shutdown bugs. diff -r 6570a6a9683b -r 7b5586a5e109 TODO.txt --- a/TODO.txt Sun Sep 29 21:56:19 2013 -0600 +++ b/TODO.txt Mon Sep 30 18:59:37 2013 -0600 @@ -5,9 +5,6 @@ Eliminate as many uses of Generic as possible. -Think about how to gracefully shutdown. Probably have a Close() -function. - Get rid of logging. We're providing status updates. Include an error() receiver function that lets internals report their errors for return from NewClient(). diff -r 6570a6a9683b -r 7b5586a5e109 example/interact.go --- a/example/interact.go Sun Sep 29 21:56:19 2013 -0600 +++ b/example/interact.go Mon Sep 30 18:59:37 2013 -0600 @@ -52,7 +52,7 @@ if err != nil { log.Fatalf("NewClient(%v): %v", jid, err) } - defer close(c.Send) + defer c.Close() go func(ch <-chan xmpp.Stanza) { for obj := range ch { diff -r 6570a6a9683b -r 7b5586a5e109 xmpp/layer3.go --- a/xmpp/layer3.go Sun Sep 29 21:56:19 2013 -0600 +++ b/xmpp/layer3.go Mon Sep 30 18:59:37 2013 -0600 @@ -26,7 +26,10 @@ var input <-chan Stanza for { select { - case stat := <-status: + case stat, ok := <-status: + if !ok { + return + } switch stat { default: input = nil diff -r 6570a6a9683b -r 7b5586a5e109 xmpp/roster.go --- a/xmpp/roster.go Sun Sep 29 21:56:19 2013 -0600 +++ b/xmpp/roster.go Mon Sep 30 18:59:37 2013 -0600 @@ -79,6 +79,7 @@ go r.rosterMgr(rosterUpdate) recv := func(in <-chan Stanza, out chan<- Stanza) { defer close(out) + defer close(rosterUpdate) for stan := range in { rosterUpdate <- stan out <- stan diff -r 6570a6a9683b -r 7b5586a5e109 xmpp/xmpp.go --- a/xmpp/xmpp.go Sun Sep 29 21:56:19 2013 -0600 +++ b/xmpp/xmpp.go Mon Sep 30 18:59:37 2013 -0600 @@ -288,3 +288,10 @@ Debug.Log(buf) } } + +func (cl *Client) Close() { + // Shuts down the receivers: + cl.setStatus(StatusShutdown) + // Shuts down the senders: + close(cl.Send) +}