コード例 #1
0
ファイル: server.go プロジェクト: InsZVA/MonkeyDB
func (cmd command) Dropdb(db **C.Database) []byte {
	//锁并发
	_, ok := mutex[**db]
	if !ok {
		mutex[**db] = new(sync.RWMutex)
	}
	mutex[**db].Lock()
	defer mutex[**db].Unlock()

	response := []byte{}
	key, _ := convert.ParseUntil(cmd, 0, 7)
	*db = C.DropDB((*C.char)(convert.Bytes2C(key)))
	return response
}
コード例 #2
0
ファイル: server.go プロジェクト: Axure/MonkeyDB
////////////////////////////////////////Dumplated//////////////////////////////////////////////////////////////////////////
func TranslateMessage(s *tcp.TCPSession, db **C.Database, message []byte) {
	command := string(message)
	params := strings.Split(command, " ")
	//fmt.Println(params)
	response := []byte{}
	if params[0] == "set" {
		r := C.Set(&(*db).tIndex, (*C.char)(convert.String2C(params[1])), (convert.String2C(params[2])))
		for i := 0; ; i++ {
			response = append(response, byte(r.msg[i]))
			if response[i] == 0 {
				break
			}
		}
	} else if params[0] == "get" {
		r := C.Get(&(*db).tIndex, (*C.char)(convert.String2C(params[1])))
		// for i := 0;;i++ {
		// 	response = append(response,byte(r.msg[i]))
		// 	if response[i] == 0 { break; }
		// }
		if int(r.code) == 0 {
			for i := 0; ; i++ {
				response = append(response, byte(*(*C.char)(unsafe.Pointer((uintptr(r.pData) + uintptr(i))))))
				if response[i] == 0 {
					break
				}
			}
		} else {
			// for i := 0;;i++ {
			// response = append(response,byte(r.msg[i]))
			// if response[i] == 0 { break; }
			// }
		}

	} else if params[0] == "delete" || params[0] == "remove" {
		r := C.Delete(&(*db).tIndex, (*C.char)(convert.String2C(params[1])))
		for i := 0; ; i++ {
			response = append(response, byte(r.msg[i]))
			if response[i] == 0 {
				break
			}
		}

	} else if params[0] == "createdb" {
		d := C.CreateDB((*C.char)(convert.String2C(params[1])))
		if d != nil {
			*db = d
			response = []byte("Already exist,switched\n")
		} else {
			response = []byte("Created\n")
		}
	} else if params[0] == "switchdb" {
		d := C.SwitchDB((*C.char)(convert.String2C(params[1])))
		if d != nil {
			*db = d
			response = []byte("ok\n")
		} else {
			response = []byte("fail\n")
		}
	} else if params[0] == "dropdb" {
		*db = C.DropDB((*C.char)(convert.String2C(params[1])))
	} else if strings.EqualFold("listdb", params[0]) {
		r := C.ListDB()
		for i := 0; i < 1024; i++ {
			b := byte(*(*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(r)) + uintptr(i))))
			response = append(response, b)
			if b == 0 {
				break
			}
		}
		C.free(unsafe.Pointer(r))
	} else {
		//fmt.Println("unkown command:",params[0])
	}
	s.SendMessage(response)
}
コード例 #3
0
ファイル: server.go プロジェクト: Axure/MonkeyDB
func (cmd command) Dropdb(db **C.Database) []byte {
	response := []byte{}
	key, _ := convert.ParseUntil(cmd, 0, 7)
	*db = C.DropDB((*C.char)(convert.Bytes2C(key)))
	return response
}