当前位置: 首页>>代码示例>>Golang>>正文


Golang rpc.Dial函数代码示例

本文整理汇总了Golang中rpc.Dial函数的典型用法代码示例。如果您正苦于以下问题:Golang Dial函数的具体用法?Golang Dial怎么用?Golang Dial使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Dial函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: clientFunc

func clientFunc() int {
	socketfname := getSocketFilename()

	// client
	client, err := rpc.Dial("unix", socketfname)
	if err != nil {
		err = tryRunServer()
		if err != nil {
			fmt.Printf("%s\n", err.String())
			return 1
		}
		waitForAFile(socketfname)
		client, err = rpc.Dial("unix", socketfname)
		if err != nil {
			fmt.Printf("%s\n", err.String())
			return 1
		}
	}
	defer client.Close()

	if flag.NArg() > 0 {
		switch flag.Arg(0) {
		case "autocomplete":
			Cmd_AutoComplete(client)
		case "close":
			Cmd_Close(client)
		case "status":
			Cmd_Status(client)
		case "drop-cache":
			Cmd_DropCache(client)
		}
	}
	return 0
}
开发者ID:kij,项目名称:gocode,代码行数:34,代码来源:gocode.go

示例2: SendHeartbeat

func SendHeartbeat(masterAddress string) {
	var args sfs.HeartbeatArgs
	var ret sfs.HeartbeatReturn

	master, err := rpc.Dial("tcp", masterAddress+":1338")
	if err != nil {
		log.Fatal("chunk: dialing:", err)
	}

	host, _ := os.Hostname()
	_, iparray, _ := net.LookupHost(host)
	tcpAddr, _ := net.ResolveTCPAddr(iparray[0] + ":1337")
	args.ChunkServerIP = *tcpAddr
	args.ChunkServerID = chunkServerID

	for {
		args.Capacity = capacity
		addedChunkSlice := make([]sfs.ChunkInfo, addedChunks.Len())
		for i := 0; i < addedChunks.Len(); i++ {
			addedChunkSlice[i] = addedChunks.At(i).(sfs.ChunkInfo)
		}
		args.AddedChunks = addedChunkSlice
		err = master.Call("Master.BeatHeart", &args, &ret)
		if err != nil {
			log.Fatal("chunk: heartbeat error: ", err)
		}
		addedChunks.Resize(0, 0)
		time.Sleep(sfs.HEARTBEAT_WAIT)
	}
	return
}
开发者ID:lalkaka,项目名称:stealthFS,代码行数:31,代码来源:chunk_mem.go

示例3: ReplicateChunk

func (t *Server) ReplicateChunk(args *sfs.ReplicateChunkArgs, ret *sfs.ReplicateChunkReturn) os.Error {

	if args.Servers == nil {
		log.Printf("chunk: replication call: nil address.")
		return nil
	}

	log.Printf("replication request for site %s and chunk %d\n",
		args.Servers[0].String(), args.ChunkID)

	for i := 0; i < len(args.Servers); i++ {
		replicationHost, err := rpc.Dial("tcp", args.Servers[i].String())
		if err != nil {
			log.Println("chunk: replication call:", err)
			continue
		}

		var readArgs sfs.ReadArgs
		var readRet sfs.ReadReturn
		readArgs.ChunkID = args.ChunkID

		err = replicationHost.Call("Server.Read", &readArgs, &readRet)
		if err != nil {
			log.Println("chunk: replication call:", err)
			continue
		}

		chunkTable[args.ChunkID] = readRet.Data
		break
	}
	return nil
}
开发者ID:lalkaka,项目名称:stealthFS,代码行数:32,代码来源:chunk_mem.go

示例4: Init

func Init(masterAddress string, loggingFlag bool) {

	var args sfs.ChunkBirthArgs
	var ret sfs.ChunkBirthReturn

	requestLoad = 0
	loadArray = make([]int, 3)
	for i := 0; i < 3; i++ {
		loadArray[i] = 0
	}
	loadArrayIndex = 0
	logging = loggingFlag

	capacity = CHUNK_TABLE_SIZE
	args.Capacity = capacity

	host, _ := os.Hostname()
	_, iparray, _ := net.LookupHost(host)
	tcpAddr, _ = net.ResolveTCPAddr(iparray[0] + ":1337")
	args.ChunkServerIP = *tcpAddr
	log.Println("Chunk: Server addr: ", args.ChunkServerIP)

	if logging {
		err := os.Mkdir("log", 0777)
		if err != nil {
			log.Println(err.String())
			logging = false
		}
		err = logger.Init("log/chunk-log-"+host+".txt", "../logger/")
		if err != nil {
			log.Println(err.String())
			logging = false
		}
	}
	logger.QuickInit()

	go sigHandler()

	master, err := rpc.Dial("tcp", masterAddress+":1338")
	if master != nil {
		defer master.Close()
	}
	if err != nil {
		log.Fatal("chunk dial error:", err)
	}

	err = master.Call("Master.BirthChunk", &args, &ret)
	if err != nil {
		log.Fatal("chunk call error: ", err)
	}
	chunkServerID = ret.ChunkServerID

	tmpS := new(Server)
	tmpRet := new(sfs.ReplicateChunkReturn)
	if ret.ChunksToGet != nil {
		for cnt := 0; cnt < len(ret.ChunksToGet); cnt++ {
			tmpS.ReplicateChunk(&(ret.ChunksToGet[cnt]), tmpRet)
		}
	}
}
开发者ID:alangenfeld,项目名称:cs639,代码行数:60,代码来源:chunk_mem.go

示例5: Delete

/* delete */
func Delete(filename string) int {

	_, present := openFiles[filename]
	if !present {
		//		log.Println("Client: filename does not exist ", filename);
		//		return FAIL
	} else {
		var dummy file
		openFiles[filename] = &dummy, false
	}

	client, err := rpc.Dial("tcp", master+":1338") //IP needs to be changed to Master's IP
	defer client.Close()

	if err != nil {
		log.Println("Client: Dial Error", err)
		return FAIL
	} else {
		fileArgs := new(sfs.DeleteArgs)
		fileInfo := new(sfs.DeleteReturn)
		fileArgs.Name = filename
		err := client.Call("Master.DeleteFile", &fileArgs, &fileInfo)
		if err != nil || !fileInfo.Status {
			log.Println("Client: Delete fail ", fileInfo.Status, err)
			return FAIL
		}
	}
	return WIN
}
开发者ID:alangenfeld,项目名称:cs639,代码行数:30,代码来源:client.go

示例6: dialServer

func dialServer(address string) (*rpc.Client, os.Error) {
	server, err := rpc.Dial("tcp", address)
	if err != nil {
		log.Println("Client: Dial Error to", address, err.String())
	}
	return server, err
}
开发者ID:alangenfeld,项目名称:cs639,代码行数:7,代码来源:client.go

示例7: Open

func Open(filename string, flag int) int {
	client, err := rpc.Dial("tcp", master+":1338") //IP needs to be changed to Master's IP
	if err != nil {
		log.Printf("Client: Error", err.String())
		os.Exit(1)
		return FAIL
	} else {
		fileInfo := new(sfs.OpenReturn)
		fileArgs := new(sfs.OpenArgs)
		fileArgs.Name = filename
		//	fileArgs.Size = 0;
		err := client.Call("Master.ReadOpen", &fileArgs, &fileInfo)
		if err != nil {
			log.Fatal("Client: Open fail ", err)
		}
		if fileInfo.New {
			log.Printf("Client: New file!\n")
		} else {
			log.Printf("Client: Old file!\n")
		}
		fd++
		var nextFile file
		nextFile.size = fileInfo.Size
		nextFile.filePtr = 0
		nextFile.name = filename
		nextFile.chunkInfo = new(vector.Vector)
		for i := 0; i < cap(fileInfo.Chunk); i++ {
			nextFile.chunkInfo.Push(fileInfo.Chunk[i])
		}

		openFiles[fd] = nextFile
		return fd
	}
	return FAIL
}
开发者ID:lalkaka,项目名称:stealthFS,代码行数:35,代码来源:client.go

示例8: AddChunks

func AddChunks(fileName string, numChunks uint64, hash []byte) (int, sfs.ChunkInfo, bool) {

	var args sfs.GetNewChunkArgs
	var returnVal sfs.GetNewChunkReturn

	args.Name = fileName
	args.Count = numChunks
	args.Hash = hash

	//	log.Printf("AddChunks: getting chunk for file %s with hash %x\n", fileName, args.Hash)

	masterConn, err := rpc.Dial("tcp", master+":1338")

	if err != nil {
		log.Println("Error Dialing Master(AddChunks):", err)
		return sfs.FAIL, returnVal.Info, returnVal.NewChunk
	}

	err = masterConn.Call("Master.GetNewChunk", &args, &returnVal)
	if err != nil {
		log.Println("Error Calling Master(AddChunks):", err)
		return sfs.FAIL, returnVal.Info, returnVal.NewChunk
	}
	masterConn.Close()
	return sfs.SUCCESS, returnVal.Info, returnVal.NewChunk

}
开发者ID:alangenfeld,项目名称:cs639,代码行数:27,代码来源:client.go

示例9: Write

func (t *Server) Write(args *sfs.WriteArgs, ret *sfs.WriteReturn) os.Error {
	requestLoad++
	ret.Status = sfs.FAIL
	var id logger.TaskId

	id = logger.Start("Write")
	log.Println("chunk: Writing to chunk ", args.Info.ChunkID)
	if capacity < 1 {
		log.Println("chunk: Server Full!")
		return nil
	}

	data, present := chunkTable[args.Info.ChunkID]
	if !present {
		addedChunks.Push(args.Info)
		capacity--
	}

	data.Data = args.Data.Data
	chunkTable[args.Info.ChunkID] = data

	tempServ := args.Info.Servers[0]
	var inRet sfs.WriteReturn

	for {
		if len(args.Info.Servers) < 2 {
			break
		}
		args.Info.Servers = args.Info.Servers[1:len(args.Info.Servers)]
		client, err := rpc.Dial("tcp", args.Info.Servers[0].String())
		if err != nil {
			log.Println("chunk: dialing error: ", err)
			continue
		}
		log.Println("chunk: forwarding write to ", args.Info.Servers[0])
		err = client.Call("Server.Write", &args, &inRet)
		client.Close()
		if err != nil {
			log.Println("chunk: server error: ", err)
			continue
		}
		break
	}

	ret.Info.Servers = make([]net.TCPAddr, len(inRet.Info.Servers)+1)

	for i := 0; i < len(ret.Info.Servers); i++ {
		if i < len(inRet.Info.Servers) {
			ret.Info.Servers[i] = inRet.Info.Servers[i]
		} else {
			ret.Info.Servers[i] = tempServ
		}
	}

	logger.End(id, false)

	ret.Status = sfs.SUCCESS
	return nil
}
开发者ID:alangenfeld,项目名称:cs639,代码行数:59,代码来源:chunk_mem.go

示例10: RemoveServer

func RemoveServer(serv *server) os.Error {

	//Remove the Server
	sHeap.Remove(serv)

	for i := 0; i < sHeap.vec.Len(); i++ {
		if sHeap.vec.At(i).(*server).id == serv.id {
			log.Printf("master: RemoveServer: remove didn't actually remove server %d! Busto Rhymes\n", serv.id)
			return nil
		}
	}

	servers[serv.id] = &server{}, false
	addrToServerMap[serv.addr.String()] = &server{}, false

	str1 := fmt.Sprintf("removing server %s:%d", serv.addr.IP.String(), serv.addr.Port)

	//////////////////////////////////////////////////////////////////////
	////////////      THIS IS A PROBLEM -- NEED TO SPREAD REPLICATION REQS
	//////////////////////////////////////////////////////////////////////
	otherserver := sHeap.vec.At(0).(*server)

	str := fmt.Sprintf("%s:%d", otherserver.addr.IP.String(), otherserver.addr.Port)

	log.Printf("master: RemoveServer: dialing %s\n", str)

	client, err := rpc.Dial("tcp", str)

	if err != nil {
		log.Printf("master: RemoveServer: unable to dial %s\n", str)
	} else {
		log.Printf("master: RemoveServer: dial %s succeeded\n", str)
	}

	//for each chunk in the server, make a replication call.
	for cnt := 0; cnt < serv.chunks.Len(); cnt++ {

		chunk := serv.chunks.At(cnt).(*chunk)

		//populate chunk location vector
		chunklist := make([]net.TCPAddr, chunk.servers.Len())
		for cnt1 := 0; cnt1 < chunk.servers.Len(); cnt1++ {
			chunklist[cnt1] = chunk.servers.At(cnt1).(*server).addr
		}

		//send rpc call off
		args := &sfs.ReplicateChunkArgs{chunk.chunkID, chunklist}
		reply := new(sfs.ReplicateChunkReturn)
		log.Printf("master: RemoveServer: issuing replication req to %s\n", str)
		err = client.Call("Server.ReplicateChunk", args, reply)
		if err != nil {
			log.Printf("master: RemoveServer: unable to call %s\n", str)
		}
		log.Printf("%s", reply)
	}

	log.Printf("RemoveServer: removing %s\n", str1)
	return nil
}
开发者ID:lalkaka,项目名称:stealthFS,代码行数:59,代码来源:master.go

示例11: tryToConnect

func tryToConnect(network, address string) (client *rpc.Client, err os.Error) {
	t := 0
	for {
		client, err = rpc.Dial(network, address)
		if err != nil && t < 1000 {
			time.Sleep(10e6) // wait 10 milliseconds
			t += 10
			continue
		}
		break
	}

	return
}
开发者ID:swcai,项目名称:gocode,代码行数:14,代码来源:gocode.go

示例12: ReplicateChunk

func (t *Server) ReplicateChunk(args *sfs.ReplicateChunkArgs, ret *sfs.ReplicateChunkReturn) os.Error {
	requestLoad++
	if args.Servers == nil {
		log.Println("chunk: replication call: nil address.")
		return nil
	}

	log.Println("chunk: replication request chunk", args.ChunkID)
	_, present := chunkTable[args.ChunkID]
	if present {
		log.Println("chunk: already have it!")
		return nil
	}

	for i := 0; i < len(args.Servers); i++ {
		if args.Servers[i].String() == tcpAddr.String() {
			continue
		}

		replicationHost, err := rpc.Dial("tcp", args.Servers[i].String())
		if replicationHost != nil {
			defer replicationHost.Close()
		}
		if err != nil {
			log.Println("chunk: replication error", err)
			continue
		}

		var readArgs sfs.ReadArgs
		var readRet sfs.ReadReturn
		readArgs.ChunkID = args.ChunkID
		readArgs.Nice = sfs.FORCE
		log.Println("chunk: replicating from", args.Servers[i])
		err = replicationHost.Call("Server.Read", &readArgs, &readRet)
		if err != nil {
			log.Println("chunk: replication error", err)
			continue
		}
		log.Println("chunk: replication complete")

		chunkTable[args.ChunkID] = readRet.Data
		var info sfs.ChunkInfo
		info.ChunkID = readArgs.ChunkID
		addedChunks.Push(info)
		capacity--
		break
	}
	return nil
}
开发者ID:alangenfeld,项目名称:cs639,代码行数:49,代码来源:chunk_mem.go

示例13: Write

func (t *Server) Write(args *sfs.WriteArgs, ret *sfs.WriteReturn) os.Error {

	log.Println("chunk: Writing to chunk ", args.Info.ChunkID)
	data, present := chunkTable[args.Info.ChunkID]
	if !present {
		addedChunks.Push(args.Info)
		capacity--
	}

	data.Data = args.Data.Data
	chunkTable[args.Info.ChunkID] = data

	tempServ := args.Info.Servers[0]
	var inRet sfs.WriteReturn

	for {
		if len(args.Info.Servers) < 2 {
			break
		}

		args.Info.Servers = args.Info.Servers[1:len(args.Info.Servers)]

		client, err := rpc.Dial("tcp", args.Info.Servers[0].String())
		if err != nil {
			log.Printf("chunk: dialing:", err)
			continue
		}

		err = client.Call("Server.Write", &args, &inRet)
		if err != nil {
			log.Fatal("chunk: server error: ", err)
		}
		break
	}

	ret.Info.Servers = make([]net.TCPAddr, len(inRet.Info.Servers)+1)

	for i := 0; i < len(ret.Info.Servers); i++ {
		if i < len(inRet.Info.Servers) {
			ret.Info.Servers[i] = inRet.Info.Servers[i]
		} else {
			ret.Info.Servers[i] = tempServ
		}
	}

	return nil
}
开发者ID:lalkaka,项目名称:stealthFS,代码行数:47,代码来源:chunk_mem.go

示例14: Read

/* read */
func Read(fd int, size int) ([]byte, int) {
	//goes to chunk and gets a chunk of memory to read...
	fileInfo := new(sfs.ReadReturn)
	fileArgs := new(sfs.ReadArgs)
	fdFile, inMap := openFiles[fd]
	var entireRead []byte
	//this size needs to be fixed
	entireRead = make([]byte, fdFile.chunkInfo.Len()*sfs.CHUNK_SIZE)
	if !inMap {
		log.Printf("Client: File not in open list!\n")
		return entireRead, FAIL
	}
	index := 0
	for i := 0; i < fdFile.chunkInfo.Len(); i++ {
		if len(fdFile.chunkInfo.At(i).(sfs.ChunkInfo).Servers) < 1 {
			log.Fatal("Client: No servers listed")
		}
		client, err := rpc.Dial("tcp", fdFile.chunkInfo.At(i).(sfs.ChunkInfo).Servers[0].String())
		if err != nil {
			log.Printf("Client: Dial Failed in Read")
			return entireRead, FAIL
		}
		fileArgs.ChunkID = fdFile.chunkInfo.At(i).(sfs.ChunkInfo).ChunkID

		chunkCall := client.Go("Server.Read", &fileArgs, &fileInfo, nil)
		replyCall := <-chunkCall.Done
		if replyCall.Error != nil {
			log.Printf("Client: error in reply from rpc in read\n")
			return entireRead, FAIL
		}
		log.Printf("\nClient: Status = %d\n", fileInfo.Status)
		log.Printf("Client: Data = %d\n", fileInfo.Data)
		if fileInfo.Status != 0 {
			break
		}
		for j := 0; j < sfs.CHUNK_SIZE; j++ {
			entireRead[j] = fileInfo.Data.Data[j]
			index++
		}
	}

	return entireRead, fileInfo.Status
}
开发者ID:lalkaka,项目名称:stealthFS,代码行数:44,代码来源:client.go

示例15: ReadDir

func ReadDir(path string) ([]string, int) {

	readDirArgs := new(sfs.ReadDirArgs)
	readDirRet := new(sfs.ReadDirReturn)
	readDirArgs.Prefix = path
	client, err := rpc.Dial("tcp", master+":1338") //IP needs to be changed to Master's IP
	defer client.Close()
	if err != nil {
		log.Println("Client: Dial Error", err)
		return readDirRet.FileNames, FAIL
	} else {
		err = client.Call("Master.ReadDir", &readDirArgs, &readDirRet)
		if err != nil {
			log.Println("Client: Read Dir fail ", err)
			return readDirRet.FileNames, FAIL
		}
	}
	//	for i:= 0 ; i < len(readDirRet.FileNames) ; i++ {
	//		log.Println("Client: Got back directory: ", readDirRet.FileNames[i])
	//	}
	return readDirRet.FileNames, WIN
}
开发者ID:alangenfeld,项目名称:cs639,代码行数:22,代码来源:client.go


注:本文中的rpc.Dial函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。