Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p-quic-transport
Commits
943b593d
Commit
943b593d
authored
Aug 08, 2017
by
Marten Seemann
Browse files
remove Serve from the quicConn
parent
1506a05b
Changes
2
Hide whitespace changes
Inline
Side-by-side
conn.go
View file @
943b593d
...
...
@@ -63,16 +63,6 @@ func (c *quicConn) OpenStream() (smux.Stream, error) {
return
&
stream
{
str
},
err
}
func
(
c
*
quicConn
)
Serve
(
handler
smux
.
StreamHandler
)
{
for
{
// accept loop
s
,
err
:=
c
.
AcceptStream
()
if
err
!=
nil
{
return
// err always means closed.
}
go
handler
(
s
)
}
}
func
(
c
*
quicConn
)
Close
()
error
{
return
c
.
sess
.
Close
(
nil
)
}
...
...
conn_test.go
View file @
943b593d
...
...
@@ -6,7 +6,6 @@ import (
"net"
"time"
smux
"github.com/libp2p/go-stream-muxer"
quic
"github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/protocol"
...
...
@@ -133,47 +132,4 @@ var _ = Describe("Conn", func() {
Expect
(
err
)
.
To
(
MatchError
(
testErr
))
})
})
Context
(
"serving"
,
func
()
{
var
(
handler
func
(
smux
.
Stream
)
handlerCalled
bool
handlerCalledWith
smux
.
Stream
)
BeforeEach
(
func
()
{
handlerCalled
=
false
handlerCalledWith
=
nil
handler
=
func
(
s
smux
.
Stream
)
{
handlerCalledWith
=
s
handlerCalled
=
true
}
})
It
(
"calls the handler"
,
func
()
{
str
:=
&
mockStream
{
id
:
5
}
sess
.
streamToAccept
=
str
var
returned
bool
go
func
()
{
conn
.
Serve
(
handler
)
returned
=
true
}()
Eventually
(
func
()
bool
{
return
handlerCalled
})
.
Should
(
BeTrue
())
Expect
(
handlerCalledWith
.
(
*
stream
)
.
Stream
)
.
To
(
Equal
(
str
))
// make the go-routine return
sess
.
streamAcceptErr
=
errors
.
New
(
"stop test"
)
})
It
(
"returns when accepting a stream errors"
,
func
()
{
sess
.
streamAcceptErr
=
errors
.
New
(
"accept err"
)
var
returned
bool
go
func
()
{
conn
.
Serve
(
handler
)
returned
=
true
}()
Eventually
(
func
()
bool
{
return
returned
})
.
Should
(
BeTrue
())
Expect
(
handlerCalled
)
.
To
(
BeFalse
())
})
})
})
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