Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
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)
if err != nil {
// No local address, but we have a remote address we can return.
return nil, opError(opDial, err, nil, &Addr{
Expand Down