sbcl stuff

This commit is contained in:
Ian Keane 2020-01-20 14:13:08 -05:00
parent 1d1dbc34df
commit 5d91dbb667
335 changed files with 119806 additions and 1 deletions

View file

@ -0,0 +1,18 @@
ABCL provides a callback interface to java objects, next to these calls:
- ext:make-socket
- ext:socket-close
- ext:make-server-socket
- ext:socket-accept
- ext:get-socket-stream (returning an io-stream)
abcl-swank (see SLIME) shows how to call directly into java.
See for the sockets implementation:
- src/org/armedbear/lisp
* socket.lisp
* socket_stream.java
* SocketStream.java

View file

@ -0,0 +1,75 @@
-*- text -*-
A document to summarizing which API's of the different implementations
are associated with 'Step 1'.
Interface to be implemented in step 1:
- socket-connect
- socket-close
- get-host-by-address
- get-hosts-by-name
(and something to do with errors; maybe move this to step 1a?)
SBCL
====
sockets:
- socket-bind
- make-instance 'inet-socket
- socket-make-stream
- socket-connect (ip vector-quad) port
- socket-close
DNS name resolution:
- get-host-by-name
- get-host-by-address
- ::host-ent-addresses
- host-ent-name
CMUCL
=====
sockets:
- ext:connect-to-inet-socket (ip integer) port
- sys:make-fd-stream
- ext:close-socket
DNS name resolution:
- ext:host-entry-name
- ext::lookup-host-entry
- ext:host-entry-addr-list
- ext:lookup-host-entry
ABCL
====
sockets
- ext:socket-connect (hostname string) port
- ext:get-socket-stream
- ext:socket-close
clisp
=====
sockets
- socket-connect port (hostname string)
- close (socket)
Allegro
=======
sockets
- make-socket
- socket-connect
- close
DNS resolution
- lookup-hostname
- ipaddr-to-hostname

View file

@ -0,0 +1,73 @@
-*- text -*-
Step 2 of the master plan: Implementing (get-local-address sock) and
(get-peer-address sock).
Step 2 is about implementing:
(get-local-address sock) -> ip
(get-peer-address sock) -> ip
(get-local-port sock) -> port
(get-peer-port sock) -> port
(get-local-name sock) -> ip, port
(get-peer-name sock) -> ip, port
ABCL
====
FFI / J-calls to "getLocalAddress"+"getAddress", "getLocalPort" (local)
FFI / J-calls to "getInetAddress"+"getAddress", "getPort" (peer)
(see SLIME / swank-abcl.lisp for an example on how to do that)
Allegro
=======
(values (socket:remote-host sock)
(socket:remote-port)) -> 32bit ip, port
(values (socket:local-host sock)
(socket:local-port sock)) -> 32bit ip, port
CLISP
=====
(socket:socket-stream-local sock nil) -> address (as dotted quad), port
(socket:socket-stream-peer sock nil) -> address (as dotted quad), port
CMUCL
=====
(ext:get-peer-host-and-port sock-fd) -> 32-bit-addr, port (peer)
(ext:get-socket-host-and-port sock-fd) -> 32-bit-addr, port (local)
LispWorks
=========
(comm:socket-stream-address sock-stream) -> 32-bit-addr, port
or: (comm:get-socket-address sock) -> 32-bit-addr, port
(comm:socket-stream-peer-address sock-stream) -> 32-bit-addr, port
or: (comm:get-socket-peer-address sock) -> 32-bit-addr, port
OpenMCL
=======
(values (ccl:local-host sock) (ccl:local-port sock)) -> 32-bit ip, port
(values (ccl:remote-host sock) (ccl:remote-port sock)) -> 32-bit ip, port
SBCL
====
(sb-bsd-sockets:socket-name sock) -> vector-quad, port
(sb-bsd-sockets:socket-peer-name sock) -> vector-quad, port

View file

@ -0,0 +1,46 @@
(require :sock)
accept-connection (sock passive-socket) &key wait Generic function.
dotted-to-ipaddr dotted &key errorp Function.
ipaddr-to-dotted ipaddr &key values Function.
ipaddr-to-hostname ipaddr Function.
lookup-hostname hostname
lookup-port portname protocol Function.
make-socket &key type format address-family connect &allow-other-keys Function.
with-pending-connect &body body Macro.
receive-from (sock datagram-socket) size &key buffer extract Generic function.
send-to sock &key
shutdown sock &key direction
socket-control stream &key output-chunking output-chunking-eof input-chunking
socket-os-fd sock Generic function.
remote-host socket Generic function.
local-host socket Generic function.
local-port socket
remote-filename socket
local-filename socket
remote-port socket
socket-address-family socket
socket-connect socket
socket-format socket
socket-type socket
errors
:address-in-use Local socket address already in use
:address-not-available Local socket address not available
:network-down Network is down
:network-reset Network has been reset
:connection-aborted Connection aborted
:connection-reset Connection reset by peer
:no-buffer-space No buffer space
:shutdown Connection shut down
:connection-timed-out Connection timed out
:connection-refused Connection refused
:host-down Host is down
:host-unreachable Host is unreachable
:unknown Unknown error

View file

@ -0,0 +1,60 @@
-*- text -*-
$Id$
A document to describe which APIs a backend should implement.
Each backend should implement:
Functions:
- handle-condition
- socket-connect
- socket-listen
- get-hosts-by-name [ optional ]
- get-host-by-address [ optional ]
- wait-for-input-internal (new in 0.4.x)
Methods:
- socket-close
- socket-accept
- get-local-name
- get-peer-name
and - for ip sockets - these methods:
- get-local-address
- get-local-port
- get-peer-address
- get-peer-port
An error-handling function, resolving implementation specific errors
to this list of errors:
- address-in-use-error
- address-not-available-error
- bad-file-descriptor-error
- connection-refused-error
- invalid-argument-error
- no-buffers-error
- operation-not-supported-error
- operation-not-permitted-error
- protocol-not-supported-error
- socket-type-not-supported-error
- network-unreachable-error
- network-down-error
- network-reset-error
- host-down-error
- host-unreachable-error
- shutdown-error
- timeout-error
- unkown-error
and these conditions:
- interrupted-condition
- unkown-condition

View file

@ -0,0 +1,38 @@
http://clisp.cons.org/impnotes.html#socket
(SOCKET:SOCKET-SERVER &OPTIONAL [port-or-socket])
(SOCKET:SOCKET-SERVER-HOST socket-server)
(SOCKET:SOCKET-SERVER-PORT socket-server)
(SOCKET:SOCKET-WAIT socket-server &OPTIONAL [seconds [microseconds]])
(SOCKET:SOCKET-ACCEPT socket-server &KEY :ELEMENT-TYPE :EXTERNAL-FORMAT :BUFFERED :TIMEOUT)
(SOCKET:SOCKET-CONNECT port &OPTIONAL [host] &KEY :ELEMENT-TYPE :EXTERNAL-FORMAT :BUFFERED :TIMEOUT)
(SOCKET:SOCKET-STATUS socket-stream-or-list &OPTIONAL [seconds [microseconds]])
(SOCKET:SOCKET-STREAM-HOST socket-stream)
(SOCKET:SOCKET-STREAM-PORT socket-stream)
(SOCKET:SOCKET-SERVICE-PORT &OPTIONAL service-name (protocol "tcp"))
(SOCKET:SOCKET-STREAM-PEER socket-stream [do-not-resolve-p])
(SOCKET:SOCKET-STREAM-LOCAL socket-stream [do-not-resolve-p])
(SOCKET:SOCKET-STREAM-SHUTDOWN socket-stream direction)
(SOCKET:SOCKET-OPTIONS socket-server &REST {option}*)
(posix:resolve-host-ipaddr &optional host)
with the host-ent structure:
name - host name
aliases - LIST of aliases
addr-list - LIST of IPs as dotted quads (IPv4) or coloned octets (IPv6)
addrtype - INTEGER address type IPv4 or IPv6
Errors are of type
SYSTEM::SIMPLE-OS-ERROR
with a 1 element (integer) SYSTEM::$FORMAT-ARGUMENTS list
This integer stores the OS error reported; meaning WSA* codes on Win32
and E* codes on *nix, only: unix.lisp in CMUCL shows
BSD, Linux and SRV4 have different number assignments for the same
E* constant names :-(

View file

@ -0,0 +1,69 @@
http://cvs2.cons.org/ftp-area/cmucl/doc/cmu-user/internet.html
$Id$
extensions:lookup-host-entry host
[structure]
host-entry
name aliases addr-type addr-list
[Function]
extensions:create-inet-listener port &optional kind &key :reuse-address :backlog :interface
=> socket fd
[Function]
extensions:accept-tcp-connection unconnected
=> socket fd, address
[Function]
extensions:connect-to-inet-socket host port &optional kind
=> socket fd
[Function]
extensions:close-socket socket
[Private function]
extensions::get-peer-host-and-port socket-fd
[Private function]
extentsions::get-socket-host-and-port socket-fd
There's currently only 1 condition to be raised:
SOCKET-ERROR (derived from SIMPLE-ERROR)
which has a SOCKET-ERRNO slot containing the unix error number.
[Function]
extensions:add-oob-handler fd char handler
[Function]
extensions:remove-oob-handler fd char
[Function]
extensions:remove-all-oob-handlers fd
[Function]
extensions:send-character-out-of-band fd char
[Function]
extensions:create-inet-socket &optional type
=> socket fd
[Function]
extensions:get-socket-option socket level optname
[Function]
extensions:set-socket-option socket level optname optval
[Function]
extensions:ip-string addr

View file

@ -0,0 +1,136 @@
-*- text -*-
$Id$
usocket: Universal sockets library
==================================
Contents
========
* Motivation
* Design goal
* Functional requirements
* Class structure
Motivation
==========
There are 2 other portability sockets packages [that I know of]
out there:
1) trivial-sockets
2) acl-compat (which is a *lot* broader, but contains sockets too)
The first misses some functionality which is fundamental when
the requirements stop being 'trivial', such as finding out the
addresses of either side connected to the tcp/ip stream.
The second, being a complete compatibility library for Allegro,
contains much more than only sockets. Next to that, as the docs
say, is it mainly directed at providing the functionality required
to port portable-allegroserve - meaning it may be (very) incomplete
on some platforms.
So, that's why I decided to inherit Erik Enge's project to build
a library with the intention to provide portability code in only
1 area of programming, targeted at 'not so trivial' programming.
Also, I need this library to extend cl-irc with full DCC functionality.
Design goal
===========
To provide a portable TCP/IP socket interface for as many
implementations as possible, while keeping the portability layer
as thin as possible.
Functional requirements
=======================
The interface provided should allow:
- 'client'/active sockets
- 'server'/listening sockets
- provide the usual stream methods to operate on the connection stream
(not necessarily the socket itself; maybe a socket slot too)
For now, as long as there are no possibilities to have UDP sockets
to write a DNS client library: (which in the end may work better,
because in this respect all implementations are different...)
- retrieve IP addresses/ports for both sides of the connection
Several relevant support functionalities will have to be provided too:
- long <-> quad-vector operators
- quad-vector <-> string operators
- hostname <-> quad-vector operators (hostname resolution)
Minimally, I'd like to support:
- SBCL
- CMUCL
- ABCL (ArmedBear)
- clisp
- Allegro
- LispWorks
- OpenMCL
Comments on the design above
============================
I don't think it's a good idea to implement name lookup in the
very first of steps: we'll see if this is required to get the
package accepted; not all implementations support it.
Name resolution errors ...
Since there is no name resolution library (yet), nor standardized
hooks into the standard C library to do it the same way on
all platforms, name resolution errors can manifest themselves
in a lot of different ways. How to marshall these to the
library users?
Several solutions come to mind:
1) Map them to 'unknown-error
2) Give them their own errors and map to those
... which implies that they are actually supported atm.
3) ...
Given that the library doesn't now, but may in the future,
include name resolution officially, I tend to think (1) is the
right answer: it leaves it all undecided.
These errors can be raised by the nameresolution service
(netdb.h) as values for 'int h_errno':
- HOST_NOT_FOUND (1)
- TRY_AGAIN (2) /* Server fail or non-authoritive Host not found */
- NO_RECOVERY (3) /* Failed permanently */
- NO_DATA (4) /* Valid address, no data for requested record */
int *__h_errno_location(void) points to thread local h_errno on
threaded glibc2 systems.
Class structure
===============
usocket
|
+- datagram-usocket
+- stream-usocket
\- stream-server-usocket
The usocket class will have methods to query local properties, such
as:
- get-local-name: to query to which interface the socket is bound
- <other socket and protocol options such as SO_REUSEADDRESS>

View file

@ -0,0 +1,20 @@
EADDRINUSE 48 address-in-use-error
EADDRNOTAVAIL 49 address-not-available-error
EAGAIN interrupted-error ;; not 1 error code: bsd == 11; non-bsd == 35
EBADF 9 bad-file-descriptor-error
ECONNREFUSED 61 connection-refused-error
EINTR 4 interrupted-error
EINVAL 22 invalid-argument-error
ENOBUFS 55 no-buffers-error
ENOMEM 12 out-of-memory-error
EOPNOTSUPP 45 operation-not-supported-error
EPERM 1 operation-not-permitted-error
EPROTONOSUPPORT 43 protocol-not-supported-error
ESOCKTNOSUPPORT 44 socket-type-not-supported-error
ENETUNREACH 51 network-unreachable-error
ENETDOWN 50 network-down-error
ENETRESET 52 network-reset-error
ESHUTDOWN 58 already-shutdown-error
ETIMEDOUT 60 connection-timeout-error
EHOSTDOWN 64 host-down-error
EHOSTUNREACH 65 host-unreachable-error

View file

@ -0,0 +1,41 @@
$Id$
http://www.lispworks.com/reference/lwu41/lwref/LWRM_37.HTM
Package: COMM
ip-address-string
socket-stream-address
socket-stream-peer-address
start-up-server
start-up-server-and-mp
string-ip-address
with-noticed-socket-stream
Needed components for usocket:
comm::get-fd-from-socket socket-fd
=> socket-fd
comm::accept-connection-to-socket socket-fd
=> socket-fd
comm::close-socket
comm::create-tcp-socket-for-service
=> socket-fd
open-tcp-stream peer-host peer-port &key direction element-type
=> socket-stream
get-host-entry (see http://www.lispworks.com/documentation/lw445/LWRM/html/lwref-30.htm#pgfId-897837)
get-socket-address
get-socket-peer-address
=> address, port
socket-stream socket-fd
=> stream
socket socket-stream (guessed from http://www.lispworks.com/documentation/lw445/LWRM/html/lwref-43.htm)
=> socket-fd

View file

@ -0,0 +1,27 @@
http://openmcl.clozure.com/Doc/sockets.html
make-socket [Function]
accept-connection [Function]
dotted-to-ipaddr [Function]
ipaddr-to-dotted [Function]
ipaddr-to-hostname [Function]
lookup-hostname [Function]
lookup-port [Function]
receive-from [Function]
send-to [Function]
shutdown [Function]
socket-os-fd [Function]
remote-port [Function]
local-host [Function]
local-port [Function]
socket-address-family [Function]
socket-connect [Function]
socket-format [Function]
socket-type [Function]
socket-error [Class]
socket-error-code [Function]
socket-error-identifier [Function]
socket-error-situation [Function]
close [method]

View file

@ -0,0 +1,114 @@
http://www.xach.com/sbcl/sb-bsd-sockets.html
$Id$
package: sb-bsd-sockets
class: socket
slots:
* file-descriptor :
* family :
* protocol :
* type :
* stream :
operators:
(socket-bind (s socket) &rest address) Generic Function
(socket-accept (socket socket)) Method
(socket-connect (s socket) &rest address) Generic Function
(socket-peername (socket socket)) Method
(socket-name (socket socket)) Method
(socket-receive (socket socket) buffer length &key oob peek waitall (element-type 'character)) Method
(socket-listen (socket socket) backlog) Method
(socket-close (socket socket)) Method
(socket-make-stream (socket socket) &rest args) Method
(sockopt-reuse-address (socket socket) argument) Accessor
(sockopt-keep-alive (socket socket) argument) Accessor
(sockopt-oob-inline (socket socket) argument) Accessor
(sockopt-bsd-compatible (socket socket) argument) Accessor
(sockopt-pass-credentials (socket socket) argument) Accessor
(sockopt-debug (socket socket) argument) Accessor
(sockopt-dont-route (socket socket) argument) Accessor
(sockopt-broadcast (socket socket) argument) Accessor
(sockopt-tcp-nodelay (socket socket) argument) Accessor
inet-domain sockets
class: inet-socket
slots:
* family :
operators:
(make-inet-address dotted-quads) Function
(get-protocol-by-name name) Function
(make-inet-socket type protocol) Function
file-domain sockets
class: unix-socket
slots:
* family :
class: host-ent
Slots:
* name :
* aliases :
* address-type :
* addresses :
(host-ent-address (host-ent host-ent)) Method
(get-host-by-name host-name) Function
(get-host-by-address address) Function
(name-service-error where) Function
(non-blocking-mode (socket socket)) Method
(define-socket-condition sockint::EADDRINUSE address-in-use-error)
(define-socket-condition sockint::EAGAIN interrupted-error)
(define-socket-condition sockint::EBADF bad-file-descriptor-error)
(define-socket-condition sockint::ECONNREFUSED connection-refused-error)
(define-socket-condition sockint::EINTR interrupted-error)
(define-socket-condition sockint::EINVAL invalid-argument-error)
(define-socket-condition sockint::ENOBUFS no-buffers-error)
(define-socket-condition sockint::ENOMEM out-of-memory-error)
(define-socket-condition sockint::EOPNOTSUPP operation-not-supported-error)
(define-socket-condition sockint::EPERM operation-not-permitted-error)
(define-socket-condition sockint::EPROTONOSUPPORT protocol-not-supported-error)
(define-socket-condition sockint::ESOCKTNOSUPPORT socket-type-not-supported-error)
(define-socket-condition sockint::ENETUNREACH network-unreachable-error)
Exported errors:
* (apropos "ERROR" :sb-bsd-sockets)
SB-BSD-SOCKETS:INTERRUPTED-ERROR
SB-BSD-SOCKETS:TRY-AGAIN-ERROR
* SB-BSD-SOCKETS:NO-RECOVERY-ERROR (EFAIL?)
SB-BSD-SOCKETS:CONNECTION-REFUSED-ERROR
SB-BSD-SOCKETS:INVALID-ARGUMENT-ERROR
* SB-BSD-SOCKETS:HOST-NOT-FOUND-ERROR
SB-BSD-SOCKETS:OPERATION-NOT-PERMITTED-ERROR
SB-BSD-SOCKETS:OPERATION-NOT-SUPPORTED-ERROR
SB-BSD-SOCKETS:PROTOCOL-NOT-SUPPORTED-ERROR
SB-BSD-SOCKETS:OPERATION-TIMEOUT-ERROR
SB-BSD-SOCKETS:SOCKET-TYPE-NOT-SUPPORTED-ERROR
SB-BSD-SOCKETS:NO-BUFFERS-ERROR
SB-BSD-SOCKETS:NETWORK-UNREACHABLE-ERROR
SB-BSD-SOCKETS:BAD-FILE-DESCRIPTOR-ERROR
SB-BSD-SOCKETS:ADDRESS-IN-USE-ERROR
SB-BSD-SOCKETS:OUT-OF-MEMORY-ERROR
And 1 non-exported error:
SB-BSD-SOCKETS::NO-ADDRESS-ERROR
*-ed errors aren't yet addressed in the errorlist supported by usocket

View file

@ -0,0 +1,28 @@
Package:
clisp : socket
cmucl : extensions
sbcl : sb-bsd-sockets
lw : comm
openmcl: openmcl-socket
allegro: sock
Connecting (TCP/inet only)
clisp : socket-connect port &optional [host] &key :element-type :external-format :buffered :timeout = > socket-stream
cmucl : connect-to-inet-socket host port &optional kind => file descriptor
sbcl : sb-socket-connect socket &rest address => socket
lw : open-tcp-stream hostname service &key direction element-type buffered => stream-object
openmcl: socket-connect socket => :active, :passive or nil
allegro: make-socket (&rest args &key type format connect address-family eol) => socket
Closing
clisp : close socket
cmucl : close-socket socket
sbcl : socket-close socket
lw : close socket
openmcl: close socket
allegro: close socket
Errors