2020-10-16 09:38:57 +03:00
|
|
|
package transport
|
|
|
|
|
2020-11-03 02:02:32 +03:00
|
|
|
import "context"
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
type noopTransport struct {
|
2020-10-16 09:38:57 +03:00
|
|
|
opts Options
|
|
|
|
}
|
|
|
|
|
2020-12-08 00:38:37 +03:00
|
|
|
// NewTransport creates new noop transport
|
2020-11-03 01:08:23 +03:00
|
|
|
func NewTransport(opts ...Option) Transport {
|
|
|
|
return &noopTransport{opts: NewOptions(opts...)}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *noopTransport) Init(opts ...Option) error {
|
2020-10-16 09:38:57 +03:00
|
|
|
for _, o := range opts {
|
|
|
|
o(&t.opts)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
func (t *noopTransport) Options() Options {
|
2020-10-16 09:38:57 +03:00
|
|
|
return t.opts
|
|
|
|
}
|
|
|
|
|
2020-11-03 02:02:32 +03:00
|
|
|
func (t *noopTransport) Dial(ctx context.Context, addr string, opts ...DialOption) (Client, error) {
|
2020-10-16 09:38:57 +03:00
|
|
|
options := NewDialOptions(opts...)
|
|
|
|
return &noopClient{opts: options}, nil
|
|
|
|
}
|
|
|
|
|
2020-11-03 02:02:32 +03:00
|
|
|
func (t *noopTransport) Listen(ctx context.Context, addr string, opts ...ListenOption) (Listener, error) {
|
2020-10-16 09:38:57 +03:00
|
|
|
options := NewListenOptions(opts...)
|
|
|
|
return &noopListener{opts: options}, nil
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
func (t *noopTransport) String() string {
|
2020-10-16 09:38:57 +03:00
|
|
|
return "noop"
|
|
|
|
}
|
|
|
|
|
|
|
|
type noopClient struct {
|
|
|
|
opts DialOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *noopClient) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *noopClient) Local() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *noopClient) Remote() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *noopClient) Recv(*Message) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *noopClient) Send(*Message) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type noopListener struct {
|
|
|
|
opts ListenOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *noopListener) Addr() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *noopListener) Accept(fn func(Socket)) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *noopListener) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|