|  | @@ -143,26 +143,38 @@ func (s *Stream) ReadTimeout(timeout time.Duration) (buf.MultiBuffer, error) {
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -func (s *Stream) Write(data buf.MultiBuffer) error {
 |  | 
 | 
											
												
													
														|  | -	if data.IsEmpty() {
 |  | 
 | 
											
												
													
														|  | 
 |  | +func (s *Stream) waitForStreamSize() error {
 | 
											
												
													
														|  | 
 |  | +	if streamSizeLimit == 0 {
 | 
											
												
													
														|  |  		return nil
 |  |  		return nil
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +	s.access.RLock()
 | 
											
												
													
														|  | 
 |  | +	defer s.access.RUnlock()
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  	for streamSizeLimit > 0 && s.size >= streamSizeLimit {
 |  |  	for streamSizeLimit > 0 && s.size >= streamSizeLimit {
 | 
											
												
													
														|  |  		select {
 |  |  		select {
 | 
											
												
													
														|  |  		case <-s.ctx.Done():
 |  |  		case <-s.ctx.Done():
 | 
											
												
													
														|  |  			return io.ErrClosedPipe
 |  |  			return io.ErrClosedPipe
 | 
											
												
													
														|  |  		case <-s.readSignal:
 |  |  		case <-s.readSignal:
 | 
											
												
													
														|  | -			s.access.RLock()
 |  | 
 | 
											
												
													
														|  |  			if s.err || s.close {
 |  |  			if s.err || s.close {
 | 
											
												
													
														|  | -				data.Release()
 |  | 
 | 
											
												
													
														|  | -				s.access.RUnlock()
 |  | 
 | 
											
												
													
														|  |  				return io.ErrClosedPipe
 |  |  				return io.ErrClosedPipe
 | 
											
												
													
														|  |  			}
 |  |  			}
 | 
											
												
													
														|  | -			s.access.RUnlock()
 |  | 
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +	return nil
 | 
											
												
													
														|  | 
 |  | +}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +func (s *Stream) Write(data buf.MultiBuffer) error {
 | 
											
												
													
														|  | 
 |  | +	if data.IsEmpty() {
 | 
											
												
													
														|  | 
 |  | +		return nil
 | 
											
												
													
														|  | 
 |  | +	}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +	if err := s.waitForStreamSize(); err != nil {
 | 
											
												
													
														|  | 
 |  | +		data.Release()
 | 
											
												
													
														|  | 
 |  | +		return err
 | 
											
												
													
														|  | 
 |  | +	}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  	s.access.Lock()
 |  |  	s.access.Lock()
 | 
											
												
													
														|  |  	defer s.access.Unlock()
 |  |  	defer s.access.Unlock()
 | 
											
												
													
														|  |  
 |  |  
 |