github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/rpc/inproc.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 12:09:45</date>
    10  //</624342664405323776>
    11  
    12  
    13  package rpc
    14  
    15  import (
    16  	"context"
    17  	"net"
    18  )
    19  
    20  //dialinproc将进程内连接附加到给定的RPC服务器。
    21  func DialInProc(handler *Server) *Client {
    22  	initctx := context.Background()
    23  	c, _ := newClient(initctx, func(context.Context) (net.Conn, error) {
    24  		p1, p2 := net.Pipe()
    25  		go handler.ServeCodec(NewJSONCodec(p1), OptionMethodInvocation|OptionSubscriptions)
    26  		return p2, nil
    27  	})
    28  	return c
    29  }
    30