Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
need help creating install package for SIMPL open source project
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="bobicanprogram" data-source="post: 1206099" data-attributes="member: 195399"><p><strong>more details on shared memory problem</strong></p><p></p><p>Here is the code snip of the shared memory activity from the sender side of the SIMPL transaction.</p><p></p><p>======= begin code snip from sender =========</p><p>_simpl_myStuff.shmid = shmget(IPC_PRIVATE, memSize, 0777 | IPC_CREAT);</p><p>if (_simpl_myStuff.shmid == -1)</p><p> {</p><p> _simpl_setErrorCode(CANNOT_CREATE_SHMEM);</p><p> _simpl_log("%s: unable to create shmem-%s\n", fn, strerror(errno));</p><p> return(-1);</p><p> }</p><p></p><p>// attach the shmem for messages to this process</p><p>_simpl_myStuff.shmPtr = shmat(_simpl_myStuff.shmid, 0, 0);</p><p>if (_simpl_myStuff.shmPtr == (char *)-1)</p><p> {</p><p> _simpl_setErrorCode(CANNOT_ATTACH_SHMEM);</p><p> _simpl_log("%s: unable to attach shmem to process-%s\n", fn, strerror(er</p><p>rno));</p><p> return(-1);</p><p> }</p><p></p><p>// release shmem if and when owner dies by an untrappable signal</p><p>shmctl(_simpl_myStuff.shmid, IPC_RMID, 0);</p><p>======= end code snip from sender =====</p><p></p><p>All these sender side calls work without any errors. The shmid is then transmitted via a named pipe (fifo) to the receiver. The log shows that this shmid is identical on both sides of this pipe. The code inside the receiver which fails is in the snip below.</p><p></p><p>======= begin code snip from receiver ======</p><p>/*</p><p>Attach the sender's shmem to this process.</p><p>Known to fail if sender suddenly disappears.</p><p>Saving this value allows the Reply() to use the same shmem.</p><p>*/</p><p>*sender = shmat(fifoMsg->shmid, 0, 0);</p><p>if (*sender == (char *)-1)</p><p> {</p><p> _simpl_setErrorCode(CANNOT_ATTACH_SHMEM);</p><p> _simpl_log("%s: shmid=%d cannot attach to shmem-%s\n", fn, fifoMsg->shmi</p><p>d, strerror(errno));</p><p> ReplyError(*sender);</p><p> return(-1);</p><p> }</p><p></p><p>======= end code snip from receiver ========</p><p></p><p>Obviously there is lots of other code surrounding these two snips, so I went back to my "Linux Programming by Example" book and pulled some shared memory sample code together which is listed below.</p><p></p><p>========= begin sample code for sender side ========</p><p>#include <stdio.h></p><p>#include <stdlib.h></p><p>#include <errno.h></p><p>#include <sys/shm.h></p><p></p><p>int main(void)</p><p>{</p><p>int shmid;</p><p>char *shmbuf;</p><p>char command[80];</p><p></p><p>printf("mkshm starting\n");</p><p></p><p>shmid=shmget(IPC_PRIVATE, 4096, 0777 | IPC_CREAT);</p><p>if(shmid == -1)</p><p> {</p><p> printf("shmget error %s\n",strerror(errno));</p><p> }</p><p></p><p>system("ipcs -m");</p><p></p><p>shmbuf=shmat(shmid,0,0);</p><p>if(shmbuf == (char *)-1)</p><p> {</p><p> printf("mkshm: shmat error %s\n",strerror(errno));</p><p> exit(-1);</p><p> }</p><p></p><p>sprintf(command,"./atshm %d", shmid);</p><p>system(command); </p><p></p><p>shmctl(shmid, IPC_RMID, 0);</p><p>exit(0);</p><p>}</p><p>========= end sample code for sender side =========</p><p></p><p>========= begin sample code for receiver side ========</p><p>#include <stdio.h></p><p>#include <stdlib.h></p><p>#include <errno.h></p><p>#include <sys/shm.h></p><p></p><p>int main(int argc, char *argv[])</p><p>{</p><p>int shmid;</p><p>char *shmbuf;</p><p></p><p>printf("atshm starting\n");</p><p></p><p>shmid=atoi(argv[1]);</p><p></p><p>printf("atshm: shmid=%d\n",shmid);</p><p></p><p>shmbuf=shmat(shmid,0,0);</p><p>if(shmbuf == (char *)-1)</p><p> {</p><p> printf("atshm: shmat error %s\n",strerror(errno));</p><p> exit(-1);</p><p> }</p><p>system("ipcs -m");</p><p></p><p>shmdt(shmbuf);</p><p></p><p>system("ipcs -m");</p><p></p><p>exit(0);</p><p>}</p><p></p><p>========= end sample code for receiver side =========</p><p></p><p></p><p>Notice that it has the same sequence as the SIMPL code.</p><p></p><p>The maddening part is that the sample code WORKS !!! </p><p></p><p>Any ideas what is going on here?</p><p></p><p>bob</p></blockquote><p></p>
[QUOTE="bobicanprogram, post: 1206099, member: 195399"] [b]more details on shared memory problem[/b] Here is the code snip of the shared memory activity from the sender side of the SIMPL transaction. ======= begin code snip from sender ========= _simpl_myStuff.shmid = shmget(IPC_PRIVATE, memSize, 0777 | IPC_CREAT); if (_simpl_myStuff.shmid == -1) { _simpl_setErrorCode(CANNOT_CREATE_SHMEM); _simpl_log("%s: unable to create shmem-%s\n", fn, strerror(errno)); return(-1); } // attach the shmem for messages to this process _simpl_myStuff.shmPtr = shmat(_simpl_myStuff.shmid, 0, 0); if (_simpl_myStuff.shmPtr == (char *)-1) { _simpl_setErrorCode(CANNOT_ATTACH_SHMEM); _simpl_log("%s: unable to attach shmem to process-%s\n", fn, strerror(er rno)); return(-1); } // release shmem if and when owner dies by an untrappable signal shmctl(_simpl_myStuff.shmid, IPC_RMID, 0); ======= end code snip from sender ===== All these sender side calls work without any errors. The shmid is then transmitted via a named pipe (fifo) to the receiver. The log shows that this shmid is identical on both sides of this pipe. The code inside the receiver which fails is in the snip below. ======= begin code snip from receiver ====== /* Attach the sender's shmem to this process. Known to fail if sender suddenly disappears. Saving this value allows the Reply() to use the same shmem. */ *sender = shmat(fifoMsg->shmid, 0, 0); if (*sender == (char *)-1) { _simpl_setErrorCode(CANNOT_ATTACH_SHMEM); _simpl_log("%s: shmid=%d cannot attach to shmem-%s\n", fn, fifoMsg->shmi d, strerror(errno)); ReplyError(*sender); return(-1); } ======= end code snip from receiver ======== Obviously there is lots of other code surrounding these two snips, so I went back to my "Linux Programming by Example" book and pulled some shared memory sample code together which is listed below. ========= begin sample code for sender side ======== #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <sys/shm.h> int main(void) { int shmid; char *shmbuf; char command[80]; printf("mkshm starting\n"); shmid=shmget(IPC_PRIVATE, 4096, 0777 | IPC_CREAT); if(shmid == -1) { printf("shmget error %s\n",strerror(errno)); } system("ipcs -m"); shmbuf=shmat(shmid,0,0); if(shmbuf == (char *)-1) { printf("mkshm: shmat error %s\n",strerror(errno)); exit(-1); } sprintf(command,"./atshm %d", shmid); system(command); shmctl(shmid, IPC_RMID, 0); exit(0); } ========= end sample code for sender side ========= ========= begin sample code for receiver side ======== #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <sys/shm.h> int main(int argc, char *argv[]) { int shmid; char *shmbuf; printf("atshm starting\n"); shmid=atoi(argv[1]); printf("atshm: shmid=%d\n",shmid); shmbuf=shmat(shmid,0,0); if(shmbuf == (char *)-1) { printf("atshm: shmat error %s\n",strerror(errno)); exit(-1); } system("ipcs -m"); shmdt(shmbuf); system("ipcs -m"); exit(0); } ========= end sample code for receiver side ========= Notice that it has the same sequence as the SIMPL code. The maddening part is that the sample code WORKS !!! Any ideas what is going on here? bob [/QUOTE]
Verification
Name this item. 🍎
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
need help creating install package for SIMPL open source project
Top