// writeUser processes a single set of return values from Buffer.Read. func (wc *writeConn) writeUser(writer *chain.ConnWriter, payload interface{}, seqno SeqNo, err error) (continueWriteLoop bool) { if err == io.EOF { // We've reached the EOF of the user write sequence. // Go back to listen for more reads from the buffer, in case a sync rewinds the buffer cursor. return true } if err == io.ErrUnexpectedEOF { // An unexpected termination has been reached, indicated by killing the buffer; nothing to send any longer. return false } if err != nil { panic("u") } // Encode chunk chunk := payload.(*Chunk) chunk.seqno = seqno // Sequence numbers are assigned 0-based integers raw, err := chunk.Encode() if err != nil { panic(err) } writer.Write(raw) // If connection is closed (no more writes) and the buffer is empty, it is time to kill the connection. if wc.bfr.Drained() { return false } return true }
// writeControl processes a single control message (SYNC or ACK). // ok equals false if the connection is permanently broken and should be killed. func writeControl(writer *chain.ConnWriter, msg encoder) { chunk, err := msg.Encode() if err != nil { panic(err) } writer.Write(chunk) }