mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-02-20 23:47:21 -05:00
error message refactoring
This commit is contained in:
parent
81855469aa
commit
75b8dd9521
@ -14,10 +14,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errTimeout = errors.New("i/o timeout")
|
ErrIOTimeout = errors.New("Read/Write timeout")
|
||||||
errBrokenPipe = errors.New("broken pipe")
|
ErrClosedListener = errors.New("Listener closed.")
|
||||||
errClosedListener = errors.New("Listener closed.")
|
ErrClosedConnection = errors.New("Connection closed.")
|
||||||
errClosedConnection = errors.New("Connection closed.")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type State int32
|
type State int32
|
||||||
@ -212,7 +211,7 @@ func (this *Connection) Read(b []byte) (int, error) {
|
|||||||
if !this.rd.IsZero() {
|
if !this.rd.IsZero() {
|
||||||
duration := this.rd.Sub(time.Now())
|
duration := this.rd.Sub(time.Now())
|
||||||
if duration <= 0 {
|
if duration <= 0 {
|
||||||
return 0, errTimeout
|
return 0, ErrIOTimeout
|
||||||
}
|
}
|
||||||
timer = time.AfterFunc(duration, this.dataInputCond.Signal)
|
timer = time.AfterFunc(duration, this.dataInputCond.Signal)
|
||||||
}
|
}
|
||||||
@ -223,7 +222,7 @@ func (this *Connection) Read(b []byte) (int, error) {
|
|||||||
timer.Stop()
|
timer.Stop()
|
||||||
}
|
}
|
||||||
if !this.rd.IsZero() && this.rd.Before(time.Now()) {
|
if !this.rd.IsZero() && this.rd.Before(time.Now()) {
|
||||||
return 0, errTimeout
|
return 0, ErrIOTimeout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -249,7 +248,7 @@ func (this *Connection) Write(b []byte) (int, error) {
|
|||||||
if !this.wd.IsZero() {
|
if !this.wd.IsZero() {
|
||||||
duration := this.wd.Sub(time.Now())
|
duration := this.wd.Sub(time.Now())
|
||||||
if duration <= 0 {
|
if duration <= 0 {
|
||||||
return totalWritten, errTimeout
|
return totalWritten, ErrIOTimeout
|
||||||
}
|
}
|
||||||
timer = time.AfterFunc(duration, this.dataOutputCond.Signal)
|
timer = time.AfterFunc(duration, this.dataOutputCond.Signal)
|
||||||
}
|
}
|
||||||
@ -262,7 +261,7 @@ func (this *Connection) Write(b []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !this.wd.IsZero() && this.wd.Before(time.Now()) {
|
if !this.wd.IsZero() && this.wd.Before(time.Now()) {
|
||||||
return totalWritten, errTimeout
|
return totalWritten, ErrIOTimeout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -292,7 +291,7 @@ func (this *Connection) SetState(state State) {
|
|||||||
// Close closes the connection.
|
// Close closes the connection.
|
||||||
func (this *Connection) Close() error {
|
func (this *Connection) Close() error {
|
||||||
if this == nil {
|
if this == nil {
|
||||||
return errClosedConnection
|
return ErrClosedConnection
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dataInputCond.Broadcast()
|
this.dataInputCond.Broadcast()
|
||||||
@ -300,7 +299,7 @@ func (this *Connection) Close() error {
|
|||||||
|
|
||||||
state := this.State()
|
state := this.State()
|
||||||
if state.Is(StateReadyToClose, StateTerminating, StateTerminated) {
|
if state.Is(StateReadyToClose, StateTerminating, StateTerminated) {
|
||||||
return errClosedConnection
|
return ErrClosedConnection
|
||||||
}
|
}
|
||||||
log.Info("KCP|Connection: Closing connection to ", this.remote)
|
log.Info("KCP|Connection: Closing connection to ", this.remote)
|
||||||
|
|
||||||
@ -347,7 +346,7 @@ func (this *Connection) SetDeadline(t time.Time) error {
|
|||||||
// SetReadDeadline implements the Conn SetReadDeadline method.
|
// SetReadDeadline implements the Conn SetReadDeadline method.
|
||||||
func (this *Connection) SetReadDeadline(t time.Time) error {
|
func (this *Connection) SetReadDeadline(t time.Time) error {
|
||||||
if this == nil || this.State() != StateActive {
|
if this == nil || this.State() != StateActive {
|
||||||
return errClosedConnection
|
return ErrClosedConnection
|
||||||
}
|
}
|
||||||
this.rd = t
|
this.rd = t
|
||||||
return nil
|
return nil
|
||||||
@ -356,7 +355,7 @@ func (this *Connection) SetReadDeadline(t time.Time) error {
|
|||||||
// SetWriteDeadline implements the Conn SetWriteDeadline method.
|
// SetWriteDeadline implements the Conn SetWriteDeadline method.
|
||||||
func (this *Connection) SetWriteDeadline(t time.Time) error {
|
func (this *Connection) SetWriteDeadline(t time.Time) error {
|
||||||
if this == nil || this.State() != StateActive {
|
if this == nil || this.State() != StateActive {
|
||||||
return errClosedConnection
|
return ErrClosedConnection
|
||||||
}
|
}
|
||||||
this.wd = t
|
this.wd = t
|
||||||
return nil
|
return nil
|
||||||
|
@ -118,7 +118,7 @@ func (this *Listener) Remove(dest string) {
|
|||||||
func (this *Listener) Accept() (internet.Connection, error) {
|
func (this *Listener) Accept() (internet.Connection, error) {
|
||||||
for {
|
for {
|
||||||
if !this.running {
|
if !this.running {
|
||||||
return nil, errClosedListener
|
return nil, ErrClosedListener
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case conn := <-this.awaitingConns:
|
case conn := <-this.awaitingConns:
|
||||||
@ -132,7 +132,7 @@ func (this *Listener) Accept() (internet.Connection, error) {
|
|||||||
// Close stops listening on the UDP address. Already Accepted connections are not closed.
|
// Close stops listening on the UDP address. Already Accepted connections are not closed.
|
||||||
func (this *Listener) Close() error {
|
func (this *Listener) Close() error {
|
||||||
if !this.running {
|
if !this.running {
|
||||||
return errClosedListener
|
return ErrClosedListener
|
||||||
}
|
}
|
||||||
this.Lock()
|
this.Lock()
|
||||||
defer this.Unlock()
|
defer this.Unlock()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user