mirror of https://github.com/hslam/ipc.git
update shm methods
This commit is contained in:
parent
f15816045d
commit
69c6385272
|
@ -56,9 +56,9 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
defer ipc.Semrm(semid)
|
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.Shmrm(shmid)
|
||||||
defer ipc.Shmdt(data)
|
defer ipc.Shmdetach(data)
|
||||||
msgid, _ := ipc.Msgget(key, ipc.IPC_CREAT|0600)
|
msgid, _ := ipc.Msgget(key, ipc.IPC_CREAT|0600)
|
||||||
defer ipc.Msgrm(msgid)
|
defer ipc.Msgrm(msgid)
|
||||||
var text string
|
var text string
|
||||||
|
|
16
ipc_test.go
16
ipc_test.go
|
@ -29,9 +29,9 @@ func TestIPC(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
defer Semrm(semid)
|
defer Semrm(semid)
|
||||||
shmid, data, _ := Shmgetat(key, 128, IPC_CREAT|0600)
|
shmid, data, _ := Shmgetattach(key, 128, IPC_CREAT|0600)
|
||||||
defer Shmrm(shmid)
|
defer Shmrm(shmid)
|
||||||
defer Shmdt(data)
|
defer Shmdetach(data)
|
||||||
msgid, _ := Msgget(key, IPC_CREAT|0600)
|
msgid, _ := Msgget(key, IPC_CREAT|0600)
|
||||||
defer Msgrm(msgid)
|
defer Msgrm(msgid)
|
||||||
if _, err := Semp(semid, semnum, SEM_UNDO); err != nil {
|
if _, err := Semp(semid, semnum, SEM_UNDO); err != nil {
|
||||||
|
@ -63,9 +63,9 @@ func TestIPC(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
defer Semrm(semid)
|
defer Semrm(semid)
|
||||||
shmid, data, _ := Shmgetat(key, 128, 0600)
|
shmid, data, _ := Shmgetattach(key, 128, 0600)
|
||||||
defer Shmrm(shmid)
|
defer Shmrm(shmid)
|
||||||
defer Shmdt(data)
|
defer Shmdetach(data)
|
||||||
msgid, _ := Msgget(key, 0600)
|
msgid, _ := Msgget(key, 0600)
|
||||||
defer Msgrm(msgid)
|
defer Msgrm(msgid)
|
||||||
|
|
||||||
|
@ -111,9 +111,9 @@ func TestMore(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
defer Semrm(semid)
|
defer Semrm(semid)
|
||||||
shmid, data, _ := Shmgetat(key, 128, IPC_CREAT|0600)
|
shmid, data, _ := Shmgetattach(key, 128, IPC_CREAT|0600)
|
||||||
defer Shmrm(shmid)
|
defer Shmrm(shmid)
|
||||||
defer Shmdt(data)
|
defer Shmdetach(data)
|
||||||
msgid, _ := Msgget(key, IPC_CREAT|0600)
|
msgid, _ := Msgget(key, IPC_CREAT|0600)
|
||||||
defer Msgrm(msgid)
|
defer Msgrm(msgid)
|
||||||
if _, err := Semp(semid, semnum, SEM_UNDO); err != nil {
|
if _, err := Semp(semid, semnum, SEM_UNDO); err != nil {
|
||||||
|
@ -148,14 +148,14 @@ func TestMore(t *testing.T) {
|
||||||
size := 128
|
size := 128
|
||||||
shmid, _ := Shmget(key, size, 0600)
|
shmid, _ := Shmget(key, size, 0600)
|
||||||
defer Shmrm(shmid)
|
defer Shmrm(shmid)
|
||||||
shmaddr, _ := Shmattach(shmid, 0600)
|
shmaddr, _ := Shmat(shmid, 0600)
|
||||||
var sl = struct {
|
var sl = struct {
|
||||||
addr uintptr
|
addr uintptr
|
||||||
len int
|
len int
|
||||||
cap int
|
cap int
|
||||||
}{shmaddr, size, size}
|
}{shmaddr, size, size}
|
||||||
data := *(*[]byte)(unsafe.Pointer(&sl))
|
data := *(*[]byte)(unsafe.Pointer(&sl))
|
||||||
defer Shmdetach(shmaddr)
|
defer Shmdt(shmaddr)
|
||||||
msgid, _ := Msgget(key, 0600)
|
msgid, _ := Msgget(key, 0600)
|
||||||
defer Msgrm(msgid)
|
defer Msgrm(msgid)
|
||||||
|
|
||||||
|
|
24
shm.go
24
shm.go
|
@ -12,24 +12,24 @@ func Shmget(key int, size int, shmFlg int) (int, error) {
|
||||||
return shm.Get(key, size, shmFlg)
|
return shm.Get(key, size, shmFlg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shmattach calls the shmat system call.
|
// Shmat calls the shmat system call.
|
||||||
func Shmattach(shmid int, shmFlg int) (uintptr, error) {
|
func Shmat(shmid int, shmFlg int) (uintptr, error) {
|
||||||
return shm.Attach(shmid, shmFlg)
|
return shm.At(shmid, shmFlg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shmdetach calls the shmdt system call.
|
// Shmdt calls the shmdt system call.
|
||||||
func Shmdetach(addr uintptr) error {
|
func Shmdt(addr uintptr) error {
|
||||||
return shm.Detach(addr)
|
return shm.Dt(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shmgetat calls the shmget and shmat system call.
|
// Shmgetattach calls the shmget and shmat system call.
|
||||||
func Shmgetat(key int, size int, shmFlg int) (int, []byte, error) {
|
func Shmgetattach(key int, size int, shmFlg int) (int, []byte, error) {
|
||||||
return shm.GetAt(key, size, shmFlg)
|
return shm.GetAttach(key, size, shmFlg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shmdt calls the shmdt system call with []byte b.
|
// Shmdetach calls the shmdt system call with []byte b.
|
||||||
func Shmdt(b []byte) error {
|
func Shmdetach(b []byte) error {
|
||||||
return shm.Dt(b)
|
return shm.Detach(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shmrm removes the shm with the given id.
|
// Shmrm removes the shm with the given id.
|
||||||
|
|
Loading…
Reference in New Issue