提交 396a6fc6 编写于 作者: yitter's avatar yitter

调整RegWorkerId的导出C函数

上级 dda4597a
...@@ -9,9 +9,11 @@ import ( ...@@ -9,9 +9,11 @@ import (
) )
func main() { func main() {
// ip := "localhost" ip := "localhost"
ipChar := C.CString("192.168.20.41") password := ""
passChar := C.CString("")
ipChar := C.CString(ip)
passChar := C.CString(password)
workerIdList := RegisterMany(ipChar, 6379, passChar, 4, 3, 0) workerIdList := RegisterMany(ipChar, 6379, passChar, 4, 3, 0)
for _, value := range workerIdList { for _, value := range workerIdList {
...@@ -21,9 +23,6 @@ func main() { ...@@ -21,9 +23,6 @@ func main() {
id := RegisterOne(ipChar, 6379, passChar, 4, 0) id := RegisterOne(ipChar, 6379, passChar, 4, 0)
fmt.Println("注册的WorkerId:", id) fmt.Println("注册的WorkerId:", id)
// C.free(unsafe.Pointer(ipChar))
// C.free(unsafe.Pointer(passChar))
// var workerId = regworkerid.RegisterOne(ip, 6379, "", 4) // var workerId = regworkerid.RegisterOne(ip, 6379, "", 4)
// fmt.Println("注册的WorkerId:", workerId) // fmt.Println("注册的WorkerId:", workerId)
...@@ -32,31 +31,31 @@ func main() { ...@@ -32,31 +31,31 @@ func main() {
} }
//export RegisterOne //export RegisterOne
// 注册一个 WorkerId,会先注销所有本机已注册的记录 // 注册一个 WorkerId
func RegisterOne(ip *C.char, port int32, password *C.char, maxWorkerId int32, database int) int32 { func RegisterOne(ip *C.char, port int32, password *C.char, maxWorkerId int32, database int) int32 {
return regworkerid.RegisterOne(C.GoString(ip), port, C.GoString(password), maxWorkerId, database) return regworkerid.RegisterOne(C.GoString(ip), port, C.GoString(password), maxWorkerId, database)
} }
// RegisterMany
// 注册多个 WorkerId,会先注销所有本机已注册的记录
func RegisterMany(ip *C.char, port int32, password *C.char, maxWorkerId, totalCount int32, database int) []int32 {
// return (*C.int)(unsafe.Pointer(&values))
//return regworkerid.RegisterMany(ip, port, password, maxWorkerId, totalCount, database)
return regworkerid.RegisterMany(C.GoString(ip), port, C.GoString(password), maxWorkerId, totalCount, database)
}
//export UnRegister //export UnRegister
// 注销本机已注册的 WorkerId // 注销本机已注册的 WorkerId
func UnRegister() { func UnRegister() {
regworkerid.UnRegister() regworkerid.UnRegister()
} }
//export Validate // export Validate
// 检查本地WorkerId是否有效(0-有效,其它-无效) // 检查本地WorkerId是否有效(0-有效,其它-无效)
func Validate(workerId int32) int32 { func Validate(workerId int32) int32 {
return regworkerid.Validate(workerId) return regworkerid.Validate(workerId)
} }
// RegisterMany
// 注册多个 WorkerId,会先注销所有本机已注册的记录
func RegisterMany(ip *C.char, port int32, password *C.char, maxWorkerId, totalCount int32, database int) []int32 {
// return (*C.int)(unsafe.Pointer(&values))
//return regworkerid.RegisterMany(ip, port, password, maxWorkerId, totalCount, database)
return regworkerid.RegisterMany(C.GoString(ip), port, C.GoString(password), maxWorkerId, totalCount, database)
}
// To Build a dll/so: // To Build a dll/so:
// windows: // windows:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册