-// add appends a queue entry under the mutex. Its ID is never reused.
-func (m *DaemonMessages) add(source, target, kind, text string) {
- m.state.Next++
- m.state.Pending = append(m.state.Pending, DaemonMessage{
- ID: m.state.Next,
- Source: source,
- Target: target,
- Kind: kind,
- Text: text,
- })
-}
-
-// failed stops all loops after a queue failure. Further sends must not change
-// the queue, because the outcome of the failed write is not known.
-func (m *DaemonMessages) failed(err error) error {
- m.failure = err
- for _, loop := range m.loops {
- loop.fail(err)
- }
-
- return err
-}
-
-// Snapshot holds the queue lock while snapshot locks and copies agent files.
-// Its callback must take the memory locks after this lock, as delivery does.
-func (m *DaemonMessages) Snapshot(snapshot func() error) error {
- m.mutex.Lock()
- defer m.mutex.Unlock()
-
- err := snapshot()
- if err != nil {
- return fmt.Errorf("copy agent message snapshot: %w", err)
- }
-
- return nil
-}
-