netchan: improve closing and shutdown. there's still more to do.

Fixes #805.

R=rsc
CC=golang-dev
https://golang.org/cl/1400041
This commit is contained in:
Rob Pike 2010-05-28 22:32:29 -07:00
parent 63f014910d
commit 752b47cfc5
3 changed files with 45 additions and 7 deletions

View file

@ -49,6 +49,17 @@ func NewImporter(network, remoteaddr string) (*Importer, os.Error) {
return imp, nil
}
// shutdown closes all channels for which we are receiving data from the remote side.
func (imp *Importer) shutdown() {
imp.chanLock.Lock()
for _, ich := range imp.chans {
if ich.dir == Recv {
ich.ch.Close()
}
}
imp.chanLock.Unlock()
}
// Handle the data from a single imported data stream, which will
// have the form
// (response, data)*
@ -60,6 +71,7 @@ func (imp *Importer) run() {
for {
if e := imp.decode(hdr); e != nil {
log.Stderr("importer header:", e)
imp.shutdown()
return
}
switch hdr.payloadType {
@ -72,7 +84,7 @@ func (imp *Importer) run() {
}
if err.error != "" {
log.Stderr("importer response error:", err.error)
// TODO: tear down connection
imp.shutdown()
return
}
default: