Recent

Author Topic: Using the RTL's "Assignpipe" function  (Read 2388 times)

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 563
Using the RTL's "Assignpipe" function
« on: July 20, 2024, 06:35:39 pm »
Can anyone point me to an example of using the RTL's "AssignPipe" function to establish two-way communications between two FPC programs (if that is even an appropriate use of the function)?  The following short example program from the RTL docs demonstrates the function, but only lets the program "talk to itself," which doesn't make much sense to me.  Why would one want to do this?

Code: Pascal  [Select][+][-]
  1. Program Example36 ;
  2. { Program to demonstrate the AssignPipe function. }
  3. Uses BaseUnix , Unix ;
  4. Var pipi, pipo : Text ;
  5. s : String ;
  6. begin
  7. Writeln ( ' Assigning Pipes. ' ) ;
  8. If assignpipe( pipi,pipo )<>0 then
  9. Writeln ( ' Error assigning pipes ! ' , fpgeterrno ) ;
  10. Writeln ( ' Writing to pipe , and flushing . ' ) ;
  11. Writeln ( pipo , ' This is a text string ' ) ; close ( pipo ) ;
  12. Writeln ( ' Reading from pipi. ' ) ;
  13. While not eof ( pipi ) do
  14. begin
  15. Readln ( pipi , s ) ;
  16. Writeln ( ' Read from pipe : ' , s ) ;
  17. end ;
  18. close ( pipi ) ;
  19. writeln ( ' Closed pipes . ' ) ;
  20. writeln
  21. end .
  22.  

Compiles and executes OK.  Any enlightenment would be appreciated -- it seems so much cleaner an approach that using two the ipc components for a full-duplex link between processes.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8027
Re: Using the RTL's "Assignpipe" function
« Reply #1 on: July 20, 2024, 08:07:23 pm »
Looking at the example, I immediately found myself wondering what underlying IPC (inter-process communication) was being used.

Without having referred to the sources, I specifically note that the example has no provision for associating a name with the pipe. That leads me to suspect that it is normally used with fork() (i.e. FpFork() in the case of FPC's RTL) where two unix processes share memory, and as such it would be intended for the case where (e.g.) a single process is collecting commands from a socket and farming it out to separate instances of itself for processing.

I'm sure you're aware that as well as these anonymous pipes (which are closely related to commandline pipelines etc.) unix has named FIFOs (which broadly speaking use the file-handling API) and unix-domain sockets (which broadly speaking use the socket-handling API). Plus shared memory, plus a few other things added at the whim of various companies and development teams over the years.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 563
Re: Using the RTL's "Assignpipe" function
« Reply #2 on: July 20, 2024, 09:46:32 pm »
OK thanks that is very helpful.  I understand now how it would be used, and will turn my attention to trying to make the FpMkfifo function work with a named pipe.  I don't spend much time with the OS unless I have to, and have only started looking into something other than simple IPC this as a result of exploring the RTL and curiousity. 

Thanks again.


MarkMLl

  • Hero Member
  • *****
  • Posts: 8027
Re: Using the RTL's "Assignpipe" function
« Reply #3 on: July 20, 2024, 10:08:25 pm »
A couple of years ago I wrote some software to support an HP1630 logic analyzer ** , outputting to a file (which might in practice be a pipeline), existing named pipe (FIFO) or existing named unix-domain socket. It had a companion program which could read from any of those, and act as a somewhat quirky disassembler... I've not put it on Github yet since it still has rough edges but you'd be welcome to a copy.

** Why do I have something so old? It has 65 inputs handled in strict synchrony, 10 nSec resolution, and is safe to around 40V input: a combination which would be megabucks for something newer.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 563
Re: Using the RTL's "Assignpipe" function
« Reply #4 on: July 21, 2024, 12:31:22 am »
Long ago, I worked on specialized lithography computer that was built around four AMD2901 bit slices.  Lots of happy hours spent with an HP logic analyzer! (although I don't remember the model number).   Lots of EPROMS too.  Took forever to hook up all the probes, and then it seemed somebody was always jerking some loose.  Happy days... (*)

I got my Fpmkfifo calls working.  No real advantage over simpleipc at all, but the feeling of victory was nice.

(*)  My boss had built a sixteen bit computer from TTL before the 2901 project, and it's read-only code store was actually built using several PCB's worth of hand-wired 1N914 diode arrays.  I still have one somewhere.  It took REAL MEN to do that stuff  :)

Thaddy

  • Hero Member
  • *****
  • Posts: 16169
  • Censorship about opinions does not belong here.
Re: Using the RTL's "Assignpipe" function
« Reply #5 on: July 21, 2024, 07:31:18 am »
The AssignPipe function should not even be there, since Assign() is enough.
Assign() can take a unix handle and simply works.
If I smell bad code it usually is bad code and that includes my own code.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8027
Re: Using the RTL's "Assignpipe" function
« Reply #6 on: July 21, 2024, 09:19:00 am »
The AssignPipe function should not even be there, since Assign() is enough.
Assign() can take a unix handle and simply works.

Not documented, therefore doesn't exist.

https://www.freepascal.org/docs-html/current/rtl/system/assign.html

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

MarkMLl

  • Hero Member
  • *****
  • Posts: 8027
Re: Using the RTL's "Assignpipe" function
« Reply #7 on: July 21, 2024, 09:26:45 am »
Long ago, I worked on specialized lithography computer that was built around four AMD2901 bit slices.  Lots of happy hours spent with an HP logic analyzer! (although I don't remember the model number).   Lots of EPROMS too.  Took forever to hook up all the probes, and then it seemed somebody was always jerking some loose.  Happy days... (*)

I had an interesting revelation in the early 80s. Got into work, sat down in front of the machine I was working on (I'd had to buy my own stool...), started running tests and found that the middle 8 bits were permanently zero. Looked carefully and noticed that one of the three ALU cards was pulled out: that sort of thing really does focus ones mind on the interplay of hardware and software.

That predated bitslice, used some sort of weird (Fairchild?) logic with split-rail power (+4.75 -1.25?). Rebadged, and sometimes entire batches were found to be out-of-spec.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

TRon

  • Hero Member
  • *****
  • Posts: 3623
Re: Using the RTL's "Assignpipe" function
« Reply #8 on: July 21, 2024, 12:06:36 pm »
Can anyone point me to an example of using the RTL's "AssignPipe" function to establish two-way communications between two FPC programs (if that is even an appropriate use of the function)?  The following short example program from the RTL docs demonstrates the function, but only lets the program "talk to itself," which doesn't make much sense to me.  Why would one want to do this?
It is just an example though perhaps not one of the most innovative ones...

If you do a grep for assignpipe you can see for yourself that it is used in/for f.e. tprocess (CreatePipeHandles). It "attaches" two pipes.

Reason it exist ? Because setting pipes up manually using different handles can make a person's brain fry  :)
« Last Edit: July 21, 2024, 12:08:43 pm by TRon »
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

Thaddy

  • Hero Member
  • *****
  • Posts: 16169
  • Censorship about opinions does not belong here.
Re: Using the RTL's "Assignpipe" function
« Reply #9 on: July 21, 2024, 03:41:20 pm »
That is the same as calling covid a mild form of flue.
There is an excellent example in the manuals and it does not use assignpipes or whatever nonsense.
« Last Edit: July 21, 2024, 04:07:50 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 563
Re: Using the RTL's "Assignpipe" function
« Reply #10 on: July 21, 2024, 04:19:09 pm »
It is just an example though perhaps not one of the most innovative ones...

Thanks for the input.  All of the examples, from the docs, the forum or elsewhere on the internet are appreciated.  The problem is that I often lack the background to understand them.  No docs are going to fix that problem :)

I clearly need to take a crack at "grep," and made a start on that this morning.  (Noted that 1st release of it was 11/1973, so I'm clearly pretty far behind...) 

TRon

  • Hero Member
  • *****
  • Posts: 3623
Re: Using the RTL's "Assignpipe" function
« Reply #11 on: July 21, 2024, 05:09:34 pm »
Thanks for the input.  All of the examples, from the docs, the forum or elsewhere on the internet are appreciated.  The problem is that I often lack the background to understand them.  No docs are going to fix that problem :)
In case there is none then the only way you might get some indication of its usage is by looking through the source-code of FPC and/or Lazarus.

Quote
I clearly need to take a crack at "grep," and made a start on that this morning.  (Noted that 1st release of it was 11/1973, so I'm clearly pretty far behind...)
I don't know if you managed to catch one of my earlier replies about that but grep can be a bit daunting. In such case using a good filemanager (such as double commander, part of many if not all distro's these days) can be of help searching through the source-code (simple F3 in the found dialog to view and find the search text in the file).

This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 563
Re: Using the RTL's "Assignpipe" function
« Reply #12 on: July 21, 2024, 06:16:31 pm »
I don't know if you managed to catch one of my earlier replies about that but grep can be a bit daunting. In such case using a good filemanager (such as double commander, part of many if not all distro's these days) can be of help searching through the source-code (simple F3 in the found dialog to view and find the search text in the file).

Thanks for the suggestion.  I've downloaded double commander and am in the process of reading the docs.

(edit)
Oh yes, that is very nice.  It will take me a while to learn to use it, but not entirely unfamiliar as I've used bookmark commander on my firefox browser for a while.  Great!  Thanks again.
« Last Edit: July 21, 2024, 06:27:19 pm by Curt Carpenter »

TRon

  • Hero Member
  • *****
  • Posts: 3623
Re: Using the RTL's "Assignpipe" function
« Reply #13 on: July 22, 2024, 07:48:19 pm »
(edit)
Oh yes, that is very nice.  It will take me a while to learn to use it, but not entirely unfamiliar as I've used bookmark commander on my firefox browser for a while.  Great!  Thanks again.
Be advised that it is just a shameless plug of a nice tool written in Pascal (and by one of our fellow forum members).

It is not my intention to burden anyone with learning yet another tool. I am old school and am used to using a dual pane file manager ever since they saw the day of light.

You can ofc use any other file-manager that you are perhaps more comfortable with and that offers grepping (searching for text in in files) functionality. And I'm fairly positive there exist GUI wrappers exposing all grep command functionality as well.

Anyhows: The idea is to advertise that you can use such tools to your advantage in case not familiar with the command-line (grep in particular).

Happy coding !
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 563
Re: Using the RTL's "Assignpipe" function
« Reply #14 on: July 22, 2024, 08:30:13 pm »
Spent part of the morning reading the help info and using it to organize some of my files.  Very nice.

 

TinyPortal © 2005-2018