r5253: *** empty log message ***
[cl-modlisp.git] / compat.lisp
index e7151214c9f3e3b9fca1aac27a5359d61cd9b7d6..e76b7ff49cdb1d5ff5116a592d46e95d18326928 100644 (file)
@@ -1,5 +1,5 @@
 ;;; -*- Syntax: Ansi-Common-Lisp; Base: 10; Mode: lisp; Package: clit -*-
-;;; $Id: compat.lisp,v 1.2 2003/07/08 08:34:22 kevin Exp $
+;;; $Id: compat.lisp,v 1.3 2003/07/08 12:10:16 kevin Exp $
 
 (in-package #:modlisp)
 
 
 #+lispworks
 (progn
-  (defclass socket ()
+  
+(define-condition lw-stream-error (error)
+  ((stream :initarg :stream
+           :reader stream-error-stream)
+   (action :initarg :action
+           :reader stream-error-action)
+   (code :initarg :code
+         :reader stream-error-code)
+   (identifier :initarg :identifier
+               :reader stream-error-identifier))
+  (:report (lambda (condition stream)
+             (format stream "A stream error occured (action=~A identifier=~A code=~A stream=~S)."
+                     (stream-error-action condition)
+                     (stream-error-identifier condition)
+                     (stream-error-code condition)
+                     (stream-error-stream condition)))))
+
+(define-condition socket-error (lw-stream-error)
+  ()
+  (:report (lambda (condition stream)
+             (format stream "A socket error occured (action=~A identifier=~A code=~A stream=~S)."
+                     (stream-error-action condition)
+                     (stream-error-identifier condition)
+                     (stream-error-code condition)
+                     (stream-error-stream condition)))))
+
+(defclass socket ()
     ((passive-socket :type fixnum
                     :initarg :passive-socket
                     :reader socket-os-fd)))
@@ -168,7 +194,8 @@ setsockopt SO_REUSEADDR if :reuse is not nil"
     (make-instance 'passive-socket
                   :port port
                   :passive-socket (%new-passive-socket port)
-                  :element-type format))
+                  :element-type (case format
+                                  (:text 'base-char))))
   )
 
 (defun make-fd-stream (socket &key input output element-type)
@@ -202,10 +229,12 @@ setsockopt SO_REUSEADDR if :reuse is not nil"
   #+clisp
   (ext:socket-accept listener)
   #+lispworks
-  (when (stream-input-available listener)
+  (progn
+    (loop while (not (stream-input-available listener))
+         do (sleep 1))
     (make-instance 'bidirectional-binary-socket-stream
                   :socket (comm::get-fd-from-socket
-                           (socket-os-fd passive-socket))
+                           (socket-os-fd listener))
                   :direction :io
                   :element-type (element-type listener)))