| | |
| | | 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) |
| | |
| | | } |
| | | |
| | | return int(idDs.Nattch), nil |
| | | } |
| | | |
| | | func GetKeyById(shmId int) (int,error) { |
| | | var idDs shm.IdDs |
| | | |
| | | _, err := shm.Ctl(shmId, shm.IPC_STAT, &idDs) |
| | | if err != nil { |
| | | return 0, err |
| | | } |
| | | |
| | | return int(idDs.Perm.Key), nil |
| | | } |