當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Client.Close方法代碼示例

本文整理匯總了Golang中net/rpc.Client.Close方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Close方法的具體用法?Golang Client.Close怎麽用?Golang Client.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net/rpc.Client的用法示例。


在下文中一共展示了Client.Close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: benchmarkEchoProtoRPC

func benchmarkEchoProtoRPC(b *testing.B, size int) {
	var client *rpc.Client
	benchmarkEcho(b, size, listenAndServeProtoRPC,
		func(addr net.Addr) {
			conn, err := tls.Dial(addr.Network(), addr.String(), clientTLSConfig)
			if err != nil {
				b.Fatal(err)
			}
			client = rpc.NewClientWithCodec(NewClientCodec(conn))
		},
		func() {
			if err := client.Close(); err != nil {
				b.Fatal(err)
			}
		},
		func(echoMsg string) string {
			args := EchoRequest{Msg: echoMsg}
			reply := EchoResponse{}
			if err := client.Call("Echo.Echo", &args, &reply); err != nil {
				b.Fatal(err)
			}
			return reply.Msg
		},
	)
}
開發者ID:iamqizhao,項目名稱:rpc-bench,代碼行數:25,代碼來源:rpc_test.go

示例2: iNewLibstore

/**@brief helper function for sorting
 * @param server master storage server addr
 * @param myhostport trib server's port
 * @param flags
 * @return *Libstore
 * @return error
 */
func iNewLibstore(server, myhostport string, flags int) (*Libstore, error) {
	var store Libstore
	var master *rpc.Client
	var args storageproto.GetServersArgs
	var reply storageproto.RegisterReply
	var err error

	store.Addr = myhostport
	store.Flags = flags

	if store.Addr != "" {
		rpc.Register(cacherpc.NewCacheRPC(&store))
	}

	lsplog.Vlogf(3, "libstore try to connect to master storage %s", server)

	master, err = rpc.DialHTTP("tcp", server)
	if lsplog.CheckReport(1, err) {
		return nil, err
	}

	lsplog.Vlogf(3, "try to call GetServers")

	master.Call("StorageRPC.GetServers", &args, &reply)

	if !reply.Ready {
		for i := 0; i < 5; i++ {
			time.Sleep(1000 * time.Millisecond)
			master.Call("StorageRPC.GetServers", &args, &reply)
		}
	}

	err = master.Close()
	if lsplog.CheckReport(1, err) {
		lsplog.Vlogf(3, "WARNING close master failed")
	}

	// couldn't get list of servers from master
	if (reply.Ready == false) || (reply.Servers == nil) {
		return nil, lsplog.MakeErr("Storage system not ready.")
	}

	store.Nodes = reply.Servers
	store.RPCConn = make([]*rpc.Client, len(store.Nodes))

	sort.Sort(store.Nodes)
	/*
	  for i := 0; i < len(store.Nodes); i++ {
	    fmt.Printf("%v\n", store.Nodes[i])
	  }*/

	store.Leases = cache.NewCache()
	if lsplog.CheckReport(1, err) {
		return nil, err
	}

	lsplog.Vlogf(3, "libstore create complete")

	return &store, nil
}
開發者ID:yuguess,項目名稱:440_P2,代碼行數:67,代碼來源:libstore-impl.go

示例3: Client

func Client() {
	var err error
	var c net.Conn
	c, err = net.DialTimeout("tcp", "127.0.0.1:9999", 1000*1000*1000*30)
	if err != nil {
		log.Fatal("dialing:", err)
	}

	var client *rpc.Client
	client = jsonrpc.NewClient(c)

	// 同步
	var a *PlusA = &PlusA{7, 8}
	var r *PlusR = new(PlusR)

	ch := make(chan int)
	for i := 0; i < 10000; i++ {
		go func() {
			client.Call("Test.Plus", a, r)
			<-ch
		}()
	}

	for j := 0; j < 10000; j++ {
		ch <- 1
		fmt.Println(r)
	}

	client.Close()
	c.Close()
}
開發者ID:fengzai,項目名稱:snippet,代碼行數:31,代碼來源:rpc-clients-concurrent.go

示例4: SendPeerMessage

func (srv *ServerNode) SendPeerMessage(peerName string, api string, args interface{}, reply interface{}) error {
	srv.lock.RLock()
	// Find the peer
	var peer *ServerPeer
	peer = srv.peers[peerName]
	srv.lock.RUnlock()

	if peer == nil {
		return ERR_PEER_NOT_FOUND
	}
	// Attempt to get a connection from the pool
	//srv_log("Looking for connection in pool for peer %v\n", peerName)
	var client *rpc.Client
	var ok bool
	client, ok = <-peer.connections
	if !ok {
		srv_log("Peer %v connection in shutdown - unable to send to peer\n", peerName)
		return ERR_PEER_NOT_FOUND
	}

	//srv_log("Found connection - sending api call %v\n", api)
	err := client.Call(api, args, reply)
	if err != nil {
		srv_log("Error in outbound call to %v - closing client and asking for a new connection: %v\n", peerName, err)
		client.Close()
		peer.broken_connections <- struct{}{}
	} else {
		//srv_log("Call worked - returning connection to the pool\n")
		// It worked - restore the connection to the pool
		peer.connections <- client
	}
	return err
}
開發者ID:owlfish,項目名稱:forestbus-server,代碼行數:33,代碼來源:ServerNode.go

示例5: Client

func Client() {
	var err error
	var c net.Conn
	c, err = net.DialTimeout("tcp", "127.0.0.1:1234", 1000*1000*1000*30)
	if err != nil {
		log.Fatal("dialing:", err)
	}

	var client *rpc.Client
	client = jsonrpc.NewClient(c)

	// 同步
	var args *Args = &Args{7, 8}
	var reply *Data = new(Data)
	client.Call("Arith.Plus", args, reply)
	fmt.Println(reply)

	// 異步
	args.A = 1
	args.B = 2
	var call *rpc.Call
	call = client.Go("Arith.Plus", args, reply, nil)
	var doneCall *rpc.Call
	doneCall = <-call.Done
	fmt.Println(doneCall.Args, doneCall.Reply)
	fmt.Println(args, reply)

	client.Close()
	c.Close()
}
開發者ID:fengzai,項目名稱:snippet,代碼行數:30,代碼來源:rpc-client.go

示例6: putConn

// putConn adds a connection to the free pool
func (r *RPCExt) putConn(c *rpc.Client) {
	r.mu.Lock()
	if n := len(r.clients); !r.closed && n < r.maxIdleConnections {
		r.clients = append(r.clients, c)
		r.mu.Unlock()
		return
	}
	r.mu.Unlock()
	c.Close()
}
開發者ID:guanglinlv,項目名稱:go-rpcext,代碼行數:11,代碼來源:rpcext.go

示例7: main

func main() {
	flag.Parse()
	args := flag.Args()
	clientName := args[0]
	if !strings.Contains(clientName, ":") {
		clientName = clientName + ":6969"
	}
	var client *rpc.Client
	var err error
	sleepDuration, _ := time.ParseDuration(fmt.Sprintf("%ds", *interval))
	for iter := 0; *numPolls < 0 || iter < *numPolls; iter++ {
		if iter > 0 {
			time.Sleep(sleepDuration)
		}
		if client == nil {
			client, err = rpc.DialHTTP("tcp", clientName)
			if err != nil {
				fmt.Printf("Error dialing\t%s\n", err)
				os.Exit(1)
			}
		}
		arg := new(uint64)
		var reply *httpd.FileSystemHistory
		err = client.Call("Subd.Poll", arg, &reply)
		if err != nil {
			fmt.Printf("Error calling\t%s\n", err)
			os.Exit(1)
		}
		if *newConnection {
			client.Close()
			client = nil
		}
		fs := reply.FileSystem
		if fs == nil {
			fmt.Println("No FileSystem pointer")
		} else {
			fs.RebuildPointers()
			if *debug {
				fs.DebugWrite(os.Stdout, "")
			} else {
				fmt.Print(fs)
			}
			if *file != "" {
				f, err := os.Create(*file)
				if err != nil {
					fmt.Printf("Error creating: %s\t%s\n", *file, err)
					os.Exit(1)
				}
				encoder := gob.NewEncoder(f)
				encoder.Encode(fs)
				f.Close()
			}
		}
	}
}
開發者ID:zaletniy,項目名稱:Dominator,代碼行數:55,代碼來源:main.go

示例8: closeBrokenConnection

/*
closeBrokenConnection is an internal method to remove broken connections from our cache.
*/
func (client *Client) closeBrokenConnection(rpcclient *rpc.Client) {
	client.nodeClientLock.Lock()
	defer client.nodeClientLock.Unlock()
	rpcclient.Close()
	for key, value := range client.nodeClientMap {
		if value == rpcclient {
			delete(client.nodeClientMap, key)
			return
		}
	}
}
開發者ID:owlfish,項目名稱:forestbus,代碼行數:14,代碼來源:Client.go

示例9: ApiQuery

func ApiQuery(w http.ResponseWriter, r *http.Request) {

	defer func() {
		//r.Body.Close()
	}()

	//_, err := ioutil.ReadAll(r.Body)
	//if err != nil {
	//    return
	//}

	var err error

	status := make(chan int, 2)

	go func() {

		var sock *rpc.Client
		if sock, err = rpc.DialHTTP("tcp", "localhost:9601"); err != nil {
			return
		}
		defer sock.Close()

		//r  := new(CommandReply)
		var rsp CommandReply
		rs := sock.Go("Command.Query", "nil", &rsp, nil)

		select {
		case <-rs.Done:
			status <- 1
		case <-time.After(3e9):
			status <- 9
		}

		//runtime.Goexit()
		return
	}()

	for {
		select {
		case <-status:
			goto L
		case <-time.After(3e9):
			goto L
		}
	}

L:
	//io.WriteString(w, "{\"status\": \"OK\"}")
	close(status)

	return
}
開發者ID:eryx,項目名稱:tips.go,代碼行數:53,代碼來源:http-httprpc-server.go

示例10: pollSubcommand

func pollSubcommand(client *rpc.Client, args []string) {
	var err error
	clientName := fmt.Sprintf("%s:%d", *subHostname, *subPortNum)
	for iter := 0; *numPolls < 0 || iter < *numPolls; iter++ {
		if iter > 0 {
			time.Sleep(time.Duration(*interval) * time.Second)
		}
		if client == nil {
			client, err = rpc.DialHTTP("tcp", clientName)
			if err != nil {
				fmt.Printf("Error dialing\t%s\n", err)
				os.Exit(1)
			}
		}
		var request sub.PollRequest
		var reply sub.PollResponse
		pollStartTime := time.Now()
		err = client.Call("Subd.Poll", request, &reply)
		fmt.Printf("Poll duration: %s\n", time.Since(pollStartTime))
		if err != nil {
			fmt.Printf("Error calling\t%s\n", err)
			os.Exit(1)
		}
		if *newConnection {
			client.Close()
			client = nil
		}
		fs := reply.FileSystem
		if fs == nil {
			fmt.Println("No FileSystem pointer")
		} else {
			fs.RebuildInodePointers()
			if *debug {
				fs.DebugWrite(os.Stdout, "")
			} else {
				fmt.Print(fs)
			}
			if *file != "" {
				f, err := os.Create(*file)
				if err != nil {
					fmt.Printf("Error creating: %s\t%s\n", *file, err)
					os.Exit(1)
				}
				encoder := gob.NewEncoder(f)
				encoder.Encode(fs)
				f.Close()
			}
		}
	}
	time.Sleep(time.Duration(*wait) * time.Second)
}
開發者ID:wxdublin,項目名稱:Dominator,代碼行數:51,代碼來源:poll.go

示例11: SetDayCounter

func SetDayCounter(uid uint32, chip int32) (ret int32, err error) {
	var cli *rpc.Client
	if cli, err = jsonrpc.Dial("tcp", PY_RPC_ADDR); err != nil {
		return
	}
	defer cli.Close()

	args := &argSetDayCounter{uid, chip}
	reply := new(setDayCounterRep)
	if cli.Call("setDayCounter", args, reply); err != nil {
		return
	}
	ret = reply.Chip
	return
}
開發者ID:lsaint,項目名稱:casino,代碼行數:15,代碼來源:dao.go

示例12: GetBillboard

func GetBillboard(uid uint32) (ret [][]string, err error) {
	var cli *rpc.Client
	if cli, err = jsonrpc.Dial("tcp", PY_RPC_ADDR); err != nil {
		return
	}
	defer cli.Close()

	args := &argGetBillboard{uid}
	reply := new(getBillboardRep)
	if cli.Call("getBillboard", args, reply); err != nil {
		return
	}
	ret = reply.Billboard
	return
}
開發者ID:lsaint,項目名稱:casino,代碼行數:15,代碼來源:dao.go

示例13: GetBalance

func GetBalance(uids []uint32) (ubl map[uint32]uint32, err error) {
	var cli *rpc.Client
	if cli, err = jsonrpc.Dial("tcp", PY_RPC_ADDR); err != nil {
		return
	}
	defer cli.Close()

	args := &argGetBalance{uids}
	reply := new(getBalanceRep)
	if err = cli.Call("getBalance", args, reply); err != nil {
		return
	}
	ubl = reply.keyToUint32()
	return
}
開發者ID:lsaint,項目名稱:casino,代碼行數:15,代碼來源:dao.go

示例14: SetName

func SetName(uid uint32, name string) (Rname string, err error) {
	var cli *rpc.Client
	if cli, err = jsonrpc.Dial("tcp", PY_RPC_ADDR); err != nil {
		return
	}
	defer cli.Close()

	args := &argSetName{uid, name}
	reply := new(setNameRep)
	if cli.Call("setName", args, reply); err != nil {
		return
	}
	Rname = reply.Name
	return
}
開發者ID:lsaint,項目名稱:casino,代碼行數:15,代碼來源:dao.go

示例15: GetLogTime

func GetLogTime(uid uint32) (intime, outtime string, err error) {
	var cli *rpc.Client
	if cli, err = jsonrpc.Dial("tcp", PY_RPC_ADDR); err != nil {
		return
	}
	defer cli.Close()

	args := &argUid{uid}
	reply := new(getLogTimeRep)
	if err = cli.Call("getLogTime", args, reply); err != nil {
		return
	}
	intime, outtime = reply.Logintime, reply.Logouttime
	return
}
開發者ID:lsaint,項目名稱:casino,代碼行數:15,代碼來源:dao.go


注:本文中的net/rpc.Client.Close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。