diff --git a/README.md b/README.md index 421c4e7..721902f 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ func main() { } func writer() { - shmid, data, err := shm.GetAt(2, 128, shm.IPC_CREATE|0600) + shmid, data, err := shm.GetAt(2, 128, shm.IPC_CREAT|0600) if err != nil { log.Fatal(err) } @@ -92,9 +92,9 @@ func writer() { if err != nil { panic(err) } + defer shm.Close(fd) length := 128 shm.Ftruncate(fd, int64(length)) - defer shm.Close(fd) defer shm.Unlink(name) data, err := mmap.Open(fd, 0, length, mmap.READ|mmap.WRITE) if err != nil { @@ -110,6 +110,7 @@ func reader() { if err != nil { panic(err) } + defer shm.Close(fd) data, err := mmap.Open(fd, 0, 128, mmap.READ) if err != nil { panic(err) diff --git a/shm_unix.go b/shm_unix.go index be9aeaa..7685de2 100644 --- a/shm_unix.go +++ b/shm_unix.go @@ -11,8 +11,8 @@ import ( ) const ( - // IPC_CREATE creates if key is nonexistent - IPC_CREATE = 00001000 + // IPC_CREAT creates if key is nonexistent + IPC_CREAT = 00001000 //IPC_RMID removes identifier IPC_RMID = 0 @@ -21,7 +21,7 @@ const ( // GetAt calls the shmget and shmat system call. func GetAt(key int, size int, shmFlg int) (uintptr, []byte, error) { if shmFlg == 0 { - shmFlg = IPC_CREATE | 0600 + shmFlg = IPC_CREAT | 0600 } shmid, _, errno := syscall.Syscall(SYS_SHMGET, uintptr(key), uintptr(validSize(int64(size))), uintptr(shmFlg)) if int(shmid) < 0 { diff --git a/shm_unix_test.go b/shm_unix_test.go index acd11e7..881518b 100644 --- a/shm_unix_test.go +++ b/shm_unix_test.go @@ -16,7 +16,7 @@ func TestGetAt(t *testing.T) { context := "Hello World" done := make(chan struct{}) go func() { - shmid, data, err := GetAt(2, 128, IPC_CREATE|0600) + shmid, data, err := GetAt(2, 128, IPC_CREAT|0600) if err != nil { t.Error(err) }