1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-12 16:24:19 -04:00
v2fly/transport/internet/kcp/connection_test.go

66 lines
1.1 KiB
Go
Raw Normal View History

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-12-08 10:27:41 -05:00
2017-10-24 10:15:35 -04:00
. "v2ray.com/ext/assert"
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-12-08 10:27:41 -05:00
func (o *NoOpConn) Overhead() int {
return 0
}
2017-04-21 09:36:05 -04:00
// Write implements io.Writer.
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
}
2016-12-08 10:27:41 -05:00
func (o *NoOpConn) Reset(input func([]Segment)) {}
2016-11-27 02:58:31 -05:00
2016-07-12 07:27:12 -04:00
func TestConnectionReadTimeout(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2016-07-12 07:27:12 -04:00
conn := NewConnection(1, &NoOpConn{}, &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)
2017-10-24 10:15:35 -04:00
assert(nBytes, Equals, 0)
assert(err, IsNotNil)
conn.Terminate()
2016-07-12 07:27:12 -04:00
}