mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-23 06:31:35 +00:00
commit
ca73cf9e98
@ -137,20 +137,23 @@ func (c *Conn) doSearch() {
|
|||||||
go func() { c.core.router.admin <- routerWork }()
|
go func() { c.core.router.admin <- routerWork }()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) getDeadlineCancellation(value *atomic.Value) util.Cancellation {
|
func (c *Conn) getDeadlineCancellation(value *atomic.Value) (util.Cancellation, bool) {
|
||||||
if deadline, ok := value.Load().(time.Time); ok {
|
if deadline, ok := value.Load().(time.Time); ok {
|
||||||
// A deadline is set, so return a Cancellation that uses it
|
// A deadline is set, so return a Cancellation that uses it
|
||||||
return util.CancellationWithDeadline(c.session.cancel, deadline)
|
c := util.CancellationWithDeadline(c.session.cancel, deadline)
|
||||||
|
return c, true
|
||||||
} else {
|
} else {
|
||||||
// No cancellation was set, so return a child cancellation with no timeout
|
// No deadline was set, so just return the existinc cancellation and a dummy value
|
||||||
return util.CancellationChild(c.session.cancel)
|
return c.session.cancel, false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used internally by Read, the caller is responsible for util.PutBytes when they're done.
|
// Used internally by Read, the caller is responsible for util.PutBytes when they're done.
|
||||||
func (c *Conn) ReadNoCopy() ([]byte, error) {
|
func (c *Conn) ReadNoCopy() ([]byte, error) {
|
||||||
cancel := c.getDeadlineCancellation(&c.readDeadline)
|
cancel, doCancel := c.getDeadlineCancellation(&c.readDeadline)
|
||||||
|
if doCancel {
|
||||||
defer cancel.Cancel(nil)
|
defer cancel.Cancel(nil)
|
||||||
|
}
|
||||||
// Wait for some traffic to come through from the session
|
// Wait for some traffic to come through from the session
|
||||||
select {
|
select {
|
||||||
case <-cancel.Finished():
|
case <-cancel.Finished():
|
||||||
@ -207,8 +210,10 @@ func (c *Conn) WriteNoCopy(msg FlowKeyMessage) error {
|
|||||||
}
|
}
|
||||||
c.session.doFunc(sessionFunc)
|
c.session.doFunc(sessionFunc)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
cancel := c.getDeadlineCancellation(&c.writeDeadline)
|
cancel, doCancel := c.getDeadlineCancellation(&c.writeDeadline)
|
||||||
|
if doCancel {
|
||||||
defer cancel.Cancel(nil)
|
defer cancel.Cancel(nil)
|
||||||
|
}
|
||||||
select {
|
select {
|
||||||
case <-cancel.Finished():
|
case <-cancel.Finished():
|
||||||
if cancel.Error() == util.CancellationTimeoutError {
|
if cancel.Error() == util.CancellationTimeoutError {
|
||||||
|
Loading…
Reference in New Issue
Block a user