Ejemplo n.º 1
0
// connect to remote servant peer
func (this *funServantPeerPool) connect(peerAddr string) (*rpc.FunServantClient,
	error) {
	transportFactory := thrift.NewTBufferedTransportFactory(this.cf.BufferSize)
	transport, err := thrift.NewTSocketTimeout(peerAddr, this.cf.IoTimeout)
	if err != nil {
		return nil, err
	}

	if err = transport.Open(); err != nil {
		log.Error("connect peer[%s]: %s", peerAddr, err)

		return nil, err
	}

	if tcpConn, ok := transport.Conn().(*net.TCPConn); ok {
		// nagle's only applies to client rather than server
		tcpConn.SetNoDelay(this.cf.TcpNoDelay)
	}

	client := rpc.NewFunServantClientFactory(
		transportFactory.GetTransport(transport),
		thrift.NewTBinaryProtocolFactoryDefault())

	return client, nil
}
Ejemplo n.º 2
0
func Servant(serverAddr string) *rpc.FunServantClient {
	transportFactory := thrift.NewTTransportFactory()
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	transport, err := thrift.NewTSocket(serverAddr)
	if err != nil {
		panic(err)
	}

	useTransport := transportFactory.GetTransport(transport)
	client := rpc.NewFunServantClientFactory(useTransport, protocolFactory)
	if err := transport.Open(); err != nil {
		panic(err)
	}

	return client
}