Skip to content

Commit

Permalink
Fixed bridge with ctx on windows
Browse files Browse the repository at this point in the history
Fixes: #22
  • Loading branch information
haraldh committed Sep 2, 2020
1 parent 2612286 commit 3863da8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 91 deletions.
28 changes: 0 additions & 28 deletions varlink/bridge.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build !windows

package varlink

import (
Expand All @@ -8,8 +6,6 @@ import (
"os"
"os/exec"
"time"

"github.com/varlink/go/varlink/internal/ctxio"
)

var _ net.Conn = &PipeCon{}
Expand Down Expand Up @@ -62,30 +58,6 @@ func (p PipeCon) Close() error {
return nil
}

// NewBridgeWithStderr returns a new connection with the given bridge.
func NewBridgeWithStderr(bridge string, stderr io.Writer) (*Connection, error) {
c := Connection{}
cmd := exec.Command("sh", "-c", bridge)
cmd.Stderr = stderr
r, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
w, err := cmd.StdinPipe()
if err != nil {
return nil, err
}
c.conn = ctxio.NewConn(PipeCon{cmd, r, w})
c.address = ""

err = cmd.Start()
if err != nil {
return nil, err
}

return &c, nil
}

// NewBridge returns a new connection with the given bridge.
func NewBridge(bridge string) (*Connection, error) {
return NewBridgeWithStderr(bridge, os.Stderr)
Expand Down
63 changes: 0 additions & 63 deletions varlink/bridge_windows.go

This file was deleted.

33 changes: 33 additions & 0 deletions varlink/newbridge.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// +build !windows

package varlink

import (
"github.com/varlink/go/varlink/internal/ctxio"
"io"
"os/exec"
)

// NewBridgeWithStderr returns a new connection with the given bridge.
func NewBridgeWithStderr(bridge string, stderr io.Writer) (*Connection, error) {
c := Connection{}
cmd := exec.Command("sh", "-c", bridge)
cmd.Stderr = stderr
r, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
w, err := cmd.StdinPipe()
if err != nil {
return nil, err
}
c.conn = ctxio.NewConn(PipeCon{cmd, r, w})
c.address = ""

err = cmd.Start()
if err != nil {
return nil, err
}

return &c, nil
}
31 changes: 31 additions & 0 deletions varlink/newbridge_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package varlink

import (
"github.com/varlink/go/varlink/internal/ctxio"
"io"
"os/exec"
)

// NewBridgeWithStderr returns a new connection with the given bridge.
func NewBridgeWithStderr(bridge string, stderr io.Writer) (*Connection, error) {
c := Connection{}
cmd := exec.Command("cmd", "/C", bridge)
cmd.Stderr = stderr
r, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
w, err := cmd.StdinPipe()
if err != nil {
return nil, err
}
c.conn = ctxio.NewConn(PipeCon{cmd, r, w})
c.address = ""

err = cmd.Start()
if err != nil {
return nil, err
}

return &c, nil
}

0 comments on commit 3863da8

Please sign in to comment.