Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
06133187
Commit
06133187
authored
Jul 29, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decomp chan creation for listener + bugfix
test failed to compile, as NewSwarm now takes a parm.
parent
74d26449
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
11 deletions
+18
-11
swarm/conn.go
swarm/conn.go
+17
-10
swarm/swarm_test.go
swarm/swarm_test.go
+1
-1
No files found.
swarm/conn.go
View file @
06133187
...
...
@@ -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
...
...
swarm/swarm_test.go
View file @
06133187
...
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment