Commit 06133187 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

decomp chan creation for listener + bugfix

test failed to compile, as NewSwarm now takes a parm.
parent 74d26449
......@@ -44,29 +44,36 @@ func Dial(network string, peer *peer.Peer) (*Conn, error) {
return nil, err
}
out := msgio.NewChan(10)
inc := msgio.NewChan(10)
conn := &Conn{
Peer: peer,
Addr: addr,
Conn: nconn,
}
Outgoing: out,
Incoming: inc,
Closed: make(chan bool, 1),
newConnChans(conn)
return conn, nil
}
// Construct new channels for given Conn.
func newConnChans(c *Conn) error {
if c.Outgoing != nil || c.Incoming != nil {
return fmt.Errorf("Conn already initialized")
}
go out.WriteTo(nconn)
go inc.ReadFrom(nconn, 1<<12)
c.Outgoing = msgio.NewChan(10)
c.Incoming = msgio.NewChan(10)
c.Closed = make(chan bool, 1)
return conn, nil
go c.Outgoing.WriteTo(c.Conn)
go c.Incoming.ReadFrom(c.Conn, 1<<12)
return nil
}
// Close closes the connection, and associated channels.
func (s *Conn) Close() error {
if s.Conn == nil {
return fmt.Errorf("Already closed.") // already closed
return fmt.Errorf("Already closed") // already closed
}
// closing net connection
......
......@@ -42,7 +42,7 @@ func pong(c net.Conn, peer *peer.Peer) {
func TestSwarm(t *testing.T) {
swarm := NewSwarm()
swarm := NewSwarm(nil)
peers := []*peer.Peer{}
listeners := []*net.Listener{}
peerNames := map[string]string{
......
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