Skip to content

feat: Add support for executing processes with Windows ConPty #311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"tfexec",
"tfstate",
"unconvert",
"webrtc",
"xerrors",
"yamux"
]
Expand Down
21 changes: 19 additions & 2 deletions peer/channel.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package peer

import (
"bufio"
"context"
"fmt"
"io"
Expand Down Expand Up @@ -80,7 +81,8 @@ type Channel struct {
dc *webrtc.DataChannel
// This field can be nil. It becomes set after the DataChannel
// has been opened and is detached.
rwc datachannel.ReadWriteCloser
rwc datachannel.ReadWriteCloser
reader io.Reader

closed chan struct{}
closeMutex sync.Mutex
Expand Down Expand Up @@ -132,6 +134,21 @@ func (c *Channel) init() {
_ = c.closeWithError(xerrors.Errorf("detach: %w", err))
return
}
// pion/webrtc will return an io.ErrShortBuffer when a read
// is triggerred with a buffer size less than the chunks written.
//
// This makes sense when considering UDP connections, because
// bufferring of data that has no transmit guarantees is likely
// to cause unexpected behavior.
//
// When ordered, this adds a bufio.Reader. This ensures additional
// data on TCP-like connections can be read in parts, while still
// being bufferred.
if c.opts.Unordered {
c.reader = c.rwc
} else {
c.reader = bufio.NewReader(c.rwc)
}
close(c.opened)
})

Expand Down Expand Up @@ -183,7 +200,7 @@ func (c *Channel) Read(bytes []byte) (int, error) {
}
}

bytesRead, err := c.rwc.Read(bytes)
bytesRead, err := c.reader.Read(bytes)
if err != nil {
if c.isClosed() {
return 0, c.closeError
Expand Down
10 changes: 7 additions & 3 deletions peer/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,18 @@ func TestConn(t *testing.T) {
go func() {
channel, err := client.Dial(context.Background(), "test", nil)
require.NoError(t, err)
_, err = channel.Write([]byte{'1', '2'})
_, err = channel.Write([]byte{1, 2})
require.NoError(t, err)
}()

channel, err := server.Accept(context.Background())
require.NoError(t, err)
_, err = channel.Read(make([]byte, 1))
data := make([]byte, 1)
_, err = channel.Read(data)
require.NoError(t, err)
require.Equal(t, uint8(0x1), data[0])
_, err = channel.Read(data)
require.NoError(t, err)
require.Equal(t, uint8(0x2), data[0])
})
}

Expand Down