github.com/arieschain/arieschain@v0.0.0-20191023063405-37c074544356/rpc/ipc.go (about) 1 package rpc 2 3 import ( 4 "context" 5 "net" 6 7 "github.com/quickchainproject/quickchain/log" 8 "github.com/quickchainproject/quickchain/p2p/netutil" 9 ) 10 11 // ServeListener accepts connections on l, serving JSON-RPC on them. 12 func (srv *Server) ServeListener(l net.Listener) error { 13 for { 14 conn, err := l.Accept() 15 if netutil.IsTemporaryError(err) { 16 log.Warn("RPC accept error", "err", err) 17 continue 18 } else if err != nil { 19 return err 20 } 21 log.Trace("Accepted connection", "addr", conn.RemoteAddr()) 22 go srv.ServeCodec(NewJSONCodec(conn), OptionMethodInvocation|OptionSubscriptions) 23 } 24 } 25 26 // DialIPC create a new IPC client that connects to the given endpoint. On Unix it assumes 27 // the endpoint is the full path to a unix socket, and Windows the endpoint is an 28 // identifier for a named pipe. 29 // 30 // The context is used for the initial connection establishment. It does not 31 // affect subsequent interactions with the client. 32 func DialIPC(ctx context.Context, endpoint string) (*Client, error) { 33 return newClient(ctx, func(ctx context.Context) (net.Conn, error) { 34 return newIPCConnection(ctx, endpoint) 35 }) 36 }