github.com/timstclair/heapster@v0.20.0-alpha1/Godeps/_workspace/src/google.golang.org/appengine/socket/socket_vm.go (about)

     1  // Copyright 2015 Google Inc. All rights reserved.
     2  // Use of this source code is governed by the Apache 2.0
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build !appengine
     6  
     7  package socket
     8  
     9  import (
    10  	"net"
    11  	"time"
    12  
    13  	"golang.org/x/net/context"
    14  )
    15  
    16  // Dial connects to the address addr on the network protocol.
    17  // The address format is host:port, where host may be a hostname or an IP address.
    18  // Known protocols are "tcp" and "udp".
    19  // The returned connection satisfies net.Conn, and is valid while ctx is valid;
    20  // if the connection is to be used after ctx becomes invalid, invoke SetContext
    21  // with the new context.
    22  func Dial(ctx context.Context, protocol, addr string) (*Conn, error) {
    23  	conn, err := net.Dial(protocol, addr)
    24  	if err != nil {
    25  		return nil, err
    26  	}
    27  	return &Conn{conn}, nil
    28  }
    29  
    30  // DialTimeout is like Dial but takes a timeout.
    31  // The timeout includes name resolution, if required.
    32  func DialTimeout(ctx context.Context, protocol, addr string, timeout time.Duration) (*Conn, error) {
    33  	conn, err := net.DialTimeout(protocol, addr, timeout)
    34  	if err != nil {
    35  		return nil, err
    36  	}
    37  	return &Conn{conn}, nil
    38  }
    39  
    40  // LookupIP returns the given host's IP addresses.
    41  func LookupIP(ctx context.Context, host string) (addrs []net.IP, err error) {
    42  	return net.LookupIP(host)
    43  }
    44  
    45  // Conn represents a socket connection.
    46  // It implements net.Conn.
    47  type Conn struct {
    48  	net.Conn
    49  }
    50  
    51  // SetContext sets the context that is used by this Conn.
    52  // It is usually used only when using a Conn that was created in a different context,
    53  // such as when a connection is created during a warmup request but used while
    54  // servicing a user request.
    55  func (cn *Conn) SetContext(ctx context.Context) {
    56  	// This function is not required on managed VMs.
    57  }
    58  
    59  // KeepAlive signals that the connection is still in use.
    60  // It may be called to prevent the socket being closed due to inactivity.
    61  func (cn *Conn) KeepAlive() error {
    62  	// This function is not required on managed VMs.
    63  	return nil
    64  }