|  | @@ -8,6 +8,7 @@ import (
 | 
											
												
													
														|  |  	"time"
 |  |  	"time"
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  	"v2ray.com/core/app/log"
 |  |  	"v2ray.com/core/app/log"
 | 
											
												
													
														|  | 
 |  | +	"v2ray.com/core/common/buf"
 | 
											
												
													
														|  |  	"v2ray.com/core/common/predicate"
 |  |  	"v2ray.com/core/common/predicate"
 | 
											
												
													
														|  |  )
 |  |  )
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -330,6 +331,31 @@ func (v *Connection) Write(b []byte) (int, error) {
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +func (c *Connection) WriteMultiBuffer(mb buf.MultiBuffer) (int, error) {
 | 
											
												
													
														|  | 
 |  | +	defer mb.Release()
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +	if len(mb) == 0 {
 | 
											
												
													
														|  | 
 |  | +		return 0, nil
 | 
											
												
													
														|  | 
 |  | +	}
 | 
											
												
													
														|  | 
 |  | +	if len(mb) == 1 {
 | 
											
												
													
														|  | 
 |  | +		return c.Write(mb[0].Bytes())
 | 
											
												
													
														|  | 
 |  | +	}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +	buffer := buf.New()
 | 
											
												
													
														|  | 
 |  | +	defer buffer.Release()
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +	totalBytes := 0
 | 
											
												
													
														|  | 
 |  | +	for !mb.IsEmpty() {
 | 
											
												
													
														|  | 
 |  | +		buffer.Reset(buf.ReadFrom(&mb))
 | 
											
												
													
														|  | 
 |  | +		nBytes, err := c.Write(buffer.Bytes())
 | 
											
												
													
														|  | 
 |  | +		totalBytes += nBytes
 | 
											
												
													
														|  | 
 |  | +		if err != nil {
 | 
											
												
													
														|  | 
 |  | +			return totalBytes, err
 | 
											
												
													
														|  | 
 |  | +		}
 | 
											
												
													
														|  | 
 |  | +	}
 | 
											
												
													
														|  | 
 |  | +	return totalBytes, nil
 | 
											
												
													
														|  | 
 |  | +}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  func (v *Connection) SetState(state State) {
 |  |  func (v *Connection) SetState(state State) {
 | 
											
												
													
														|  |  	current := v.Elapsed()
 |  |  	current := v.Elapsed()
 | 
											
												
													
														|  |  	atomic.StoreInt32((*int32)(&v.state), int32(state))
 |  |  	atomic.StoreInt32((*int32)(&v.state), int32(state))
 |