github.com/arieschain/arieschain@v0.0.0-20191023063405-37c074544356/rpc/ipc_windows.go (about)

     1  // +build windows
     2  
     3  package rpc
     4  
     5  import (
     6  	"context"
     7  	"net"
     8  	"time"
     9  
    10  	"gopkg.in/natefinch/npipe.v2"
    11  )
    12  
    13  // This is used if the dialing context has no deadline. It is much smaller than the
    14  // defaultDialTimeout because named pipes are local and there is no need to wait so long.
    15  const defaultPipeDialTimeout = 2 * time.Second
    16  
    17  // ipcListen will create a named pipe on the given endpoint.
    18  func ipcListen(endpoint string) (net.Listener, error) {
    19  	return npipe.Listen(endpoint)
    20  }
    21  
    22  // newIPCConnection will connect to a named pipe with the given endpoint as name.
    23  func newIPCConnection(ctx context.Context, endpoint string) (net.Conn, error) {
    24  	timeout := defaultPipeDialTimeout
    25  	if deadline, ok := ctx.Deadline(); ok {
    26  		timeout = deadline.Sub(time.Now())
    27  		if timeout < 0 {
    28  			timeout = 0
    29  		}
    30  	}
    31  	return npipe.DialTimeout(endpoint, timeout)
    32  }