示例#1
0
文件: server.go 项目: JashDave/cloud
func serve(conn *net.TCPConn, uid uint64, receiveChan *(chan *fs.Msg), rn *raft.RaftNode) {
	reader := bufio.NewReader(conn)

	//replyChan := fs.GetChannel(uid)
	for {
		msg, msgerr, fatalerr := fs.GetMsg(reader)
		if fatalerr != nil || msgerr != nil {
			reply(conn, &fs.Msg{Kind: 'M'})
			conn.Close()
			break
		}

		if msgerr != nil {
			if (!reply(conn, &fs.Msg{Kind: 'M'})) {
				conn.Close()
				break
			}
		}

		//response := fsys.ProcessMsg(msg)
		data, _ := json.Marshal(ClientMessage{uid, *msg}) //? handle error reply(conn, &fs.Msg{Kind: 'I'})
		rn.Append(data)
		response, _ := <-*receiveChan //? error
		if !reply(conn, response) {
			conn.Close()
			break
		}
	}
}
示例#2
0
文件: server.go 项目: JashDave/cloud
func InitClientHandeler(rn *raft.RaftNode, fsys *fs.FileSystem) *ClientHandeler {
	ch := ClientHandeler{}
	//fmt.Println("RN:", rn,"FS", fsys)
	ch.rn = rn
	ch.client_chans = make(map[uint64](chan *fs.Msg))
	ch.commitChan = rn.GetCommitChannel()
	ch.fsys = fsys
	return &ch
}