mirror of https://github.com/v2ray/v2ray-core
fix kcp for not sending data immediately
parent
6f4bddd62e
commit
0a6a9547a0
|
@ -338,10 +338,15 @@ func (c *Connection) waitForDataOutput() error {
|
||||||
|
|
||||||
// Write implements io.Writer.
|
// Write implements io.Writer.
|
||||||
func (c *Connection) Write(b []byte) (int, error) {
|
func (c *Connection) Write(b []byte) (int, error) {
|
||||||
totalWritten := 0
|
updatePending := false
|
||||||
|
defer func() {
|
||||||
|
if updatePending {
|
||||||
|
c.dataUpdater.WakeUp()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
dataWritten := false
|
totalWritten := 0
|
||||||
for {
|
for {
|
||||||
if c == nil || c.State() != StateActive {
|
if c == nil || c.State() != StateActive {
|
||||||
return totalWritten, io.ErrClosedPipe
|
return totalWritten, io.ErrClosedPipe
|
||||||
|
@ -354,15 +359,16 @@ func (c *Connection) Write(b []byte) (int, error) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
dataWritten = true
|
updatePending = true
|
||||||
|
|
||||||
if totalWritten == len(b) {
|
if totalWritten == len(b) {
|
||||||
return totalWritten, nil
|
return totalWritten, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if dataWritten {
|
if updatePending {
|
||||||
c.dataUpdater.WakeUp()
|
c.dataUpdater.WakeUp()
|
||||||
|
updatePending = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.waitForDataOutput(); err != nil {
|
if err := c.waitForDataOutput(); err != nil {
|
||||||
|
@ -375,8 +381,14 @@ func (c *Connection) Write(b []byte) (int, error) {
|
||||||
func (c *Connection) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
func (c *Connection) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
||||||
defer mb.Release()
|
defer mb.Release()
|
||||||
|
|
||||||
|
updatePending := false
|
||||||
|
defer func() {
|
||||||
|
if updatePending {
|
||||||
|
c.dataUpdater.WakeUp()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
dataWritten := false
|
|
||||||
for {
|
for {
|
||||||
if c == nil || c.State() != StateActive {
|
if c == nil || c.State() != StateActive {
|
||||||
return io.ErrClosedPipe
|
return io.ErrClosedPipe
|
||||||
|
@ -387,14 +399,15 @@ func (c *Connection) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
||||||
}) {
|
}) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
dataWritten = true
|
updatePending = true
|
||||||
if mb.IsEmpty() {
|
if mb.IsEmpty() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if dataWritten {
|
if updatePending {
|
||||||
c.dataUpdater.WakeUp()
|
c.dataUpdater.WakeUp()
|
||||||
|
updatePending = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.waitForDataOutput(); err != nil {
|
if err := c.waitForDataOutput(); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue