Date : Thu, 23 Jul 2009 01:50:12 +0100
From : jgh@... (Jonathan Graham Harston)
Subject: RFC: BBC Ethernet API
Request For Comments - Proposed BBC Ethernet API
------------------------------------------------
In discussing "BBC Ethernet interface", on 10 Jul 2009 Sprow wrote:
> What's missing at the moment (aside from me not having an NFS server
> to test on) is any kind of API to allow users such as yourself to talk
> to the network. [...] I guess the simplest thing to do would be present
> a BSD-a-like sockets interface via OSWord or something similar.
I present here a proposal for an OSWORD Ethernet access call. Having
examined the BSD sockets library and the RISC OS Sockets documentation it is
clear that the calls have a fairly uniform interface. Parameters passed to
calls are almost always: socket, address, length, flags, remote_address,
remote_length. This makes it fairly easy to translate to an OSWORD
interface. I propose the following:
On entry: A%=192, X%=control block, Y%=X%DIV256
X%?0 = OSWORD send block length
X%?1 = OSWORD receive block length
X%?2 = command - same as RISC OS SWI Socket_ command number
X%?3 = 0
X%!4 = socket
X%!8 = address
X%!12 = length
X%!16 = flags
X%!20 = address
X%!24 = address length
On exit: X%?3 = 0 for OK, <>0 for error
X%!4 onwards = any returned parameters
Memory pointed to by X%!8 on entry may be modified
Commands passed in X%?2 are those in the RISC OS Socket_ SWIs, that is:
&00 Socket_Creat X%!4=domain, X%!8=type, X%!12=protocol
&01 Socket_Bind X%!4=sock, X%!8=name, X%!12=namelen
&02 Socket_Listen X%!4=sock, X%!8=backlog
&03 Socket_Accept X%!4=sock, X%!8=addr, X%!12=len
&04 Socket_Connect X%!4=sock, X%!8=name, X%!12=namelen
&05 Socket_Recv X%!4=sock, X%!8=buf, X%!12=len, X%!16=flags
&06 Socket_Recvfrom X%!4=sock, X%!8=buf, X%!12=len, X%!16=flags,
X%!20=from, X%!24=fromlen
&07 Socket_Recvmsg X%!4=sock, X%!8=msg, X%!12=flags
&08 Socket_Send X%!4=sock, X%!8=msg, X%!12=len, X%!16=flags
&09 Socket_Sendto X%!4=sock, X%!8=msg, X%!12=len, X%!16=flags,
X%!20=to, X%!24=tolen
&0A Socket_Sendmsg X%!4=sock, X%!8=msg, X%!12=flags
&0B Socket_Shutdown X%!4=sock, X%!8=how
&0C Socket_Setsockopt X%!4=sock, X%!8=level, X%!12=optname, X%!16=optval,
X%!20=optlen
&0D Socket_Getsockopt X%!4=sock, X%!8=level, X%!12=optname, X%!16=optval,
X%!20=optlen
&0E Socket_Getpeername X%!4=sock, X%!8=name, X%!12=namelen
&0F Socket_Getsockname X%!4=sock, X%!8=name, X%!12=namelen
&10 Socket_Close X%!4=sock
&11 Socket_Select X%!4=nfds, X%!8=readfds, X%!12=writefds,
X%!16=exceptfds, X%!20=timeout
&12 Socket_Ioctl X%!4=sock, X%!8=request, X%!12=argp
&13 Socket_Read X%!4=sock, X%!8=buf, X%!12=num
&14 Socket_Write X%!4=sock, X%!8=buf, X%!12=num
&15 Socket_Stat X%!4=sock, X%!8=buf
&16 Socket_Readv X%!4=sock, X%!8=iov, X%!12=iovcnt
&17 Socket_Writev X%!4=sock, X%!8=iov, X%!12=iovcnt
Calls can be put in BASIC veneers in the following manner:
DEFFNSocket_Open(X%!4, X%!8):!X%=&2020:A%=192:CALL &FFF1:=X%!4
DEFFNSocket_Listen(X%!4, X%!8):!X%=&2020:X%?2=2:A%=192:CALL &FFF1:=X%?3
DEFFNSocket_Connect(X%!4, X%!8, X%!12):!X%=&2020:X%?2=4:A%=192:CALL
&FFF1:=X%?3
and called with code similar to:
sock%=FNSocket_Open(domain%, type%, protocol%)
A%=FNSocket_Listen(sock%, buflen):IF A%:PROCSocket_Error(A%):END
A%=FNSocket_Read(sock%, buffer, buflen):IF A%:PROCSocket_Error(A%):END
--
J.G.Harston - jgh@... - mdfs.net/User/JGH
BBC BASIC for Windows and Internationalisation
See http://mdfs.net/Software/BBCBasic/Windows/ProgTips