2016-07-12 07:27:12 -04:00
|
|
|
package kcp_test
|
|
|
|
|
|
|
|
import (
|
2016-11-27 02:58:31 -05:00
|
|
|
"net"
|
2016-07-12 07:27:12 -04:00
|
|
|
"testing"
|
|
|
|
"time"
|
2016-08-20 14:55:45 -04:00
|
|
|
"v2ray.com/core/testing/assert"
|
2016-11-27 02:58:31 -05:00
|
|
|
"v2ray.com/core/transport/internet"
|
|
|
|
"v2ray.com/core/transport/internet/internal"
|
2016-08-20 14:55:45 -04:00
|
|
|
. "v2ray.com/core/transport/internet/kcp"
|
2016-07-12 07:27:12 -04:00
|
|
|
)
|
|
|
|
|
2016-11-27 02:58:31 -05:00
|
|
|
type NoOpConn struct{}
|
2016-07-12 11:11:36 -04:00
|
|
|
|
2016-11-27 02:58:31 -05:00
|
|
|
func (o *NoOpConn) Write(b []byte) (int, error) {
|
2016-07-12 11:11:36 -04:00
|
|
|
return len(b), nil
|
|
|
|
}
|
|
|
|
|
2016-11-27 02:58:31 -05:00
|
|
|
func (o *NoOpConn) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *NoOpConn) Read([]byte) (int, error) {
|
|
|
|
panic("Should not be called.")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *NoOpConn) LocalAddr() net.Addr {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *NoOpConn) RemoteAddr() net.Addr {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *NoOpConn) SetDeadline(time.Time) error {
|
2016-07-12 11:11:36 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-11-27 02:58:31 -05:00
|
|
|
func (o *NoOpConn) SetReadDeadline(time.Time) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *NoOpConn) SetWriteDeadline(time.Time) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *NoOpConn) Id() internal.ConnectionId {
|
|
|
|
return internal.ConnectionId{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *NoOpConn) Reset(auth internet.Authenticator, input func([]byte)) {}
|
|
|
|
|
|
|
|
type NoOpRecycler struct{}
|
|
|
|
|
|
|
|
func (o *NoOpRecycler) Put(internal.ConnectionId, net.Conn) {}
|
|
|
|
|
2016-07-12 07:27:12 -04:00
|
|
|
func TestConnectionReadTimeout(t *testing.T) {
|
|
|
|
assert := assert.On(t)
|
|
|
|
|
2016-11-27 02:58:31 -05:00
|
|
|
conn := NewConnection(1, &NoOpConn{}, &NoOpRecycler{}, NewSimpleAuthenticator(), &Config{})
|
2016-07-12 07:27:12 -04:00
|
|
|
conn.SetReadDeadline(time.Now().Add(time.Second))
|
|
|
|
|
|
|
|
b := make([]byte, 1024)
|
|
|
|
nBytes, err := conn.Read(b)
|
|
|
|
assert.Int(nBytes).Equals(0)
|
|
|
|
assert.Error(err).IsNotNil()
|
2016-10-10 10:50:54 -04:00
|
|
|
|
|
|
|
conn.Terminate()
|
2016-07-12 07:27:12 -04:00
|
|
|
}
|