xmpp.go
branch20120108-close
changeset 63 c7f2edd25f4a
parent 62 6e2eea62ccca
child 64 ac0639692317
equal deleted inserted replaced
62:6e2eea62ccca 63:c7f2edd25f4a
    78 	Uid string
    78 	Uid string
    79 	// This client's JID. This will be updated asynchronously by
    79 	// This client's JID. This will be updated asynchronously by
    80 	// the time StartSession() returns.
    80 	// the time StartSession() returns.
    81 	Jid JID
    81 	Jid JID
    82 	password string
    82 	password string
       
    83 	tcp net.Conn
    83 	socket net.Conn
    84 	socket net.Conn
    84 	socketSync sync.WaitGroup
    85 	socketSync sync.WaitGroup
    85 	saslExpected string
    86 	saslExpected string
    86 	authDone bool
    87 	authDone bool
    87 	handlers chan *stanzaHandler
    88 	handlers chan *stanzaHandler
   100 	// StartSession() returns.
   101 	// StartSession() returns.
   101 	Features *Features
   102 	Features *Features
   102 	filterOut chan<- <-chan Stanza
   103 	filterOut chan<- <-chan Stanza
   103 	filterIn <-chan <-chan Stanza
   104 	filterIn <-chan <-chan Stanza
   104 }
   105 }
   105 var _ io.Closer = &Client{}
       
   106 
   106 
   107 // Connect to the appropriate server and authenticate as the given JID
   107 // Connect to the appropriate server and authenticate as the given JID
   108 // with the given password. This function will return as soon as a TCP
   108 // with the given password. This function will return as soon as a TCP
   109 // connection has been established, but before XMPP stream negotiation
   109 // connection has been established, but before XMPP stream negotiation
   110 // has completed. The negotiation will occur asynchronously, and any
   110 // has completed. The negotiation will occur asynchronously, and any
   145 
   145 
   146 	cl := new(Client)
   146 	cl := new(Client)
   147 	cl.Uid = <- Id
   147 	cl.Uid = <- Id
   148 	cl.password = password
   148 	cl.password = password
   149 	cl.Jid = *jid
   149 	cl.Jid = *jid
       
   150 	cl.tcp = tcp
   150 	cl.socket = tcp
   151 	cl.socket = tcp
   151 	cl.handlers = make(chan *stanzaHandler, 100)
   152 	cl.handlers = make(chan *stanzaHandler, 100)
   152 	cl.inputControl = make(chan int)
   153 	cl.inputControl = make(chan int)
   153 
   154 
   154 	extStanza := make(map[string] func(*xml.Name) interface{})
   155 	extStanza := make(map[string] func(*xml.Name) interface{})
   184 	// Initial handshake.
   185 	// Initial handshake.
   185 	hsOut := &stream{To: jid.Domain, Version: Version}
   186 	hsOut := &stream{To: jid.Domain, Version: Version}
   186 	cl.xmlOut <- hsOut
   187 	cl.xmlOut <- hsOut
   187 
   188 
   188 	return cl, nil
   189 	return cl, nil
   189 }
       
   190 
       
   191 func (c *Client) Close() os.Error {
       
   192 	tryClose(c.In, c.Out)
       
   193 	return nil
       
   194 }
   190 }
   195 
   191 
   196 func (cl *Client) startTransport() (io.Reader, io.Writer) {
   192 func (cl *Client) startTransport() (io.Reader, io.Writer) {
   197 	inr, inw := io.Pipe()
   193 	inr, inw := io.Pipe()
   198 	outr, outw := io.Pipe()
   194 	outr, outw := io.Pipe()