|
|
|
|
@@ -63,7 +63,7 @@ type Context struct {
|
|
|
|
|
generation Long
|
|
|
|
|
// Pending file descriptors to be sent with the next message.
|
|
|
|
|
pendingFiles []int
|
|
|
|
|
// File count kept track of in [Header].
|
|
|
|
|
// File count already kept track of in [Header].
|
|
|
|
|
headerFiles int
|
|
|
|
|
// Files from the server. This is discarded on every Roundtrip so eventProxy
|
|
|
|
|
// implementations must make sure to close them to avoid leaking fds.
|
|
|
|
|
@@ -271,16 +271,20 @@ func (ctx *Context) recvmsg(remaining []byte) (payload []byte, err error) {
|
|
|
|
|
n, oobn, recvflags, err = ctx.conn.Recvmsg(ctx.iovecBuf[len(remaining):], ctx.oobBuf[:], recvmsgFlags)
|
|
|
|
|
|
|
|
|
|
if oob := ctx.oobBuf[:oobn]; len(oob) > 0 {
|
|
|
|
|
var oobErr error
|
|
|
|
|
|
|
|
|
|
var scm []syscall.SocketControlMessage
|
|
|
|
|
if scm, err = syscall.ParseSocketControlMessage(oob); err != nil {
|
|
|
|
|
if scm, oobErr = syscall.ParseSocketControlMessage(oob); oobErr != nil {
|
|
|
|
|
ctx.closeReceivedFiles()
|
|
|
|
|
err = oobErr
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var fds []int
|
|
|
|
|
for i := range scm {
|
|
|
|
|
if fds, err = syscall.ParseUnixRights(&scm[i]); err != nil {
|
|
|
|
|
if fds, oobErr = syscall.ParseUnixRights(&scm[i]); oobErr != nil {
|
|
|
|
|
ctx.closeReceivedFiles()
|
|
|
|
|
err = oobErr
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
ctx.receivedFiles = append(ctx.receivedFiles, fds...)
|
|
|
|
|
@@ -310,7 +314,7 @@ func (ctx *Context) recvmsg(remaining []byte) (payload []byte, err error) {
|
|
|
|
|
err = syscall.EPIPE // not wrapped as it did not come from the syscall
|
|
|
|
|
}
|
|
|
|
|
if n > 0 {
|
|
|
|
|
payload = ctx.iovecBuf[:n]
|
|
|
|
|
payload = ctx.iovecBuf[:len(remaining)+n]
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
@@ -581,6 +585,9 @@ func (ctx *Context) roundtrip() (err error) {
|
|
|
|
|
if err = ctx.sendmsg(ctx.buf, ctx.pendingFiles...); err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
ctx.buf = ctx.buf[:0]
|
|
|
|
|
ctx.pendingFiles = ctx.pendingFiles[:0]
|
|
|
|
|
ctx.headerFiles = 0
|
|
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
|
var danglingFiles DanglingFilesError
|
|
|
|
|
@@ -657,10 +664,6 @@ func (ctx *Context) consume(receiveRemaining []byte) (remaining []byte, err erro
|
|
|
|
|
return
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
ctx.buf = ctx.buf[:0]
|
|
|
|
|
ctx.pendingFiles = ctx.pendingFiles[:0]
|
|
|
|
|
ctx.headerFiles = 0
|
|
|
|
|
|
|
|
|
|
if remaining, err = ctx.recvmsg(receiveRemaining); err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
@@ -674,20 +677,14 @@ func (ctx *Context) consume(receiveRemaining []byte) (remaining []byte, err erro
|
|
|
|
|
if err = header.UnmarshalBinary(remaining[:SizeHeader]); err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// remote sequence sometimes do not start with 0
|
|
|
|
|
if ctx.remoteSequence == 0 {
|
|
|
|
|
ctx.remoteSequence = header.Sequence
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if header.Sequence != ctx.remoteSequence {
|
|
|
|
|
return remaining, UnexpectedSequenceError(header.Sequence)
|
|
|
|
|
}
|
|
|
|
|
ctx.remoteSequence++
|
|
|
|
|
|
|
|
|
|
if len(remaining) < int(SizeHeader+header.Size) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
ctx.remoteSequence++
|
|
|
|
|
|
|
|
|
|
proxy, ok := ctx.proxy[header.ID]
|
|
|
|
|
if !ok {
|
|
|
|
|
@@ -823,8 +820,7 @@ func connectName(name string, manager bool) (conn *net.UnixConn, err error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ConnectName connects to a PipeWire remote by name.
|
|
|
|
|
func ConnectName(name string, manager bool) (ctx *Context, err error) {
|
|
|
|
|
var props SPADict
|
|
|
|
|
func ConnectName(name string, manager bool, props SPADict) (ctx *Context, err error) {
|
|
|
|
|
if manager {
|
|
|
|
|
props = append(props, SPADictItem{Key: PW_KEY_REMOTE_INTENTION, Value: "manager"})
|
|
|
|
|
}
|
|
|
|
|
@@ -850,4 +846,6 @@ func ConnectName(name string, manager bool) (ctx *Context, err error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Connect connects to the PipeWire remote.
|
|
|
|
|
func Connect(manager bool) (ctx *Context, err error) { return ConnectName("", manager) }
|
|
|
|
|
func Connect(manager bool, props SPADict) (ctx *Context, err error) {
|
|
|
|
|
return ConnectName("", manager, props)
|
|
|
|
|
}
|
|
|
|
|
|