mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
netchan: provide a method (Importer.Errors()) to recover protocol errors.
R=rsc CC=golang-dev https://golang.org/cl/2229044
This commit is contained in:
parent
8a313e201a
commit
da705c6212
3 changed files with 61 additions and 5 deletions
|
|
@ -28,6 +28,7 @@ type Importer struct {
|
|||
conn net.Conn
|
||||
chanLock sync.Mutex // protects access to channel map
|
||||
chans map[string]*chanDir
|
||||
errors chan os.Error
|
||||
}
|
||||
|
||||
// NewImporter creates a new Importer object to import channels
|
||||
|
|
@ -43,6 +44,7 @@ func NewImporter(network, remoteaddr string) (*Importer, os.Error) {
|
|||
imp.encDec = newEncDec(conn)
|
||||
imp.conn = conn
|
||||
imp.chans = make(map[string]*chanDir)
|
||||
imp.errors = make(chan os.Error, 10)
|
||||
go imp.run()
|
||||
return imp, nil
|
||||
}
|
||||
|
|
@ -86,15 +88,18 @@ func (imp *Importer) run() {
|
|||
}
|
||||
if err.error != "" {
|
||||
impLog("response error:", err.error)
|
||||
imp.shutdown()
|
||||
return
|
||||
if sent := imp.errors <- os.ErrorString(err.error); !sent {
|
||||
imp.shutdown()
|
||||
return
|
||||
}
|
||||
continue // errors are not acknowledged.
|
||||
}
|
||||
case payClosed:
|
||||
ich := imp.getChan(hdr.name)
|
||||
if ich != nil {
|
||||
ich.ch.Close()
|
||||
}
|
||||
continue
|
||||
continue // closes are not acknowledged.
|
||||
default:
|
||||
impLog("unexpected payload type:", hdr.payloadType)
|
||||
return
|
||||
|
|
@ -132,6 +137,14 @@ func (imp *Importer) getChan(name string) *chanDir {
|
|||
return ich
|
||||
}
|
||||
|
||||
// Errors returns a channel from which transmission and protocol errors
|
||||
// can be read. Clients of the importer are not required to read the error
|
||||
// channel for correct execution. However, if too many errors occur
|
||||
// without being read from the error channel, the importer will shut down.
|
||||
func (imp *Importer) Errors() chan os.Error {
|
||||
return imp.errors
|
||||
}
|
||||
|
||||
// Import imports a channel of the given type and specified direction.
|
||||
// It is equivalent to ImportNValues with a count of -1, meaning unbounded.
|
||||
func (imp *Importer) Import(name string, chT interface{}, dir Dir) os.Error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue