stream.go
changeset 29 a456133ed0ac
parent 26 4d0a369079ce
child 30 a77fc342e013
equal deleted inserted replaced
28:78961db80bae 29:a456133ed0ac
   193 			case *auth:
   193 			case *auth:
   194 				cl.handleSasl(obj)
   194 				cl.handleSasl(obj)
   195 			default:
   195 			default:
   196 				send = true
   196 				send = true
   197 			}
   197 			}
       
   198 			if !send {
       
   199 				continue
       
   200 			}
   198 			st, ok := x.(Stanza)
   201 			st, ok := x.(Stanza)
   199 			if !ok {
   202 			if !ok {
   200 				log.Printf("Unhandled non-stanza: %v",
   203 				log.Printf("Unhandled non-stanza: %v",
   201 					x)
   204 					x)
   202 				continue
   205 				continue
   211 			}
   214 			}
   212 		}
   215 		}
   213 	}
   216 	}
   214 }
   217 }
   215 
   218 
   216 // BUG(cjyar) Disable this loop until resource binding is
   219 // This loop is paused until resource binding is complete. Otherwise
   217 // complete. Otherwise the app might inject something weird into our
   220 // the app might inject something inappropriate into our negotiations
   218 // negotiation stream.
   221 // with the server. The control channel controls this loop's
   219 func writeStream(srvOut chan<- interface{}, cliIn <-chan Stanza) {
   222 // activity.
       
   223 func writeStream(srvOut chan<- interface{}, cliIn <-chan Stanza,
       
   224 	control <-chan int) {
   220 	defer tryClose(srvOut, cliIn)
   225 	defer tryClose(srvOut, cliIn)
   221 
   226 
   222 	for x := range cliIn {
   227 	var input <-chan Stanza
   223 		srvOut <- x
   228 	for {
       
   229 		select {
       
   230 		case status := <- control:
       
   231 			switch status {
       
   232 			case 0:
       
   233 				input = nil
       
   234 			case 1:
       
   235 				input = cliIn
       
   236 			case -1:
       
   237 				break
       
   238 			}
       
   239 		case x := <- input:
       
   240 			srvOut <- x
       
   241 		}
   224 	}
   242 	}
   225 }
   243 }
   226 
   244 
   227 func handleStream(ss *stream) {
   245 func handleStream(ss *stream) {
   228 }
   246 }
   511 			log.Println("Can't parse JID %s", jidStr)
   529 			log.Println("Can't parse JID %s", jidStr)
   512 			return false
   530 			return false
   513 		}
   531 		}
   514 		cl.Jid = *jid
   532 		cl.Jid = *jid
   515 		log.Printf("Bound resource: %s", cl.Jid.String())
   533 		log.Printf("Bound resource: %s", cl.Jid.String())
   516 		return true
   534 		cl.bindDone()
       
   535 		return false
   517 	}
   536 	}
   518 	cl.HandleStanza(msg.Id, f)
   537 	cl.HandleStanza(msg.Id, f)
   519 	cl.xmlOut <- msg
   538 	cl.xmlOut <- msg
   520 }
   539 }
   521 
   540