From 69c6385272c4d2c401b8f286c2415ee9989f5bc1 Mon Sep 17 00:00:00 2001 From: hslam <791874158@qq.com> Date: Tue, 1 Dec 2020 16:08:25 +0800 Subject: [PATCH] update shm methods --- README.md | 4 ++-- ipc_test.go | 16 ++++++++-------- shm.go | 24 ++++++++++++------------ 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index c246bfa..5a5f1d5 100644 --- a/README.md +++ b/README.md @@ -56,9 +56,9 @@ func main() { } } defer ipc.Semrm(semid) - shmid, data, _ := ipc.Shmgetat(key, 128, ipc.IPC_CREAT|0600) + shmid, data, _ := ipc.Shmgetattach(key, 128, ipc.IPC_CREAT|0600) defer ipc.Shmrm(shmid) - defer ipc.Shmdt(data) + defer ipc.Shmdetach(data) msgid, _ := ipc.Msgget(key, ipc.IPC_CREAT|0600) defer ipc.Msgrm(msgid) var text string diff --git a/ipc_test.go b/ipc_test.go index 6dc06e3..94db7cc 100644 --- a/ipc_test.go +++ b/ipc_test.go @@ -29,9 +29,9 @@ func TestIPC(t *testing.T) { } } defer Semrm(semid) - shmid, data, _ := Shmgetat(key, 128, IPC_CREAT|0600) + shmid, data, _ := Shmgetattach(key, 128, IPC_CREAT|0600) defer Shmrm(shmid) - defer Shmdt(data) + defer Shmdetach(data) msgid, _ := Msgget(key, IPC_CREAT|0600) defer Msgrm(msgid) if _, err := Semp(semid, semnum, SEM_UNDO); err != nil { @@ -63,9 +63,9 @@ func TestIPC(t *testing.T) { } } defer Semrm(semid) - shmid, data, _ := Shmgetat(key, 128, 0600) + shmid, data, _ := Shmgetattach(key, 128, 0600) defer Shmrm(shmid) - defer Shmdt(data) + defer Shmdetach(data) msgid, _ := Msgget(key, 0600) defer Msgrm(msgid) @@ -111,9 +111,9 @@ func TestMore(t *testing.T) { } } defer Semrm(semid) - shmid, data, _ := Shmgetat(key, 128, IPC_CREAT|0600) + shmid, data, _ := Shmgetattach(key, 128, IPC_CREAT|0600) defer Shmrm(shmid) - defer Shmdt(data) + defer Shmdetach(data) msgid, _ := Msgget(key, IPC_CREAT|0600) defer Msgrm(msgid) if _, err := Semp(semid, semnum, SEM_UNDO); err != nil { @@ -148,14 +148,14 @@ func TestMore(t *testing.T) { size := 128 shmid, _ := Shmget(key, size, 0600) defer Shmrm(shmid) - shmaddr, _ := Shmattach(shmid, 0600) + shmaddr, _ := Shmat(shmid, 0600) var sl = struct { addr uintptr len int cap int }{shmaddr, size, size} data := *(*[]byte)(unsafe.Pointer(&sl)) - defer Shmdetach(shmaddr) + defer Shmdt(shmaddr) msgid, _ := Msgget(key, 0600) defer Msgrm(msgid) diff --git a/shm.go b/shm.go index bdc586a..787d9c7 100644 --- a/shm.go +++ b/shm.go @@ -12,24 +12,24 @@ func Shmget(key int, size int, shmFlg int) (int, error) { return shm.Get(key, size, shmFlg) } -// Shmattach calls the shmat system call. -func Shmattach(shmid int, shmFlg int) (uintptr, error) { - return shm.Attach(shmid, shmFlg) +// Shmat calls the shmat system call. +func Shmat(shmid int, shmFlg int) (uintptr, error) { + return shm.At(shmid, shmFlg) } -// Shmdetach calls the shmdt system call. -func Shmdetach(addr uintptr) error { - return shm.Detach(addr) +// Shmdt calls the shmdt system call. +func Shmdt(addr uintptr) error { + return shm.Dt(addr) } -// Shmgetat calls the shmget and shmat system call. -func Shmgetat(key int, size int, shmFlg int) (int, []byte, error) { - return shm.GetAt(key, size, shmFlg) +// Shmgetattach calls the shmget and shmat system call. +func Shmgetattach(key int, size int, shmFlg int) (int, []byte, error) { + return shm.GetAttach(key, size, shmFlg) } -// Shmdt calls the shmdt system call with []byte b. -func Shmdt(b []byte) error { - return shm.Dt(b) +// Shmdetach calls the shmdt system call with []byte b. +func Shmdetach(b []byte) error { + return shm.Detach(b) } // Shmrm removes the shm with the given id.