File: bridge.go

package info (click to toggle)
golang-github-varlink-go 0.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, experimental, forky, sid, trixie
  • size: 272 kB
  • sloc: makefile: 13
file content (64 lines) | stat: -rw-r--r-- 1,048 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package varlink

import (
	"io"
	"net"
	"os"
	"os/exec"
	"time"
)

var _ net.Conn = &PipeCon{}

type PipeCon struct {
	cmd    *exec.Cmd
	reader io.ReadCloser
	writer io.WriteCloser
}

func (p PipeCon) Read(b []byte) (n int, err error) {
	return p.reader.Read(b)
}

func (p PipeCon) Write(b []byte) (n int, err error) {
	return p.writer.Write(b)
}

func (p PipeCon) LocalAddr() net.Addr {
	panic("implement me")
}

func (p PipeCon) RemoteAddr() net.Addr {
	panic("implement me")
}

func (p PipeCon) SetDeadline(t time.Time) error {
	panic("implement me")
}

func (p PipeCon) SetReadDeadline(t time.Time) error {
	return nil
}

func (p PipeCon) SetWriteDeadline(t time.Time) error {
	return nil
}

func (p PipeCon) Close() error {
	err1 := (p.reader).Close()
	err2 := (p.writer).Close()
	if err1 != nil {
		return err1
	}
	if err2 != nil {
		return err2
	}
	p.cmd.Wait()

	return nil
}

// NewBridge returns a new connection with the given bridge.
func NewBridge(bridge string) (*Connection, error) {
	return NewBridgeWithStderr(bridge, os.Stderr)
}