mirror of https://github.com/hslam/ipc.git
add ipc
This commit is contained in:
parent
7cf6cacadf
commit
b21fd44a40
|
@ -0,0 +1,15 @@
|
||||||
|
// Copyright (c) 2020 Meng Huang (mhboy@outlook.com)
|
||||||
|
// This package is licensed under a MIT license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package ipc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hslam/ftok"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Ftok uses the given pathname (which must refer to an existing, accessible file) and
|
||||||
|
// the least significant 8 bits of proj_id (which must be nonzero) to generate
|
||||||
|
// a key_t type System V IPC key.
|
||||||
|
func Ftok(pathname string, projectid uint8) (int, error) {
|
||||||
|
return ftok.Ftok(pathname, projectid)
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
// Copyright (c) 2020 Meng Huang (mhboy@outlook.com)
|
||||||
|
// This package is licensed under a MIT license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Package ipc provides a way to use System V IPC.
|
||||||
|
// System V IPC includes three interprocess communication mechanisms
|
||||||
|
// that are widely available on UNIX systems: message queues, semaphore, and shared memory.
|
||||||
|
package ipc
|
||||||
|
|
||||||
|
const (
|
||||||
|
// IPC_CREAT creates if key is nonexistent
|
||||||
|
IPC_CREAT = 00001000
|
||||||
|
|
||||||
|
// IPC_EXCL fails if key exists.
|
||||||
|
IPC_EXCL = 00002000
|
||||||
|
|
||||||
|
// IPC_NOWAIT returns error no wait.
|
||||||
|
IPC_NOWAIT = 04000
|
||||||
|
|
||||||
|
// SEM_UNDO sets up adjust on exit entry
|
||||||
|
SEM_UNDO = 010000
|
||||||
|
|
||||||
|
// IPC_RMID removes identifier
|
||||||
|
IPC_RMID = 0
|
||||||
|
// IPC_SET sets ipc_perm options.
|
||||||
|
IPC_SET = 1
|
||||||
|
// IPC_STAT gets ipc_perm options.
|
||||||
|
IPC_STAT = 2
|
||||||
|
)
|
|
@ -0,0 +1,28 @@
|
||||||
|
// Copyright (c) 2020 Meng Huang (mhboy@outlook.com)
|
||||||
|
// This package is licensed under a MIT license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package ipc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hslam/msg"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Msgget calls the msgget system call.
|
||||||
|
func Msgget(key int, msgflg int) (uintptr, error) {
|
||||||
|
return msg.Get(key, msgflg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Msgsnd calls the msgsnd system call.
|
||||||
|
func Msgsnd(msgid uintptr, msgType uint, msgText []byte, flags uint) error {
|
||||||
|
return msg.Snd(msgid, msgType, msgText, flags)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Msgrcv calls the msgrcv system call.
|
||||||
|
func Msgrcv(msgid uintptr, msgType uint, flags uint) ([]byte, error) {
|
||||||
|
return msg.Rcv(msgid, msgType, flags)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Msgrm removes the shm with the given id.
|
||||||
|
func Msgrm(msgid uintptr) error {
|
||||||
|
return msg.Remove(msgid)
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright (c) 2020 Meng Huang (mhboy@outlook.com)
|
||||||
|
// This package is licensed under a MIT license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package ipc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hslam/sem"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Semget calls the semget system call.
|
||||||
|
func Semget(key int) (uintptr, error) {
|
||||||
|
return sem.Get(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Semp calls the semop P system call.
|
||||||
|
func Semp(semid uintptr, flg int16) (bool, error) {
|
||||||
|
return sem.P(semid, flg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Semv calls the semop V system call.
|
||||||
|
func Semv(semid uintptr, flg int16) (bool, error) {
|
||||||
|
return sem.V(semid, flg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Semgetvalue calls the semctl GETVAL system call.
|
||||||
|
func Semgetvalue(semid uintptr) (int, error) {
|
||||||
|
return sem.GetValue(semid)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Semrm removes the semaphore with the given id.
|
||||||
|
func Semrm(semid uintptr) error {
|
||||||
|
return sem.Remove(semid)
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
// Copyright (c) 2020 Meng Huang (mhboy@outlook.com)
|
||||||
|
// This package is licensed under a MIT license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package ipc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hslam/shm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Shmgetat calls the shmget and shmat system call.
|
||||||
|
func Shmgetat(key int, size int, shmFlg int) (uintptr, []byte, error) {
|
||||||
|
return shm.GetAt(key, size, shmFlg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shmdt calls the shmdt system call.
|
||||||
|
func Shmdt(b []byte) error {
|
||||||
|
return shm.Dt(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shmrm removes the shm with the given id.
|
||||||
|
func Shmrm(shmid uintptr) error {
|
||||||
|
return shm.Remove(shmid)
|
||||||
|
}
|
Loading…
Reference in New Issue