* * *

Author Topic: Strange behavior with freepascal and IPC Queue Message  (Read 3469 times)

eolandro

  • Newbie
  • Posts: 4
Strange behavior with freepascal and IPC Queue Message
« on: April 18, 2017, 08:59:54 am »
I have two codes one in freepascal and anothe in php. The pascal code creates an IPC Queue and sends one byte in that queue. If the queue already has elements. it does not send any byte. The php code only gets the state of the queue.

But the strange is freepascal can not get the length of the queue(sg_qnum). This value is always zero.
In the other hand the php code gets that value without trouble.

I have no other PC maybe is my installation maybe is my code.

Can you help me test my code?

Thanks

Thaddy

  • Hero Member
  • *****
  • Posts: 5984
Re: Strange behavior with freepascal and IPC Queue Message
« Reply #1 on: April 18, 2017, 11:08:47 am »
Both attachment read like a piece of shit.
Do better.
I might not give the answer that you want me to.. Peter Green 1969

eolandro

  • Newbie
  • Posts: 4
Re: Strange behavior with freepascal and IPC Queue Message
« Reply #2 on: April 18, 2017, 06:28:56 pm »
Both attachment read like a piece of shit.
Do better.

Show me how. Let me see your code. An example.

Kays

  • Full Member
  • ***
  • Posts: 108
  • Whasup!?
    • KaiBurghardt.de
Re: Strange behavior with freepascal and IPC Queue Message
« Reply #3 on: January 10, 2018, 12:32:24 pm »
[…] But the strange is freepascal can not get the length of the queue(sg_qnum). This value is always zero. […]
Yeah, this happens occasionally, but usually with new (Linux) features: The record shipped with the RTL doesn't correctly map the memory structure, thus making you read a byte remaining zero. I had to redeclare TMSQid_ds using /usr/include/x86_64-linux-gnu/bits/msq.h as the blueprint:
Code: Pascal  [Select]
  1.         TMSQid_ds = record
  2.                 /// \brief structure describing operation permission
  3.                 msg_perm: TIPC_perm;
  4.                 /// \brief time of last msgsnd command
  5.                 msg_stime: time_t;
  6.                 {$ifndef CPUX86_64}
  7.                         glibc_reserved0: culong;
  8.                 {$endif}
  9.                 /// \brief time of last msgrcv command
  10.                 msg_rtime: time_t;
  11.                 {$ifndef CPUX86_64}
  12.                         glibc_reserved1: culong;
  13.                 {$endif}
  14.                 /// \brief time of last change
  15.                 msg_ctime: time_t;
  16.                 {$ifndef CPUX86_64}
  17.                         glibc_reserved2: culong;
  18.                 {$endif}
  19.                 /// \brief current number of bytes on queue
  20.                 msg_cbytes: msglen_t;
  21.                 /// \brief number of messages currently on queue
  22.                 msg_qnum: msgqnum_t;
  23.                 /// \brief max number of bytes allowed on queue
  24.                 msg_qbytes: msglen_t;
  25.                 /// \brief pid of last msgsnd()
  26.                 msg_lspid: pid_t;
  27.                 /// \brief pid of last msgrcv()
  28.                 msg_lrpid: pid_t;
  29.                 glibc_reserved3: culong;
  30.                 glibc_reserved4: culong;
  31.         end;
  • for failing routines' return values do a equal-comparison
  • you can specify octal numbers by prepending an ampersand
  • use sizeOf() where appropriate
Yours Sincerely
Kai Burghardt

Thaddy

  • Hero Member
  • *****
  • Posts: 5984
Re: Strange behavior with freepascal and IPC Queue Message
« Reply #4 on: January 10, 2018, 12:43:37 pm »
[Yeah, this happens occasionally, but usually with new (Linux) features: The record shipped with the RTL doesn't correctly map the memory structure
So you did not know to add {$packrecords C} ??
I might not give the answer that you want me to.. Peter Green 1969

Kays

  • Full Member
  • ***
  • Posts: 108
  • Whasup!?
    • KaiBurghardt.de
Re: Strange behavior with freepascal and IPC Queue Message
« Reply #5 on: January 10, 2018, 01:10:33 pm »
[…] So you did not know to add {$packrecords C} ?? […]
Nah, I wasn't particularly aware of that now. I don't compile my RTL, though. I use what's packaged.

So I first headed to /usr/share/fpcsrc/3.0.0/packages/rtl-extra/src/ipc.pp and then looked at bits/msq.h for reference. As the fields aren't already in order, I assumed that's the problem.

And there's a {$packrecords C} in ipc.pp; I can't tell right off the bat whether it has/had its proper effect, but I guess the peeps who write RTL units know what they're doing.

PS: “the fields aren't already in order”: I've had another look onto I: I mean the fields msg_first and msg_last don't appear in my bits/msq.h, but they do in the if defined(Linux) branch in ipc.pp.
PPS: And this is already, at least in trunk, fixed. But, as I wrote, I usually work/produce with already packaged (“stable”) stuff.
« Last Edit: January 10, 2018, 05:01:37 pm by Kays »
Yours Sincerely
Kai Burghardt

eolandro

  • Newbie
  • Posts: 4
Re: Strange behavior with freepascal and IPC Queue Message
« Reply #6 on: January 13, 2018, 07:26:08 am »
thanks so much!!!!

i was so much time stuck.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus