code: func (e *endpoint) prepareForWrite(to *tcpip.FullAddress) (retry bool, err *tcpip.Error) {
  	switch e.state {
  	case stateInitial:
  	case stateConnected:
  		return false, nil
  
  	case stateBound:
  		if to == nil {
  			return false, tcpip.ErrDestinationRequired
  		}
  		return false, nil
  	default:
  		return false, tcpip.ErrInvalidEndpointState
  	}
  
  	e.mu.RUnlock()
  	defer e.mu.RLock()
  
  	e.mu.Lock()
  	defer e.mu.Unlock()
  
  	// The state changed when we released the shared locked and re-acquired
  	// it in exclusive mode. Try again.
  	if e.state != stateInitial {
  		return true, nil
  	}
  
  	// The state is still 'initial', so try to bind the endpoint.
  	if err := e.bindLocked(tcpip.FullAddress{}); err != nil {
  		return false, err
  	}
  
  	return true, nil
  }
docs: // prepareForWrite prepares the endpoint for sending data. In particular, it
  // binds it if it's still in the initial state. To do so, it must first
  // reacquire the mutex in exclusive mode.
  //
  // Returns true for retry if preparation should be retried.