github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/rpc/ipc_windows.go (about) 1 // This file is part of the go-sberex library. The go-sberex library is 2 // free software: you can redistribute it and/or modify it under the terms 3 // of the GNU Lesser General Public License as published by the Free 4 // Software Foundation, either version 3 of the License, or (at your option) 5 // any later version. 6 // 7 // The go-sberex library is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 // General Public License <http://www.gnu.org/licenses/> for more details. 11 12 // +build windows 13 14 package rpc 15 16 import ( 17 "context" 18 "net" 19 "time" 20 21 "gopkg.in/natefinch/npipe.v2" 22 ) 23 24 // This is used if the dialing context has no deadline. It is much smaller than the 25 // defaultDialTimeout because named pipes are local and there is no need to wait so long. 26 const defaultPipeDialTimeout = 2 * time.Second 27 28 // ipcListen will create a named pipe on the given endpoint. 29 func ipcListen(endpoint string) (net.Listener, error) { 30 return npipe.Listen(endpoint) 31 } 32 33 // newIPCConnection will connect to a named pipe with the given endpoint as name. 34 func newIPCConnection(ctx context.Context, endpoint string) (net.Conn, error) { 35 timeout := defaultPipeDialTimeout 36 if deadline, ok := ctx.Deadline(); ok { 37 timeout = deadline.Sub(time.Now()) 38 if timeout < 0 { 39 timeout = 0 40 } 41 } 42 return npipe.DialTimeout(endpoint, timeout) 43 }