|
@@ -3,6 +3,7 @@ package yamux
|
|
import (
|
|
import (
|
|
"bufio"
|
|
"bufio"
|
|
"bytes"
|
|
"bytes"
|
|
|
|
+ "context"
|
|
"fmt"
|
|
"fmt"
|
|
"io"
|
|
"io"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
@@ -250,6 +251,22 @@ func (s *Session) AcceptStream() (*Stream, error) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// AcceptStream is used to block until the next available stream
|
|
|
|
+// is ready to be accepted.
|
|
|
|
+func (s *Session) AcceptStreamWithContext(ctx context.Context) (*Stream, error) {
|
|
|
|
+ select {
|
|
|
|
+ case <-ctx.Done():
|
|
|
|
+ return nil, ctx.Err()
|
|
|
|
+ case stream := <-s.acceptCh:
|
|
|
|
+ if err := stream.sendWindowUpdate(); err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+ return stream, nil
|
|
|
|
+ case <-s.shutdownCh:
|
|
|
|
+ return nil, s.shutdownErr
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
// Close is used to close the session and all streams.
|
|
// Close is used to close the session and all streams.
|
|
// Attempts to send a GoAway before closing the connection.
|
|
// Attempts to send a GoAway before closing the connection.
|
|
func (s *Session) Close() error {
|
|
func (s *Session) Close() error {
|