summaryrefslogtreecommitdiff
path: root/libgo/go/netchan/common.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/netchan/common.go')
-rw-r--r--libgo/go/netchan/common.go27
1 files changed, 19 insertions, 8 deletions
diff --git a/libgo/go/netchan/common.go b/libgo/go/netchan/common.go
index 56c0b25199f..dd06050ee50 100644
--- a/libgo/go/netchan/common.go
+++ b/libgo/go/netchan/common.go
@@ -6,7 +6,7 @@ package netchan
import (
"gob"
- "net"
+ "io"
"os"
"reflect"
"sync"
@@ -93,7 +93,7 @@ type encDec struct {
enc *gob.Encoder
}
-func newEncDec(conn net.Conn) *encDec {
+func newEncDec(conn io.ReadWriter) *encDec {
return &encDec{
dec: gob.NewDecoder(conn),
enc: gob.NewEncoder(conn),
@@ -199,9 +199,10 @@ func (cs *clientSet) sync(timeout int64) os.Error {
// are delivered into the local channel.
type netChan struct {
*chanDir
- name string
- id int
- size int // buffer size of channel.
+ name string
+ id int
+ size int // buffer size of channel.
+ closed bool
// sender-specific state
ackCh chan bool // buffered with space for all the acks we need
@@ -227,6 +228,9 @@ func newNetChan(name string, id int, ch *chanDir, ed *encDec, size int, count in
// Close the channel.
func (nch *netChan) close() {
+ if nch.closed {
+ return
+ }
if nch.dir == Recv {
if nch.sendCh != nil {
// If the sender goroutine is active, close the channel to it.
@@ -239,6 +243,7 @@ func (nch *netChan) close() {
nch.ch.Close()
close(nch.ackCh)
}
+ nch.closed = true
}
// Send message from remote side to local receiver.
@@ -256,7 +261,10 @@ func (nch *netChan) send(val reflect.Value) {
nch.sendCh = make(chan reflect.Value, nch.size)
go nch.sender()
}
- if ok := nch.sendCh <- val; !ok {
+ select {
+ case nch.sendCh <- val:
+ // ok
+ default:
// TODO: should this be more resilient?
panic("netchan: remote sender sent more values than allowed")
}
@@ -318,8 +326,11 @@ func (nch *netChan) acked() {
if nch.dir != Send {
panic("recv on wrong direction of channel")
}
- if ok := nch.ackCh <- true; !ok {
- panic("netchan: remote receiver sent too many acks")
+ select {
+ case nch.ackCh <- true:
+ // ok
+ default:
// TODO: should this be more resilient?
+ panic("netchan: remote receiver sent too many acks")
}
}