mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
connection CloseChan method
This commit is contained in:
parent
3b59bcc0f3
commit
68e62f3eb7
4 changed files with 31 additions and 7 deletions
|
@ -133,6 +133,20 @@ func (mr *MockMultiConnMockRecorder) Close() *gomock.Call {
|
|||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockMultiConn)(nil).Close))
|
||||
}
|
||||
|
||||
// CloseChan mocks base method.
|
||||
func (m *MockMultiConn) CloseChan() <-chan struct{} {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "CloseChan")
|
||||
ret0, _ := ret[0].(<-chan struct{})
|
||||
return ret0
|
||||
}
|
||||
|
||||
// CloseChan indicates an expected call of CloseChan.
|
||||
func (mr *MockMultiConnMockRecorder) CloseChan() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CloseChan", reflect.TypeOf((*MockMultiConn)(nil).CloseChan))
|
||||
}
|
||||
|
||||
// Context mocks base method.
|
||||
func (m *MockMultiConn) Context() context.Context {
|
||||
m.ctrl.T.Helper()
|
||||
|
|
|
@ -3,10 +3,12 @@ package quic
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
|
||||
"github.com/quic-go/quic-go"
|
||||
|
||||
"github.com/anyproto/any-sync/net/peer"
|
||||
"github.com/anyproto/any-sync/net/transport"
|
||||
"github.com/quic-go/quic-go"
|
||||
"net"
|
||||
)
|
||||
|
||||
func newConn(cctx context.Context, qconn quic.Connection) transport.MultiConn {
|
||||
|
@ -61,13 +63,17 @@ func (q *quicMultiConn) Addr() string {
|
|||
|
||||
func (q *quicMultiConn) IsClosed() bool {
|
||||
select {
|
||||
case <-q.Connection.Context().Done():
|
||||
case <-q.CloseChan():
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (q *quicMultiConn) CloseChan() <-chan struct{} {
|
||||
return q.Connection.Context().Done()
|
||||
}
|
||||
|
||||
func (q *quicMultiConn) Close() error {
|
||||
return q.Connection.CloseWithError(2, "")
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@ type MultiConn interface {
|
|||
Addr() string
|
||||
// IsClosed returns true when connection is closed
|
||||
IsClosed() bool
|
||||
// CloseChan returns a channel that will be closed with connection
|
||||
CloseChan() <-chan struct{}
|
||||
// Close closes the connection and all sub connections
|
||||
Close() error
|
||||
}
|
||||
|
|
|
@ -2,13 +2,15 @@ package yamux
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/anyproto/any-sync/net/connutil"
|
||||
"github.com/anyproto/any-sync/net/peer"
|
||||
"github.com/anyproto/any-sync/net/transport"
|
||||
"github.com/hashicorp/yamux"
|
||||
"io"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/yamux"
|
||||
|
||||
"github.com/anyproto/any-sync/net/connutil"
|
||||
"github.com/anyproto/any-sync/net/peer"
|
||||
"github.com/anyproto/any-sync/net/transport"
|
||||
)
|
||||
|
||||
func NewMultiConn(cctx context.Context, luConn *connutil.LastUsageConn, addr string, sess *yamux.Session) transport.MultiConn {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue