1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
<html>
<head>
<title>~/src/firstworks/rudiments-0.31/include/rudiments/sharedmemory.h.html</title>
<meta name="Generator" content="Vim/7.0">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#ffffff" text="#000000">
<pre>
<font color="#0000ff">// Copyright (c) 1999-2002 David Muse</font>
<font color="#0000ff">// See the COPYING file for more information.</font>
<font color="#a020f0">#ifndef RUDIMENTS_SHAREDMEMORY_H</font>
<font color="#a020f0">#define RUDIMENTS_SHAREDMEMORY_H</font>
<font color="#a020f0">#include </font><font color="#ff00ff"><rudiments/private/sharedmemoryincludes.h></font>
<font color="#0000ff">// Shared memory segments allow multiple processes to access a common</font>
<font color="#0000ff">// address space.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Shared memory can be used for interprocess communication and is generally</font>
<font color="#0000ff">// faster than using fifo's or unix sockets.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// To synchronize access to shared memory, use the semaphoreset class.</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// A shared memory segment is owned by a user and group and has access </font>
<font color="#0000ff">// permissions just like a file.</font>
<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
<font color="#2e8b57"><b>namespace</b></font> rudiments {
<font color="#a020f0">#endif</font>
<font color="#2e8b57"><b>class</b></font> sharedmemoryprivate;
<font color="#2e8b57"><b>class</b></font> sharedmemory {
<font color="#a52a2a"><b>public</b></font>:
sharedmemory();
<font color="#0000ff">// Creates a shared memory segment.</font>
~sharedmemory();
<font color="#0000ff">// Cleans up and removes the shared memory segment if</font>
<font color="#0000ff">// it was created by the create() or createOrAttach() </font>
<font color="#0000ff">// method below. If it was just attached to, it is</font>
<font color="#0000ff">// not removed.</font>
<font color="#2e8b57"><b>bool</b></font> create(key_t key, <font color="#2e8b57"><b>size_t</b></font> size,
mode_t permissions);
<font color="#0000ff">// Creates a shared memory segment of "size" bytes, </font>
<font color="#0000ff">// identified by "key".</font>
<font color="#0000ff">// "key" should be generated using the ftok</font>
<font color="#0000ff">// function.</font>
<font color="#0000ff">// "permissions" sets the access permissions</font>
<font color="#0000ff">// for the segment.</font>
<font color="#2e8b57"><b>bool</b></font> attach(key_t key);
<font color="#0000ff">// Attaches to a shared memory identified by "key".</font>
<font color="#2e8b57"><b>bool</b></font> createOrAttach(key_t key, <font color="#2e8b57"><b>size_t</b></font> size,
mode_t permissions);
<font color="#0000ff">// Attempts to create the shared memory segment </font>
<font color="#0000ff">// identified by "key". If this fails, it attempts</font>
<font color="#0000ff">// to attach to a shared memory segment identified by</font>
<font color="#0000ff">// "key".</font>
<font color="#2e8b57"><b>void</b></font> dontRemove();
<font color="#0000ff">// Instructs the destructor not to remove the shared</font>
<font color="#0000ff">// memory segment if it was created during a call to</font>
<font color="#0000ff">// create() or createOrAttach() above. This is useful</font>
<font color="#0000ff">// if an application creates a shared memory segment</font>
<font color="#0000ff">// then forks and wants to delete the shared memory</font>
<font color="#0000ff">// segment in the forked process but does not want</font>
<font color="#0000ff">// the segment removed from the system.</font>
<font color="#2e8b57"><b>bool</b></font> forceRemove();
<font color="#0000ff">// Removes the shared memory segment whether it was</font>
<font color="#0000ff">// created or just attached to.</font>
<font color="#2e8b57"><b>int</b></font> getId() <font color="#2e8b57"><b>const</b></font>;
<font color="#0000ff">// Returns the internal id for the </font>
<font color="#0000ff">// shared memory segment.</font>
<font color="#2e8b57"><b>void</b></font> *getPointer() <font color="#2e8b57"><b>const</b></font>;
<font color="#0000ff">// Returns a pointer to the shared memory</font>
<font color="#0000ff">// segment. Data may be read from or written</font>
<font color="#0000ff">// to the segment using this pointer.</font>
<font color="#2e8b57"><b>bool</b></font> setUserName(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *username);
<font color="#0000ff">// Makes this shared memory segment owned by</font>
<font color="#0000ff">// the user "username".</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Note that setUserName() uses the passwdentry class.</font>
<font color="#0000ff">// If you are using this method in a multithreaded</font>
<font color="#0000ff">// application, you may need to supply the passwdentry</font>
<font color="#0000ff">// class a mutex. See passwdentry.h for more detail.</font>
<font color="#2e8b57"><b>bool</b></font> setGroupName(<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *groupname);
<font color="#0000ff">// Makes this shared memory segment owned by</font>
<font color="#0000ff">// the group "groupname".</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Note that setGroupName() uses the groupentry class.</font>
<font color="#0000ff">// If you are using this method in a multithreaded</font>
<font color="#0000ff">// application, you may need to supply the groupentry</font>
<font color="#0000ff">// class a mutex. See groupentry.h for more detail.</font>
<font color="#2e8b57"><b>bool</b></font> setUserId(uid_t uid);
<font color="#0000ff">// makes this shared memory segment owned by</font>
<font color="#0000ff">// the user identified by uid</font>
<font color="#2e8b57"><b>bool</b></font> setGroupId(gid_t gid);
<font color="#0000ff">// makes this shared memory segment owned by</font>
<font color="#0000ff">// the group identified by gid</font>
<font color="#2e8b57"><b>bool</b></font> setPermissions(mode_t permissions);
<font color="#0000ff">// sets the access permissions for this</font>
<font color="#0000ff">// shared memory segment to "permissions"</font>
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *getUserName();
<font color="#0000ff">// returns the name of the user that owns this</font>
<font color="#0000ff">// shared memory segment</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Note that getUserName() uses the passwdentry class.</font>
<font color="#0000ff">// If you are using this method in a multithreaded</font>
<font color="#0000ff">// application, you may need to supply the passwdentry</font>
<font color="#0000ff">// class a mutex. See passwdentry.h for more detail.</font>
<font color="#2e8b57"><b>const</b></font> <font color="#2e8b57"><b>char</b></font> *getGroupName();
<font color="#0000ff">// returns the name of the group that owns this</font>
<font color="#0000ff">// shared memory segment</font>
<font color="#0000ff">//</font>
<font color="#0000ff">// Note that getGroupName() uses the groupentry class.</font>
<font color="#0000ff">// If you are using this method in a multithreaded</font>
<font color="#0000ff">// application, you may need to supply the groupentry</font>
<font color="#0000ff">// class a mutex. See groupentry.h for more detail.</font>
uid_t getUserId();
<font color="#0000ff">// returns the user id of the user that owns this</font>
<font color="#0000ff">// shared memory segment</font>
gid_t getGroupId();
<font color="#0000ff">// returns the group id of the group that owns this</font>
<font color="#0000ff">// shared memory segment</font>
mode_t getPermissions();
<font color="#0000ff">// returns the access permissions for this</font>
<font color="#0000ff">// shared memory segment</font>
<font color="#a020f0"> #include </font><font color="#ff00ff"><rudiments/private/sharedmemory.h></font>
};
<font color="#a020f0">#ifdef RUDIMENTS_NAMESPACE</font>
}
<font color="#a020f0">#endif</font>
<font color="#a020f0">#endif</font>
</pre>
</body>
</html>
|