Q: SuperBASIC net driver semantics

Anything QL Software or Programming Related.
Post Reply
User avatar
ppe
Trump Card
Posts: 171
Joined: Tue Dec 14, 2010 10:48 am
Location: Espoo, Finland

Q: SuperBASIC net driver semantics

Post by ppe »

Hello everyone,

I would appreciate some feedback and ideas from SuperBASIC programmers. I'm continuing work on my W5300 based ethernet card driver for a black box QL. The driver currently supports TCP_ channels and SuperBASIC OPEN, CLOSE, PRINT, INKEY$ and INPUT keywords. Syntax of the driver string is currently "TCP_<host>:<port>". This is enough for most TCP client software, and in fact Tim and Dilwyn's SuperBASIC IRC client runs nicely already (also when QLiberated). I'm currently in the process of adding UDP support so that e.g. NTP client is easy to write in SuperBASIC.

Next thing on my to-implement list is socket listen functionality. This will enable QL-to-QL communications, or some simple server software (e.g. HTTP shoutbox) to be implemented easily.

I would appreciate some insight on what would be a semantically coherent approach to defining a listening TCP socket from SuperBASIC. For listening, the remote host is obviously not required, but the port on which the socket should listen must be specified. Some approaches I have considered so far:

Code: Select all

OPEN #chan,"TCP_:<listen-port>"

The missing host part would imply a listening socket

Code: Select all

OPEN #channel,"TCP_":SOCK_LISTEN (#channel,port)
An open without any host:port specification would open a channel and a separate new SOCK_LISTEN keyword would set it in listen mode and specify the port

Code: Select all

OPEN "TCPL_<port>"
A separate device identifier for listening sockets

I would really appreciate if you could take a minute to consider what would be the most "SuperBASIC-y" way of doing this. Feedback and opinions on changes / new approaches is welcome.

Kind regards,
Petri


User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Q: SuperBASIC net driver semantics

Post by tofro »

Petri,

I don't think it's enough to look at a "SuperBASIC"y implementation. It makes sense to look into other languages (most importantly, C, as this already has a socket implementation).

the original QL (uqlx) socket implementation used the access key in the open call to denote you want to open a server socket. IO_NEW (2) as in "Open new (exclusive) File" was intended to be used for server sockets that are not used for data transfer, but rather only for accept()ing connections. That boils down to using the S*BASIC keyword OPEN_NEW for such sockets, host and port # would then denote the port to listen to. (translated into UNIX terminology, an OPEN_NEW of a TCP socket with a port number only (or your own IP address, or an IP address of 0.0.0.0) covers both the socket() and the bind() system call).

accept() is implemented via IO.OPEN as well, and here is where things are getting a bit wierd in the uqlx implementation: You are expected to open a generic socket ("SCK_") and pass in the accepting socket's channel ID in the access key register (d3, normally used for NEW, OVERWRITE, SHARED, DIRECTORY,.... but obviously with much higher values here). That is obviously not possible from standard S*BASIC, so would need a new implementation. The open call would then return the new socket channel. (That's exactly how the C68 socket implementation talks to the uqlx network driver).


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
XorA
Site Admin
Posts: 1358
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Re: Q: SuperBASIC net driver semantics

Post by XorA »

According to the docs its SCK_


User avatar
ppe
Trump Card
Posts: 171
Joined: Tue Dec 14, 2010 10:48 am
Location: Espoo, Finland

Re: Q: SuperBASIC net driver semantics

Post by ppe »

Thank you tofro, this is very helpful! Yes, I'm hoping to support the C socket library at one point but tackling SuperBASIC first whilst keeping the library compatibility on the device drvier layer in mind. OPEN_NEW semantics sounds straightforward enough. Being compatible with uqlx semantics is definitely desirable.

So, using the Open Type Key solves half of the problem and then I just need to create a new function

Code: Select all

new_chan = SOCK_ACCEPT(#chan)
This would make it easy to use from S*BASIC. And using QLiberator one could then spawn a job per sock_accept to handle the per-client communications.


Martin_Head
Aurora
Posts: 847
Joined: Tue Dec 17, 2013 1:17 pm

Re: Q: SuperBASIC net driver semantics

Post by Martin_Head »

You might want to check out IP_Basic, here http://www.dilwyn.me.uk/internet/index.html It adds a bunch of SuperBASIC commands like IP_BIND, IP_LISTEN and IP_ACCEPT. The source code is supplied, so you may be able to bend it to do what you want.

I have a later unreleased version than the one on Dilwyn's site. Mostly bug fixes.


User avatar
ppe
Trump Card
Posts: 171
Joined: Tue Dec 14, 2010 10:48 am
Location: Espoo, Finland

Re: Q: SuperBASIC net driver semantics

Post by ppe »

Martin_Head wrote:You might want to check out IP_Basic, here http://www.dilwyn.me.uk/internet/index.html It adds a bunch of SuperBASIC commands like IP_BIND, IP_LISTEN and IP_ACCEPT. The source code is supplied, so you may be able to bend it to do what you want.

I have a later unreleased version than the one on Dilwyn's site. Mostly bug fixes.
Thank you Martin for bringing this to my attention, good thing there may be no need to reinvent the wheel! I have no idea how I missed that package on Dilwyn's site... I'll take a look - will probably be interested in the later version, too... :)

Cheers!
Petri


Martin_Head
Aurora
Posts: 847
Joined: Tue Dec 17, 2013 1:17 pm

Re: Q: SuperBASIC net driver semantics

Post by Martin_Head »

ppe wrote:
Martin_Head wrote:You might want to check out IP_Basic, here http://www.dilwyn.me.uk/internet/index.html It adds a bunch of SuperBASIC commands like IP_BIND, IP_LISTEN and IP_ACCEPT. The source code is supplied, so you may be able to bend it to do what you want.

I have a later unreleased version than the one on Dilwyn's site. Mostly bug fixes.
Thank you Martin for bringing this to my attention, good thing there may be no need to reinvent the wheel! I have no idea how I missed that package on Dilwyn's site... I'll take a look - will probably be interested in the later version, too... :)

Cheers!
Petri
Here's an unreleased update to IPBasic (Version 1.05)

In the summer of 2019 I did some bug fixes, and liaised with the emulator writers to fix some bugs and inconsistences in their implementations of the IP device driver.

I had been sitting on this update waiting for the emulator writers to release updates. So I could test it, and finish the documentation.

However I started working on the Q68 Ethernet driver, and I have not had the time to test and finish the update.

So you may find some problems.

I have also included an unfinished copy of my QDOS TCP/IP booklet, which I was doing at the same time as it tied into the fixes the Emulator writers were doing.
Attachments
QDOS TCP 2019_09_27.zip
(56.09 KiB) Downloaded 56 times
IPBasic105.zip
(79.96 KiB) Downloaded 58 times


User avatar
ppe
Trump Card
Posts: 171
Joined: Tue Dec 14, 2010 10:48 am
Location: Espoo, Finland

Re: Q: SuperBASIC net driver semantics

Post by ppe »

Martin_Head wrote: Here's an unreleased update to IPBasic (Version 1.05)
I have also included an unfinished copy of my QDOS TCP/IP booklet, which I was doing at the same time as it tied into the fixes the Emulator writers were doing.
Many thanks Martin, very kind of you! And amazing work on the documentation, by the way!


Post Reply