aboutsummaryrefslogtreecommitdiffstats
path: root/Lisp/moxie/compat
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2008-04-02 19:20:20 -0400
committerBrian Cully <bjc@kublai.com>2008-04-02 19:20:20 -0400
commitab10720260e2c184b319026da89f4dfd338500bb (patch)
treea692a27435da0296972e43b21b2f35762e720bfd /Lisp/moxie/compat
downloadmoxie-ab10720260e2c184b319026da89f4dfd338500bb.tar.gz
moxie-ab10720260e2c184b319026da89f4dfd338500bb.zip
Initial commit
Diffstat (limited to 'Lisp/moxie/compat')
-rw-r--r--Lisp/moxie/compat/compat-clisp.lib17
-rw-r--r--Lisp/moxie/compat/compat-clisp.lisp24
-rw-r--r--Lisp/moxie/compat/compat-openmcl.lisp59
-rw-r--r--Lisp/moxie/compat/compat-sbcl.faslbin0 -> 16205 bytes
-rw-r--r--Lisp/moxie/compat/compat-sbcl.lisp49
5 files changed, 149 insertions, 0 deletions
diff --git a/Lisp/moxie/compat/compat-clisp.lib b/Lisp/moxie/compat/compat-clisp.lib
new file mode 100644
index 0000000..6d4ac37
--- /dev/null
+++ b/Lisp/moxie/compat/compat-clisp.lib
@@ -0,0 +1,17 @@
+#0Y UTF-8
+(COMMON-LISP::SETQ COMMON-LISP::*PACKAGE* (SYSTEM::%FIND-PACKAGE "MOXIE"))
+(SYSTEM::C-DEFUN 'MOXIE::MAKE-RESULT-STREAM
+ (SYSTEM::LAMBDA-LIST-TO-SIGNATURE 'COMMON-LISP::NIL))
+(SYSTEM::C-DEFUN 'MOXIE::COERCE-INET-ADDRESS-DESIGNATOR
+ (SYSTEM::LAMBDA-LIST-TO-SIGNATURE '(MOXIE::HOST)))
+(SYSTEM::C-DEFUN 'MOXIE::OPEN-CONNECTION
+ (SYSTEM::LAMBDA-LIST-TO-SIGNATURE
+ '(MOXIE::HOST MOXIE::PORT COMMON-LISP::&KEY (MOXIE::BUFFERING :FULL))))
+(SYSTEM::C-DEFUN 'MOXIE::CLOSE-CONNECTION
+ (SYSTEM::LAMBDA-LIST-TO-SIGNATURE '(COMMON-LISP::STREAM)))
+(SYSTEM::C-DEFUN 'MOXIE::ADD-INPUT-HANDLER
+ (SYSTEM::LAMBDA-LIST-TO-SIGNATURE '(COMMON-LISP::STREAM MOXIE::HANDLER)))
+(SYSTEM::C-DEFUN 'MOXIE::REMOVE-INPUT-HANDLER
+ (SYSTEM::LAMBDA-LIST-TO-SIGNATURE '(MOXIE::HANDLER)))
+(SYSTEM::C-DEFUN 'MOXIE::SAVE-LISP-AND-DIE
+ (SYSTEM::LAMBDA-LIST-TO-SIGNATURE '(MOXIE::PATH)))
diff --git a/Lisp/moxie/compat/compat-clisp.lisp b/Lisp/moxie/compat/compat-clisp.lisp
new file mode 100644
index 0000000..160d193
--- /dev/null
+++ b/Lisp/moxie/compat/compat-clisp.lisp
@@ -0,0 +1,24 @@
+;;; -*- Lisp -*-
+;; $Id: compat-clisp.lisp 40 2006-01-02 03:35:07Z bjc $
+(in-package :moxie)
+
+(defun make-result-stream ()
+ (ext:make-stream 3 :direction :output))
+
+(defun coerce-inet-address-designator (host)
+ "Coerce HOST into an addess vector.")
+
+(defun open-connection (host port &key (buffering :full))
+ "Opens a connection to HOST:PORT, returning a STREAM if successful, NIL otherwise.")
+
+(defun close-connection (stream)
+ "Closes STREAM.")
+
+(defun add-input-handler (stream handler)
+ "Adds HANDLER to the input handler list on SOCKET.")
+
+(defun remove-input-handler (handler))
+
+(defun save-lisp-and-die (path)
+ (ext:saveinitmem path)
+ (ext:quit))
diff --git a/Lisp/moxie/compat/compat-openmcl.lisp b/Lisp/moxie/compat/compat-openmcl.lisp
new file mode 100644
index 0000000..6bafbd7
--- /dev/null
+++ b/Lisp/moxie/compat/compat-openmcl.lisp
@@ -0,0 +1,59 @@
+;;; -*- Lisp -*-
+;; $Id: compat-openmcl.lisp 36 2006-01-01 20:47:40Z bjc $
+(in-package :moxie)
+
+(defvar *stream-to-process* (make-hash-table))
+(defvar *stream-to-handler* (make-hash-table))
+
+(defmacro with-thread (thread &body body)
+ `(ccl:process-interrupt ,thread
+ (lambda ()
+ ,@body)))
+
+(defun make-result-stream ()
+ (ccl::make-fd-stream 3 :direction :output))
+
+(defun coerce-inet-address-designator (host)
+ "Coerce HOST into an addess vector."
+ (or (and (integerp host) host)
+ (ccl:dotted-to-ipaddr host :errorp nil)
+ (ignore-errors (ccl:lookup-hostname host))))
+
+(defun open-connection-thread (parent stream)
+ (ccl:socket-connect stream)
+ (loop
+ (ccl:process-input-wait (ccl:stream-device stream :input))
+ (let ((handler (gethash stream *stream-to-handler*)))
+ (with-thread parent
+ (funcall handler stream)))))
+
+(defun open-connection (host port &rest args)
+ "Opens a connection to HOST:PORT, returning a STREAM if successful, NIL otherwise."
+ (declare (ignore args))
+ (let ((s (ccl:make-socket :address-family :internet :type :stream :connect :active
+ :remote-host (coerce-inet-address-designator host)
+ :remote-port port)))
+ (setf (gethash s *stream-to-process*)
+ (ccl:process-run-function (format nil "Connection to ~A:~A" host port)
+ #'open-connection-thread
+ ccl:*current-process* s))
+ s))
+
+(defun close-connection (stream)
+ "Closes STREAM."
+ (ignore-errors
+ (close stream)
+ (ccl:process-kill (gethash stream *stream-to-process*))
+ (remove-input-handler stream)
+ (remhash stream *stream-to-process*)))
+
+(defun add-input-handler (stream handler)
+ "Adds HANDLER to the input handler list on STREAM."
+ (setf (gethash stream *stream-to-handler*) handler))
+
+(defun remove-input-handler (stream)
+ "Removes all handlers from STREAM."
+ (remhash stream *stream-to-handler*))
+
+(defun save-lisp-and-die (path)
+ (ccl:save-application path)) \ No newline at end of file
diff --git a/Lisp/moxie/compat/compat-sbcl.fasl b/Lisp/moxie/compat/compat-sbcl.fasl
new file mode 100644
index 0000000..d1e2b41
--- /dev/null
+++ b/Lisp/moxie/compat/compat-sbcl.fasl
Binary files differ
diff --git a/Lisp/moxie/compat/compat-sbcl.lisp b/Lisp/moxie/compat/compat-sbcl.lisp
new file mode 100644
index 0000000..bb43bc8
--- /dev/null
+++ b/Lisp/moxie/compat/compat-sbcl.lisp
@@ -0,0 +1,49 @@
+;;; -*- Lisp -*-
+;; $Id: compat-sbcl.lisp 36 2006-01-01 20:47:40Z bjc $
+(in-package :moxie)
+
+(defvar *stream-to-handler* (make-hash-table))
+(defvar *stream-to-socket* (make-hash-table))
+
+(defun make-result-stream ()
+ (sb-sys:make-fd-stream 3 :output t))
+
+(defun coerce-inet-address-designator (host)
+ "Coerce HOST into an addess vector."
+ (cond ((typep host '(vector (unsigned-byte 8) 4)) host)
+ ((some #'alpha-char-p host) (sb-bsd-sockets:host-ent-address
+ (sb-bsd-sockets:get-host-by-name host)))
+ (t (sb-bsd-sockets:make-inet-address host))))
+
+(defun open-connection (host port &key (buffering :full))
+ "Opens a connection to HOST:PORT, returning a STREAM if successful, NIL otherwise."
+ (let ((socket (make-instance 'sb-bsd-sockets:inet-socket :type :stream
+ :protocol :tcp)))
+ (sb-bsd-sockets:socket-connect socket (coerce-inet-address-designator host) port)
+ (let ((stream (sb-bsd-sockets:socket-make-stream socket
+ :input t :output t :buffering buffering)))
+ (setf (gethash stream *stream-to-socket*) socket)
+ stream)))
+
+(defun close-connection (stream)
+ "Closes STREAM."
+ (ignore-errors
+ (remove-input-handler stream)
+ (remhash stream *stream-to-socket*)
+ (close stream)))
+
+(defun add-input-handler (stream handler)
+ "Adds HANDLER to the input handler list on SOCKET."
+ (setf (gethash stream *stream-to-handler*)
+ (sb-sys:add-fd-handler (sb-bsd-sockets:socket-file-descriptor (gethash stream *stream-to-socket*))
+ :input
+ (lambda (fd)
+ (declare (ignore fd))
+ (funcall handler stream)))))
+
+(defun remove-input-handler (stream)
+ (awhen (gethash stream *stream-to-handler*)
+ (sb-sys:remove-fd-handler it)))
+
+(defun save-lisp-and-die (path)
+ (sb-ext:save-lisp-and-die path)) \ No newline at end of file