module SysVIPC
Document-class: SysVIPC
SysVIPC
¶ ↑
Ruby module for System V Inter-Process Communication: message queues, semaphores, and shared memory.
Hosted as project sysvipc on RubyForge.
Copyright (C) 2001, 2006, 2007 Daiki Ueno Copyright (C) 2006-2013 James Steven Jenkins
Usage Synopsis¶ ↑
Common Code¶ ↑
All programs using this module must include
require 'SysVIPC'
It may be convenient to add
include SysVIPC
All IPC objects are identified by a key. SysVIPC
includes a convenience function for mapping file names and integer IDs into a key:
key = ftok('/a/file/that/must/exist', 0)
Message Queues¶ ↑
Get (create if necessary) a message queue:
mq = MessageQueue.new(key, IPC_CREAT | 0600)
Send a message of type 0:
mq.send(0, 'message')
Receive up to 100 bytes from the first message of type 0:
msg = mq.receive(0, 100)
Semaphores¶ ↑
Get (create if necessary) a set of 5 semaphores:
sm = Semaphore.new(key, 5, IPC_CREAT | 0600)
Initialize semaphores if newly created:
sm.setall(Array.new(5, 1)) if sm.pid(0) == 0
Acquire semaphore 2 (waiting if necessary):
sm.op([Sembuf.new(2, -1)])
Release semaphore 2:
sm.op([Sembuf.new(2, 1)])
Shared Memory¶ ↑
Get (create if necessary) an 8192-byte shared memory region:
sh = SharedMemory.new(key, 8192, IPC_CREAT | 0660)
Attach shared memory:
shmaddr = sh.attach
Write data:
shmaddr.write('testing')
Read 100 bytes of data:
data = shmaddr.read(100);
Detach shared memory:
sh.detach(shmaddr)
Installation¶ ↑
-
ruby setup.rb config
-
ruby setup.rb setup
-
ruby setup.rb install
(requires appropriate privilege)
Testing¶ ↑
-
./test_sysvipc_l
(low-level interface) -
./test_sysvipc_h
(high-level interface)
Constants
- GETALL
- GETNCNT
- GETPID
- GETVAL
- GETZCNT
- IPC_CREAT
- IPC_EXCL
- IPC_NOWAIT
- IPC_PRIVATE
- IPC_RMID
- IPC_SET
- IPC_STAT
- MSG_NOERROR
- RELEASE
- SEM_UNDO
- SETALL
- SETVAL
- SHMLBA
- SHM_RDONLY
- SHM_RND
- VERSION
Public Class Methods
SWIGINTERN VALUE _wrap_errno_get(VALUE self) { VALUE _val; _val = SWIG_From_int((int)(errno)); return _val; }
SWIGINTERN VALUE _wrap_ftok(int argc, VALUE *argv, VALUE self) { char *arg1 = (char *) 0 ; int arg2 ; int res1 ; char *buf1 = 0 ; int alloc1 = 0 ; int val2 ; int ecode2 = 0 ; key_t result; VALUE vresult = Qnil; if ((argc < 2) || (argc > 2)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 2)",argc); SWIG_fail; } res1 = SWIG_AsCharPtrAndSize(argv[0], &buf1, NULL, &alloc1); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "char const *","ftok", 1, argv[0] )); } arg1 = (char *)(buf1); ecode2 = SWIG_AsVal_int(argv[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), Ruby_Format_TypeError( "", "int","ftok", 2, argv[1] )); } arg2 = (int)(val2); result = (key_t)ftok((char const *)arg1,arg2); vresult = SWIG_From_unsigned_SS_int((unsigned int)(result)); if (alloc1 == SWIG_NEWOBJ) free((char*)buf1); return vresult; fail: if (alloc1 == SWIG_NEWOBJ) free((char*)buf1); return Qnil; }
SWIGINTERN VALUE _wrap_msgctl(int argc, VALUE *argv, VALUE self) { int arg1 ; int arg2 ; struct msqid_ds *arg3 = (struct msqid_ds *) 0 ; int val1 ; int ecode1 = 0 ; int val2 ; int ecode2 = 0 ; void *argp3 = 0 ; int res3 = 0 ; VALUE result; VALUE vresult = Qnil; { } if ((argc < 2) || (argc > 3)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 2)",argc); SWIG_fail; } ecode1 = SWIG_AsVal_int(argv[0], &val1); if (!SWIG_IsOK(ecode1)) { SWIG_exception_fail(SWIG_ArgError(ecode1), Ruby_Format_TypeError( "", "int","inner_msgctl", 1, argv[0] )); } arg1 = (int)(val1); ecode2 = SWIG_AsVal_int(argv[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), Ruby_Format_TypeError( "", "int","inner_msgctl", 2, argv[1] )); } arg2 = (int)(val2); if (argc > 2) { res3 = SWIG_ConvertPtr(argv[2], &argp3,SWIGTYPE_p_msqid_ds, 0 | 0 ); if (!SWIG_IsOK(res3)) { SWIG_exception_fail(SWIG_ArgError(res3), Ruby_Format_TypeError( "", "struct msqid_ds *","inner_msgctl", 3, argv[2] )); } arg3 = (struct msqid_ds *)(argp3); } result = (VALUE)inner_msgctl(arg1,arg2,arg3); vresult = result; return vresult; fail: return Qnil; }
SWIGINTERN VALUE _wrap_msgget(int argc, VALUE *argv, VALUE self) { key_t arg1 ; int arg2 ; unsigned int val1 ; int ecode1 = 0 ; int val2 ; int ecode2 = 0 ; int result; VALUE vresult = Qnil; if ((argc < 2) || (argc > 2)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 2)",argc); SWIG_fail; } ecode1 = SWIG_AsVal_unsigned_SS_int(argv[0], &val1); if (!SWIG_IsOK(ecode1)) { SWIG_exception_fail(SWIG_ArgError(ecode1), Ruby_Format_TypeError( "", "key_t","msgget", 1, argv[0] )); } arg1 = (key_t)(val1); ecode2 = SWIG_AsVal_int(argv[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), Ruby_Format_TypeError( "", "int","msgget", 2, argv[1] )); } arg2 = (int)(val2); result = (int)msgget(arg1,arg2); vresult = SWIG_From_int((int)(result)); return vresult; fail: return Qnil; }
SWIGINTERN VALUE _wrap_msgrcv(int argc, VALUE *argv, VALUE self) { int arg1 ; size_t arg2 ; long arg3 ; int arg4 ; int val1 ; int ecode1 = 0 ; size_t val2 ; int ecode2 = 0 ; long val3 ; int ecode3 = 0 ; int val4 ; int ecode4 = 0 ; VALUE result; VALUE vresult = Qnil; if ((argc < 4) || (argc > 4)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 4)",argc); SWIG_fail; } ecode1 = SWIG_AsVal_int(argv[0], &val1); if (!SWIG_IsOK(ecode1)) { SWIG_exception_fail(SWIG_ArgError(ecode1), Ruby_Format_TypeError( "", "int","inner_msgrcv", 1, argv[0] )); } arg1 = (int)(val1); ecode2 = SWIG_AsVal_size_t(argv[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), Ruby_Format_TypeError( "", "size_t","inner_msgrcv", 2, argv[1] )); } arg2 = (size_t)(val2); ecode3 = SWIG_AsVal_long(argv[2], &val3); if (!SWIG_IsOK(ecode3)) { SWIG_exception_fail(SWIG_ArgError(ecode3), Ruby_Format_TypeError( "", "long","inner_msgrcv", 3, argv[2] )); } arg3 = (long)(val3); ecode4 = SWIG_AsVal_int(argv[3], &val4); if (!SWIG_IsOK(ecode4)) { SWIG_exception_fail(SWIG_ArgError(ecode4), Ruby_Format_TypeError( "", "int","inner_msgrcv", 4, argv[3] )); } arg4 = (int)(val4); result = (VALUE)inner_msgrcv(arg1,arg2,arg3,arg4); vresult = result; return vresult; fail: return Qnil; }
SWIGINTERN VALUE _wrap_msgsnd(int argc, VALUE *argv, VALUE self) { int arg1 ; long arg2 ; VALUE arg3 = (VALUE) 0 ; int arg4 ; int val1 ; int ecode1 = 0 ; long val2 ; int ecode2 = 0 ; int val4 ; int ecode4 = 0 ; VALUE result; VALUE vresult = Qnil; if ((argc < 4) || (argc > 4)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 4)",argc); SWIG_fail; } ecode1 = SWIG_AsVal_int(argv[0], &val1); if (!SWIG_IsOK(ecode1)) { SWIG_exception_fail(SWIG_ArgError(ecode1), Ruby_Format_TypeError( "", "int","inner_msgsnd", 1, argv[0] )); } arg1 = (int)(val1); ecode2 = SWIG_AsVal_long(argv[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), Ruby_Format_TypeError( "", "long","inner_msgsnd", 2, argv[1] )); } arg2 = (long)(val2); arg3 = argv[2]; ecode4 = SWIG_AsVal_int(argv[3], &val4); if (!SWIG_IsOK(ecode4)) { SWIG_exception_fail(SWIG_ArgError(ecode4), Ruby_Format_TypeError( "", "int","inner_msgsnd", 4, argv[3] )); } arg4 = (int)(val4); result = (VALUE)inner_msgsnd(arg1,arg2,arg3,arg4); vresult = result; return vresult; fail: return Qnil; }
SWIGINTERN VALUE _wrap_semctl(int argc, VALUE *argv, VALUE self) { int arg1 ; int arg2 ; int arg3 ; VALUE arg4 = (VALUE) 0 ; int val1 ; int ecode1 = 0 ; int val2 ; int ecode2 = 0 ; int val3 ; int ecode3 = 0 ; VALUE result; VALUE vresult = Qnil; { } if ((argc < 3) || (argc > 4)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 3)",argc); SWIG_fail; } ecode1 = SWIG_AsVal_int(argv[0], &val1); if (!SWIG_IsOK(ecode1)) { SWIG_exception_fail(SWIG_ArgError(ecode1), Ruby_Format_TypeError( "", "int","inner_semctl", 1, argv[0] )); } arg1 = (int)(val1); ecode2 = SWIG_AsVal_int(argv[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), Ruby_Format_TypeError( "", "int","inner_semctl", 2, argv[1] )); } arg2 = (int)(val2); ecode3 = SWIG_AsVal_int(argv[2], &val3); if (!SWIG_IsOK(ecode3)) { SWIG_exception_fail(SWIG_ArgError(ecode3), Ruby_Format_TypeError( "", "int","inner_semctl", 3, argv[2] )); } arg3 = (int)(val3); if (argc > 3) { arg4 = argv[3]; } result = (VALUE)inner_semctl(arg1,arg2,arg3,arg4); vresult = result; return vresult; fail: return Qnil; }
SWIGINTERN VALUE _wrap_semget(int argc, VALUE *argv, VALUE self) { key_t arg1 ; int arg2 ; int arg3 ; unsigned int val1 ; int ecode1 = 0 ; int val2 ; int ecode2 = 0 ; int val3 ; int ecode3 = 0 ; int result; VALUE vresult = Qnil; if ((argc < 3) || (argc > 3)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 3)",argc); SWIG_fail; } ecode1 = SWIG_AsVal_unsigned_SS_int(argv[0], &val1); if (!SWIG_IsOK(ecode1)) { SWIG_exception_fail(SWIG_ArgError(ecode1), Ruby_Format_TypeError( "", "key_t","semget", 1, argv[0] )); } arg1 = (key_t)(val1); ecode2 = SWIG_AsVal_int(argv[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), Ruby_Format_TypeError( "", "int","semget", 2, argv[1] )); } arg2 = (int)(val2); ecode3 = SWIG_AsVal_int(argv[2], &val3); if (!SWIG_IsOK(ecode3)) { SWIG_exception_fail(SWIG_ArgError(ecode3), Ruby_Format_TypeError( "", "int","semget", 3, argv[2] )); } arg3 = (int)(val3); result = (int)semget(arg1,arg2,arg3); vresult = SWIG_From_int((int)(result)); return vresult; fail: return Qnil; }
SWIGINTERN VALUE _wrap_semop(int argc, VALUE *argv, VALUE self) { int arg1 ; struct sembuf *arg2 ; size_t arg3 ; int val1 ; int ecode1 = 0 ; size_t val3 ; int ecode3 = 0 ; VALUE result; VALUE vresult = Qnil; if ((argc < 3) || (argc > 3)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 3)",argc); SWIG_fail; } ecode1 = SWIG_AsVal_int(argv[0], &val1); if (!SWIG_IsOK(ecode1)) { SWIG_exception_fail(SWIG_ArgError(ecode1), Ruby_Format_TypeError( "", "int","inner_semop", 1, argv[0] )); } arg1 = (int)(val1); { struct sembuf *sp, *t; int i, len; argv[1] = rb_check_array_type(argv[1]); len = RARRAY_LEN(argv[1]); arg2 = sp = (struct sembuf *) ALLOCA_N(struct sembuf, len); for (i = 0; i < len; i++) { Data_Get_Struct(rb_ary_entry(argv[1], i), struct sembuf, t); memcpy(sp++, t, sizeof(struct sembuf)); } } ecode3 = SWIG_AsVal_size_t(argv[2], &val3); if (!SWIG_IsOK(ecode3)) { SWIG_exception_fail(SWIG_ArgError(ecode3), Ruby_Format_TypeError( "", "size_t","inner_semop", 3, argv[2] )); } arg3 = (size_t)(val3); result = (VALUE)inner_semop(arg1,arg2,arg3); vresult = result; return vresult; fail: return Qnil; }
SWIGINTERN VALUE _wrap_shmat(int argc, VALUE *argv, VALUE self) { int arg1 ; struct shmaddr *arg2 = (struct shmaddr *) 0 ; int arg3 ; int val1 ; int ecode1 = 0 ; void *argp2 = 0 ; int res2 = 0 ; int val3 ; int ecode3 = 0 ; struct shmaddr *result = 0 ; VALUE vresult = Qnil; if ((argc < 3) || (argc > 3)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 3)",argc); SWIG_fail; } ecode1 = SWIG_AsVal_int(argv[0], &val1); if (!SWIG_IsOK(ecode1)) { SWIG_exception_fail(SWIG_ArgError(ecode1), Ruby_Format_TypeError( "", "int","shmat", 1, argv[0] )); } arg1 = (int)(val1); res2 = SWIG_ConvertPtr(argv[1], &argp2,SWIGTYPE_p_shmaddr, 0 | 0 ); if (!SWIG_IsOK(res2)) { SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "struct shmaddr const *","shmat", 2, argv[1] )); } arg2 = (struct shmaddr *)(argp2); ecode3 = SWIG_AsVal_int(argv[2], &val3); if (!SWIG_IsOK(ecode3)) { SWIG_exception_fail(SWIG_ArgError(ecode3), Ruby_Format_TypeError( "", "int","shmat", 3, argv[2] )); } arg3 = (int)(val3); result = (struct shmaddr *)shmat(arg1,(struct shmaddr const *)arg2,arg3); vresult = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_shmaddr, 0 | 0 ); return vresult; fail: return Qnil; }
SWIGINTERN VALUE _wrap_shmctl(int argc, VALUE *argv, VALUE self) { int arg1 ; int arg2 ; struct shmid_ds *arg3 = (struct shmid_ds *) 0 ; int val1 ; int ecode1 = 0 ; int val2 ; int ecode2 = 0 ; void *argp3 = 0 ; int res3 = 0 ; VALUE result; VALUE vresult = Qnil; { } if ((argc < 2) || (argc > 3)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 2)",argc); SWIG_fail; } ecode1 = SWIG_AsVal_int(argv[0], &val1); if (!SWIG_IsOK(ecode1)) { SWIG_exception_fail(SWIG_ArgError(ecode1), Ruby_Format_TypeError( "", "int","inner_shmctl", 1, argv[0] )); } arg1 = (int)(val1); ecode2 = SWIG_AsVal_int(argv[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), Ruby_Format_TypeError( "", "int","inner_shmctl", 2, argv[1] )); } arg2 = (int)(val2); if (argc > 2) { res3 = SWIG_ConvertPtr(argv[2], &argp3,SWIGTYPE_p_shmid_ds, 0 | 0 ); if (!SWIG_IsOK(res3)) { SWIG_exception_fail(SWIG_ArgError(res3), Ruby_Format_TypeError( "", "struct shmid_ds *","inner_shmctl", 3, argv[2] )); } arg3 = (struct shmid_ds *)(argp3); } result = (VALUE)inner_shmctl(arg1,arg2,arg3); vresult = result; return vresult; fail: return Qnil; }
SWIGINTERN VALUE _wrap_shmdt(int argc, VALUE *argv, VALUE self) { struct shmaddr *arg1 = (struct shmaddr *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int result; VALUE vresult = Qnil; if ((argc < 1) || (argc > 1)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(argv[0], &argp1,SWIGTYPE_p_shmaddr, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "struct shmaddr *","shmdt", 1, argv[0] )); } arg1 = (struct shmaddr *)(argp1); result = (int)shmdt(arg1); vresult = SWIG_From_int((int)(result)); return vresult; fail: return Qnil; }
SWIGINTERN VALUE _wrap_shmget(int argc, VALUE *argv, VALUE self) { key_t arg1 ; size_t arg2 ; int arg3 ; unsigned int val1 ; int ecode1 = 0 ; size_t val2 ; int ecode2 = 0 ; int val3 ; int ecode3 = 0 ; int result; VALUE vresult = Qnil; if ((argc < 3) || (argc > 3)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 3)",argc); SWIG_fail; } ecode1 = SWIG_AsVal_unsigned_SS_int(argv[0], &val1); if (!SWIG_IsOK(ecode1)) { SWIG_exception_fail(SWIG_ArgError(ecode1), Ruby_Format_TypeError( "", "key_t","shmget", 1, argv[0] )); } arg1 = (key_t)(val1); ecode2 = SWIG_AsVal_size_t(argv[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), Ruby_Format_TypeError( "", "size_t","shmget", 2, argv[1] )); } arg2 = (size_t)(val2); ecode3 = SWIG_AsVal_int(argv[2], &val3); if (!SWIG_IsOK(ecode3)) { SWIG_exception_fail(SWIG_ArgError(ecode3), Ruby_Format_TypeError( "", "int","shmget", 3, argv[2] )); } arg3 = (int)(val3); result = (int)shmget(arg1,arg2,arg3); vresult = SWIG_From_int((int)(result)); return vresult; fail: return Qnil; }
SWIGINTERN VALUE _wrap_shmread(int argc, VALUE *argv, VALUE self) { struct shmaddr *arg1 = (struct shmaddr *) 0 ; size_t arg2 ; size_t arg3 ; void *argp1 = 0 ; int res1 = 0 ; size_t val2 ; int ecode2 = 0 ; size_t val3 ; int ecode3 = 0 ; VALUE result; VALUE vresult = Qnil; if ((argc < 3) || (argc > 3)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 3)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(argv[0], &argp1,SWIGTYPE_p_shmaddr, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "struct shmaddr const *","inner_shmread", 1, argv[0] )); } arg1 = (struct shmaddr *)(argp1); ecode2 = SWIG_AsVal_size_t(argv[1], &val2); if (!SWIG_IsOK(ecode2)) { SWIG_exception_fail(SWIG_ArgError(ecode2), Ruby_Format_TypeError( "", "size_t","inner_shmread", 2, argv[1] )); } arg2 = (size_t)(val2); ecode3 = SWIG_AsVal_size_t(argv[2], &val3); if (!SWIG_IsOK(ecode3)) { SWIG_exception_fail(SWIG_ArgError(ecode3), Ruby_Format_TypeError( "", "size_t","inner_shmread", 3, argv[2] )); } arg3 = (size_t)(val3); result = (VALUE)inner_shmread((struct shmaddr const *)arg1,arg2,arg3); vresult = result; return vresult; fail: return Qnil; }
SWIGINTERN VALUE _wrap_shmwrite(int argc, VALUE *argv, VALUE self) { struct shmaddr *arg1 = (struct shmaddr *) 0 ; VALUE arg2 = (VALUE) 0 ; size_t arg3 ; void *argp1 = 0 ; int res1 = 0 ; size_t val3 ; int ecode3 = 0 ; VALUE result; VALUE vresult = Qnil; { } if ((argc < 1) || (argc > 3)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail; } res1 = SWIG_ConvertPtr(argv[0], &argp1,SWIGTYPE_p_shmaddr, 0 | 0 ); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "struct shmaddr *","inner_shmwrite", 1, argv[0] )); } arg1 = (struct shmaddr *)(argp1); if (argc > 1) { arg2 = argv[1]; } if (argc > 2) { ecode3 = SWIG_AsVal_size_t(argv[2], &val3); if (!SWIG_IsOK(ecode3)) { SWIG_exception_fail(SWIG_ArgError(ecode3), Ruby_Format_TypeError( "", "size_t","inner_shmwrite", 3, argv[2] )); } arg3 = (size_t)(val3); } result = (VALUE)inner_shmwrite(arg1,arg2,arg3); vresult = result; return vresult; fail: return Qnil; }