Recent

Author Topic: msgrcv only succeeds if msgsnd sends a buffer with only zeros.  (Read 396 times)

TCH

  • Full Member
  • ***
  • Posts: 177
I have two processes, which have these lines:
Code: Pascal  [Select][+][-]
  1. msgp.mtype := 1;
  2. e := msgsnd(msqid, @msgp, 4, IPC_NOWAIT);
and
Code: Pascal  [Select][+][-]
  1. sz := msgrcv(msqid, @msgp, 4, 1, IPC_NOWAIT);
The variable msgp is the type of
Code: Pascal  [Select][+][-]
  1. type mymsg1 = record
  2.         mtype: longword;
  3.         mtext: array[0..7] of byte;
  4. end;
Now, msgsnd() always reports no problems, that the buffer is sent. However, msgrcv() always gives back -1 with errno of ESysENOMSG, except if the first four byte of msgp.mtext are zeros. Then it succeeds, else it fails. Regardless the size of the sent buffer.

The very same algorithm and code works flawlessly with C. Any ideas?

TCH

  • Full Member
  • ***
  • Posts: 177
Re: msgrcv only succeeds if msgsnd sends a buffer with only zeros.
« Reply #1 on: May 17, 2022, 11:58:24 am »
No ideas?

MarkMLl

  • Hero Member
  • *****
  • Posts: 4163
Re: msgrcv only succeeds if msgsnd sends a buffer with only zeros.
« Reply #2 on: May 17, 2022, 12:13:49 pm »
What library are you using? How is the socket opened?

Give us a compilable example to demonstrate the problem.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 9983
  • FPC developer.
Re: msgrcv only succeeds if msgsnd sends a buffer with only zeros.
« Reply #3 on: May 17, 2022, 01:31:09 pm »
  • OS
  • compiler target and version
  • c code
  • pascal code

MarkMLl

  • Hero Member
  • *****
  • Posts: 4163
Re: msgrcv only succeeds if msgsnd sends a buffer with only zeros.
« Reply #4 on: May 17, 2022, 02:09:15 pm »
If we really are obliged to read minds, I suggest that https://linux.die.net/man/2/msgrcv might be relevant, which *explicitly* says:

Code: Text  [Select][+][-]
  1. The msgp argument is a pointer to caller-defined structure of the following
  2. general form:
  3.  
  4.     struct msgbuf {
  5.         long mtype;       /* message type, must be > 0 */
  6.         char mtext[1];    /* message data */
  7.     };
  8.  
  9. The mtext field is an array (or other structure) whose size is specified by
  10. msgsz, a nonnegative integer value. Messages of zero length (i.e., no
  11. mtext field) are permitted. The mtype field must have a strictly positive
  12. integer value. This value can be used by the receiving process for message
  13. selection (see the description of msgrcv() below).
  14.  

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

TCH

  • Full Member
  • ***
  • Posts: 177
Re: msgrcv only succeeds if msgsnd sends a buffer with only zeros.
« Reply #5 on: May 18, 2022, 06:36:02 pm »
I use no library and i open no socket. The OS is Linux AMD64, the target is the same. The FPC is of version 3.2.2 The C and Pascal code are here:
http://oscomp.hu/depot/msgtest.c
http://oscomp.hu/depot/msgtest.pas
And i've read the manual; the C code works as intended. But in the Pascal code, only a longint of zero can be transmitted, all else will yield a result of -1 and ESysENOMSG in errno (fpgeterrno).

MarkMLl

  • Hero Member
  • *****
  • Posts: 4163
Re: msgrcv only succeeds if msgsnd sends a buffer with only zeros.
« Reply #6 on: May 18, 2022, 06:47:45 pm »
I use no library and i open no socket. The OS is Linux AMD64, the target is the same. The FPC is of version 3.2.2 The C and Pascal code are here:
http://oscomp.hu/depot/msgtest.c
http://oscomp.hu/depot/msgtest.pas
And i've read the manual; the C code works as intended. But in the Pascal code, only a longint of zero can be transmitted, all else will yield a result of -1 and ESysENOMSG in errno (fpgeterrno).

You are using the Pascal ipc library as documented at https://www.freepascal.org/docs-html/current/rtl/ipc/index-5.html.

I suggest you start off with the example give there, without making any assumptions that it is directly compatible with the low-level unix API.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

TCH

  • Full Member
  • ***
  • Posts: 177
Re: msgrcv only succeeds if msgsnd sends a buffer with only zeros.
« Reply #7 on: May 18, 2022, 07:26:35 pm »
Isn't that a unit? Also, even if it's not compatible with the UNIX API, why does it work with a buffer of zeros and not elseway? This is the most basic existing usage: one send and one receive. It should work.
Besides i need to be compatible with the UNIX API. The programs will not necessarily be all written in Pascal. Maybe either process will be C, the other will be Pascal. (Not this one example.)
« Last Edit: May 18, 2022, 07:32:18 pm by TCH »

 

TinyPortal © 2005-2018