BackedPipe provides a reliable bidirectional byte stream over unreliable network connections. It orchestrates a BackedReader and BackedWriter to provide transparent reconnection and data replay capabilities.
| 66 | // It orchestrates a BackedReader and BackedWriter to provide transparent reconnection |
| 67 | // and data replay capabilities. |
| 68 | type BackedPipe struct { |
| 69 | ctx context.Context |
| 70 | cancel context.CancelFunc |
| 71 | mu sync.RWMutex |
| 72 | reader *BackedReader |
| 73 | writer *BackedWriter |
| 74 | reconnector Reconnector |
| 75 | conn io.ReadWriteCloser |
| 76 | |
| 77 | // State machine |
| 78 | state connectionState |
| 79 | connGen uint64 // Increments on each successful reconnection |
| 80 | |
| 81 | // Unified error handling with generation filtering |
| 82 | errChan chan ErrorEvent |
| 83 | |
| 84 | // forceReconnectHook is a test hook invoked after ForceReconnect registers |
| 85 | // with the singleflight group. |
| 86 | forceReconnectHook func() |
| 87 | |
| 88 | // singleflight group to dedupe concurrent ForceReconnect calls |
| 89 | sf singleflight.Group |
| 90 | |
| 91 | // Track first error per generation to avoid duplicate reconnections |
| 92 | lastErrorGen uint64 |
| 93 | } |
| 94 | |
| 95 | // NewBackedPipe creates a new BackedPipe with default options and the specified reconnector. |
| 96 | // The pipe starts disconnected and must be connected using Connect(). |
nothing calls this directly
no outgoing calls
no test coverage detected