code: func (e *endpoint) handleSegments() *tcpip.Error {
  	checkRequeue := true
  	for i := 0; i < maxSegmentsPerWake; i++ {
  		s := e.segmentQueue.dequeue()
  		if s == nil {
  			checkRequeue = false
  			break
  		}
  
  		// Invoke the tcp probe if installed.
  		if e.probe != nil {
  			e.probe(e.completeState())
  		}
  
  		if s.flagIsSet(header.TCPFlagRst) {
  			if e.rcv.acceptable(s.sequenceNumber, 0) {
  				// RFC 793, page 37 states that "in all states
  				// except SYN-SENT, all reset (RST) segments are
  				// validated by checking their SEQ-fields." So
  				// we only process it if it's acceptable.
  				s.decRef()
  				return tcpip.ErrConnectionReset
  			}
  		} else if s.flagIsSet(header.TCPFlagAck) {
  			// Patch the window size in the segment according to the
  			// send window scale.
  			s.window <<= e.snd.sndWndScale
  
  			// RFC 793, page 41 states that "once in the ESTABLISHED
  			// state all segments must carry current acknowledgment
  			// information."
  			e.rcv.handleRcvdSegment(s)
  			e.snd.handleRcvdSegment(s)
  		}
  		s.decRef()
  	}
  
  	// If the queue is not empty, make sure we'll wake up in the next
  	// iteration.
  	if checkRequeue && !e.segmentQueue.empty() {
  		e.newSegmentWaker.Assert()
  	}
  
  	// Send an ACK for all processed packets if needed.
  	if e.rcv.rcvNxt != e.snd.maxSentAck {
  		e.snd.sendAck()
  	}
  
  	e.resetKeepaliveTimer(true)
  
  	return nil
  }
docs: // handleSegments pulls segments from the queue and processes them. It returns
  // no error if the protocol loop should continue, an error otherwise.