Commit 6c092cf4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent c1e40bfe
...@@ -95,8 +95,8 @@ type listener struct { ...@@ -95,8 +95,8 @@ type listener struct {
} }
// allocFreeEntry finds first free port and allocate network entry for it // allocFreeEntry finds first free port and allocates network entry for it
// must be called under .mu held // must be called with .mu held
func (n *Network) allocFreeEntry() *entry { func (n *Network) allocFreeEntry() *entry {
// find first free port if it was not specified // find first free port if it was not specified
port := 0 port := 0
...@@ -153,8 +153,8 @@ func (l *listener) Close() error { ...@@ -153,8 +153,8 @@ func (l *listener) Close() error {
} }
// Listen starts new listener // Listen starts new listener
// Ct either allocates new port if laddr is "" or binds to laddr. // It either allocates free port if laddr is "" or binds to laddr.
// Once listener is started Dials could connect to listener address. // Once listener is started Dials could connect to listening address.
// Connection requests created by Dials could be accepted via Accept. // Connection requests created by Dials could be accepted via Accept.
func (n *Network) Listen(laddr string) (net.Listener, error) { func (n *Network) Listen(laddr string) (net.Listener, error) {
lerr := func(err error) error { lerr := func(err error) error {
...@@ -243,20 +243,22 @@ func (n *Network) Dial(addr string) (net.Conn, error) { ...@@ -243,20 +243,22 @@ func (n *Network) Dial(addr string) (net.Conn, error) {
} }
n.mu.Lock() n.mu.Lock()
defer n.mu.Unlock() // XXX ok to defer here?
if port >= len(n.entryv) { if port >= len(n.entryv) {
return nil, derr(errConnRefused) // XXX merge with vvv n.mu.Unlock()
return nil, derr(errConnRefused)
} }
e := n.entryv[port] e := n.entryv[port]
if e == nil || e.listener == nil { if e == nil || e.listener == nil {
return nil, derr(errConnRefused) // XXX merge with ^^^ n.mu.Unlock()
return nil, derr(errConnRefused)
} }
l := e.listener l := e.listener
// NOTE listener is not locking n.mu -> it is ok to send/receive under mu - FIXME not correct // NOTE Accept is locking n.mu -> we must release n.mu before sending dial request
// FIXME -> Accept needs to register new connection under n.mu n.mu.Unlock()
resp := make(chan net.Conn) resp := make(chan net.Conn)
select { select {
case <-l.down: case <-l.down:
......
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