Skip to content

Commit

Permalink
vsock: implemented DialContext
Browse files Browse the repository at this point in the history
  • Loading branch information
balena committed Feb 2, 2023
1 parent 051f33a commit aecf384
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions conn_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
type conn = socket.Conn

// dial is the entry point for Dial on Linux.
func dial(cid, port uint32, _ *Config) (*Conn, error) {
func dial(ctx context.Context, cid, port uint32, _ *Config) (*Conn, error) {
// TODO(mdlayher): Config default nil check and initialize. Pass options to
// socket.Config where necessary.

Expand All @@ -26,7 +26,7 @@ func dial(cid, port uint32, _ *Config) (*Conn, error) {
}

sa := &unix.SockaddrVM{CID: cid, Port: port}
rsa, err := c.Connect(context.Background(), sa)
rsa, err := c.Connect(ctx, sa)
if err != nil {
_ = c.Close()
return nil, err
Expand Down
17 changes: 16 additions & 1 deletion vsock.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vsock

import (
"context"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -176,7 +177,21 @@ func (l *Listener) opError(op string, err error) error {
// When the connection is no longer needed, Close must be called to free
// resources.
func Dial(contextID, port uint32, cfg *Config) (*Conn, error) {
c, err := dial(contextID, port, cfg)
return DialContext(context.Background(), contextID, port, cfg)
}

// DialContext connects to the address on the named network using
// the provided context.
//
// The provided Context must be non-nil. If the context expires before
// the connection is complete, an error is returned. Once successfully
// connected, any expiration of the context will not affect the
// connection.
//
// See func Dial for a description of the contextID and port
// parameters.
func DialContext(ctx context.Context, contextID, port uint32, cfg *Config) (*Conn, error) {
c, err := dial(ctx, contextID, port, cfg)

Check failure on line 194 in vsock.go

View workflow job for this annotation

GitHub Actions / build (1.18)

too many arguments in call to dial

Check failure on line 194 in vsock.go

View workflow job for this annotation

GitHub Actions / build (1.18)

too many arguments in call to dial

Check failure on line 194 in vsock.go

View workflow job for this annotation

GitHub Actions / build (1.19)

too many arguments in call to dial

Check failure on line 194 in vsock.go

View workflow job for this annotation

GitHub Actions / build (1.18)

too many arguments in call to dial

Check failure on line 194 in vsock.go

View workflow job for this annotation

GitHub Actions / build (1.20)

too many arguments in call to dial

Check failure on line 194 in vsock.go

View workflow job for this annotation

GitHub Actions / build (1.19)

too many arguments in call to dial

Check failure on line 194 in vsock.go

View workflow job for this annotation

GitHub Actions / build (1.20)

too many arguments in call to dial
if err != nil {
// No local address, but we have a remote address we can return.
return nil, opError(opDial, err, nil, &Addr{
Expand Down

0 comments on commit aecf384

Please sign in to comment.