diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-12-06 01:51:57 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-12-06 02:12:47 +0900 |
| commit | 8a2f9edcf963358aeeddf1ee544300e2ec72a533 (patch) | |
| tree | 72ea28e868371b823d02f064fc02423f94921bb5 /internal/pipewire/core.go | |
| parent | 0d3f332d45bc80be9d4e7ff7a3a3df9b66d40c0b (diff) | |
internal/pipewire: use sendmsg/recvmsg directly
The PipeWire protocol does not work with Go abstractions. This change makes relevant methods call sendmsg/recvmsg directly.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pipewire/core.go')
| -rw-r--r-- | internal/pipewire/core.go | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/internal/pipewire/core.go b/internal/pipewire/core.go index 435aa89c..c2913b29 100644 --- a/internal/pipewire/core.go +++ b/internal/pipewire/core.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "strconv" + "time" ) /* pipewire/core.h */ @@ -348,17 +349,28 @@ func (ctx *Context) coreSync(id Int) error { // receiving a [CoreDone] event targeting the [CoreSync] event it delivered. var ErrNotDone = errors.New("did not receive a Core::Done event targeting previously delivered Core::Sync") +const ( + // syncTimeout is the maximum duration [Core.Sync] is allowed to take before + // receiving [CoreDone] or failing. + syncTimeout = 5 * time.Second +) + // Sync queues a [CoreSync] message for the PipeWire server and initiates a Roundtrip. func (core *Core) Sync() error { core.done = false if err := core.ctx.coreSync(roundtripSyncID); err != nil { return err } - if err := core.ctx.Roundtrip(); err != nil { - return err - } - if !core.done { - return ErrNotDone + + deadline := time.Now().Add(syncTimeout) + for !core.done { + if time.Now().After(deadline) { + return ErrNotDone + } + + if err := core.ctx.Roundtrip(); err != nil { + return err + } } return nil } |
