Exemplo n.º 1
0
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
		}
	}
}
Exemplo n.º 2
0
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
}