Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh: support drop user notify #201

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,9 @@ const ReqIDKey = "taos_req_id"
const (
TAOS_NOTIFY_PASSVER = 0
TAOS_NOTIFY_WHITELIST_VER = 1
TAOS_NOTIFY_USER_DROPPED = 2
)

const (
TAOS_CONN_MODE_BI = 0
)
21 changes: 21 additions & 0 deletions wrapper/notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,25 @@ func TestNotify(t *testing.T) {
t.Error("wait for notify callback timeout")
}
}
{
notify := make(chan struct{}, 1)
handler := cgo.NewHandle(notify)
errCode := TaosSetNotifyCB(conn2, handler, common.TAOS_NOTIFY_USER_DROPPED)
if errCode != 0 {
errStr := TaosErrorStr(nil)
t.Error(errCode, errStr)
}
err = exec(conn, "drop USER t_notify")
assert.NoError(t, err)
timeout, cancel = context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
now := time.Now()
select {
case _ = <-notify:
fmt.Println(time.Now().Sub(now))
t.Log("user dropped")
case <-timeout.Done():
t.Error("wait for notify callback timeout")
}
}
}
8 changes: 6 additions & 2 deletions wrapper/notifycb.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ func NotifyCallback(p unsafe.Pointer, ext unsafe.Pointer, notifyType C.int) {
// channel may be closed
recover()
}()
if int(notifyType) == common.TAOS_NOTIFY_PASSVER {
switch int(notifyType) {
case common.TAOS_NOTIFY_PASSVER:
version := int32(*(*C.int32_t)(ext))
c := (*(*cgo.Handle)(p)).Value().(chan int32)
c <- version
} else if int(notifyType) == common.TAOS_NOTIFY_WHITELIST_VER {
case common.TAOS_NOTIFY_WHITELIST_VER:
version := int64(*(*C.int64_t)(ext))
c := (*(*cgo.Handle)(p)).Value().(chan int64)
c <- version
case common.TAOS_NOTIFY_USER_DROPPED:
c := (*(*cgo.Handle)(p)).Value().(chan struct{})
c <- struct{}{}
}
}
2 changes: 0 additions & 2 deletions wrapper/whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"github.com/taosdata/driver-go/v3/wrapper/cgo"
)

const TAOS_NOTIFY_WHITELIST_VER = 1

// typedef void (*__taos_async_whitelist_fn_t)(void *param, int code, TAOS *taos, int numOfWhiteLists, uint64_t* pWhiteLists);

// TaosFetchWhitelistA DLL_EXPORT void taos_fetch_whitelist_a(TAOS *taos, __taos_async_whitelist_fn_t fp, void *param);
Expand Down