From 76a2829555cf460df48cb86600a44681f57ab1fa Mon Sep 17 00:00:00 2001 From: chenshijun <chenshijun@aiotlink.com> Date: 星期二, 07 四月 2020 20:51:56 +0800 Subject: [PATCH] shmwrap.go 增加check共享内存key对应的共享内存是否存在的接口 --- shmwrap.go | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/shmwrap.go b/shmwrap.go index 8dad1d7..8634dbf 100644 --- a/shmwrap.go +++ b/shmwrap.go @@ -149,6 +149,18 @@ return data, id } +// CheckShmExist check if shm is exist or not +// if exist, return id and true, else return 0 and false +func CheckShmExist(key int) (int, bool) { + id, err := shm.Get(key, 0, 0) + if err != nil || id == -1 { //no exist + fmt.Printf("AttachBlock Get:%x, %v\n", key, err) + return 0, false + } + + return id, true +} + // DetachShm destroy func DetachShm(data []byte) { ReleaseBlock(data) -- Gitblit v1.8.0