forked from quic-go/quic-go
add a method to open new Streams to the client
This commit is contained in:
@@ -111,6 +111,11 @@ func (c *Client) Listen() error {
|
||||
}
|
||||
}
|
||||
|
||||
// OpenStream opens a stream, for client-side created streams (i.e. odd streamIDs)
|
||||
func (c *Client) OpenStream(id protocol.StreamID) (utils.Stream, error) {
|
||||
return c.session.OpenStream(id)
|
||||
}
|
||||
|
||||
// Close closes the connection
|
||||
func (c *Client) Close() error {
|
||||
_ = c.session.Close(nil)
|
||||
|
||||
@@ -82,6 +82,12 @@ var _ = Describe("Client", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
It("opens a stream", func() {
|
||||
stream, err := client.OpenStream(1337)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(stream.StreamID()).To(Equal(protocol.StreamID(1337)))
|
||||
})
|
||||
|
||||
Context("handling packets", func() {
|
||||
It("errors on too large packets", func() {
|
||||
err := client.handlePacket(bytes.Repeat([]byte{'f'}, int(protocol.MaxPacketSize+1)))
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
// packetHandler handles packets
|
||||
type packetHandler interface {
|
||||
handlePacket(*receivedPacket)
|
||||
OpenStream(protocol.StreamID) (utils.Stream, error)
|
||||
run()
|
||||
Close(error) error
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@ func (s *mockSession) Close(e error) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *mockSession) OpenStream(id protocol.StreamID) (utils.Stream, error) {
|
||||
return &stream{streamID: id}, nil
|
||||
}
|
||||
func newMockSession(conn connection, v protocol.VersionNumber, connectionID protocol.ConnectionID, sCfg *handshake.ServerConfig, streamCallback StreamCallback, closeCallback closeCallback) (packetHandler, error) {
|
||||
return &mockSession{
|
||||
connectionID: connectionID,
|
||||
|
||||
Reference in New Issue
Block a user