Feature #1236
Add "socket" devices
Description
Kreuzer wants "socket" devices as in CoCoA-4 so that ApCoCoA can be easily ported to CoCoA-5.
I see two parts:
(1) a function to create a socket device (ought to be easy with BOOST ASIO)
(2) a function to read from a device (previously CoCoA-4 used source
).
Related issues
History
#1 Updated by John Abbott over 5 years ago
I think creating the device should be fairly easy: BOOST ASIO sublibrary already has a nice classboost::asio::ip::tcp::iostream
Reading from a socket-stream is trickier. In CoCoA-5 the source
comand can be used only at top-level.
A simple first solution would be to implement something like GetLine
which reads a string value.
However we might typically want to read several lines...
#2 Updated by John Abbott over 5 years ago
The interpreter has a way of representing OSTREAM
but nothing for input-streams or input+output-streams.
- replace
OSTREAM
byIOSTREAM
which decides at run time whether it is IN, OUT or IN+OUT - add new classes for
ISTREAM
andIOSTREAM
The first approach appears to be simpler: just change 1 class, rather than add 2 new classes.
Note that for us a socket is IN+OUT; a file could be any of IN, OUT or IN+OUT (but perhaps
IN+OUT is ill-advised?)
#3 Updated by John Abbott about 5 years ago
- Status changed from New to In Progress
- Assignee set to John Abbott
- Target version changed from CoCoA-5.?.? to CoCoA-5.3.0
- % Done changed from 0 to 20
I have opted for the following design in the first impl:OpenSocket
creates a RECORD
with two fields send
and recv
.send
has type <out-stream>
, while recv
has type <in-stream>
.
Some simple tests pass. Doc not yet updated. Ange is testing.
#4 Updated by John Abbott about 5 years ago
I have used the BOOST "asio" library. On my machine compilation requires the linking flag -lpthread
#5 Updated by Anna Maria Bigatti about 5 years ago
OK, I'll test it on Mac when you are in Genova
#6 Updated by John Abbott about 5 years ago
I have updated the CoCoA-5 manual.
I have modified the code so that OpenSocket
returns a record with 4 fields: send
and recv
as mentioned above, and host
and port
for the hostname and port number respectively (this could be useful during debugging).
At the moment I have not mentioned the fields host
and port
in the documentation.
Should I? Are these field names good? Perhaps HostName
and PortNum
are better?
#7 Updated by John Abbott about 5 years ago
- Status changed from In Progress to Feedback
- % Done changed from 20 to 90
- Estimated time set to 9.90 h
Anna prefers the longer field names. Code cleaned, and checked-in. Anna will test.
Doc updated.
#8 Updated by John Abbott about 5 years ago
- Related to Support #1240: John's visit Feb 2019 added
#9 Updated by John Abbott over 4 years ago
It would be good to close this soon.
We should test it on the 3 usual platforms: GNU/Linux seems OK to me, Mac? Microsoft?
#10 Updated by John Abbott about 4 years ago
I have made the manual entry better (I hope!)
#11 Updated by John Abbott about 4 years ago
- Status changed from Feedback to Closed
- % Done changed from 90 to 100
I have just tested, and slightly modified the manual.
Closing.