Commit a35297b6 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 21902468
......@@ -67,6 +67,9 @@ type Conn struct {
connId uint32
rxq chan *PktBuf // received packets for this Conn go here
txerr chan error // transmit errors for this Conn go back here
// Conn has to be explicitly closed by user; it can also be closed by NodeLink.Close
closeOnce sync.Once
closed chan struct{}
}
......@@ -142,8 +145,7 @@ func (nl *NodeLink) Close() error {
// XXX only interrupt, not close? Or allow multiple conn.Close() ?
conn.close() // XXX err -> errv
}
nl.connTab = nil // XXX ok? vs panic on NewConn after close ?
nl.connTab = nil // clear + mark closed
return err
}
......@@ -219,6 +221,9 @@ func (nl *NodeLink) newConn(connId uint32) *Conn {
func (nl *NodeLink) NewConn() *Conn {
nl.connMu.Lock()
defer nl.connMu.Unlock()
if nl.connTab == nil {
panic("NewConn() on closed node-link")
}
c := nl.newConn(nl.nextConnId)
nl.nextConnId += 2
return c
......@@ -340,7 +345,9 @@ func (c *Conn) Recv() (*PktBuf, error) {
// worker for Close() & co
func (c *Conn) close() {
close(c.closed) // XXX better just close c.rxq + ??? for tx
c.closeOnce.Do(func() {
close(c.closed) // XXX better just close c.rxq + ??? for tx
})
}
// Close connection
......
......@@ -138,7 +138,6 @@ func nodeLinkPipe() (nl1, nl2 *NodeLink) {
func TestNodeLink(t *testing.T) {
// TODO catch exception -> add proper location from it -> t.Fatal (see git-backup)
println("111")
nl1, nl2 := nodeLinkPipe()
// Close vs recvPkt
......@@ -198,7 +197,6 @@ func TestNodeLink(t *testing.T) {
// test channels on top of nodelink
println("222")
nl1, nl2 = nodeLinkPipe()
// Close vs Recv
......@@ -229,7 +227,6 @@ func TestNodeLink(t *testing.T) {
xwait(wg)
// NodeLink.Close vs Conn.Send/Recv
println("333")
c11 := nl1.NewConn()
c12 := nl1.NewConn()
wg = WorkGroup()
......@@ -249,9 +246,10 @@ func TestNodeLink(t *testing.T) {
tdelay()
xclose(nl1)
xwait(wg)
xclose(c11)
xclose(c12)
xclose(nl2) // for completeness
println("444")
/*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment