func timeoutWriteHeader(w *xdr.Writer, hdr header) { // This tries to write a message header to w, but times out after a while. // This is useful because in testing, with a PipeWriter, it will block // forever if the other side isn't reading any more. On the other hand we // can't just "go" it into the background, because if the other side is // still there we should wait for the write to complete. Yay. var buf [8]byte // header and message length binary.BigEndian.PutUint32(buf[:], encodeHeader(hdr)) binary.BigEndian.PutUint32(buf[4:], 0) // zero message length, explicitly done := make(chan struct{}) go func() { w.WriteRaw(buf[:]) l.Infoln("write completed") close(done) }() select { case <-done: case <-time.After(250 * time.Millisecond): } }
func (u *Opaque) encodeXDR(w *xdr.Writer) (int, error) { return w.WriteRaw(u[:]) }