Commit d93f2397 authored by madhu's avatar madhu Committed by Madhu
Browse files

backend/openmcl.lisp: (to-format): ensure bivalent streams get created

Explicitly specifying :FORMAT :TEXT to CCL:MAKE-SOCKET
makes the socket monovalent.  (This is at odds with the doc)
So use :BIVALENT instead of TEXT in the ccl backend

(in-package "CL-USER")
(defun test-bivalence (sock)
  (list :write-byte (ignore-errors (write-byte 95 sock))
	:write-char (ignore-errors (write-byte #\G sock))
	:format (ccl:socket-format sock)
	:external-format (stream-external-format sock)
	:element-type (stream-element-type sock)))

(defmacro getf-and-remf (place indicator default)
  `(let ((val (getf ,place ,indicator)))
     (cond (val (remf ,place ,indicator) val)
	   (t ,default))))

(defun make-sock (&rest make-socket-args)
  (let* ((args (copy-seq make-socket-args))
	 (remote-host (getf-and-remf args :remote-host "localhost"))
	 (remote-port (getf-and-remf args :remote-port 22)))
    (apply #'ccl:make-socket
	  :remote-host remote-host
	  :remote-port remote-port


;; :TEXT FAILs to be bivalent
(test-bivalence (make-sock :format :text)) ; => (:WRITE-BYTE NIL :WRITE-CHAR NIL :FORMAT :TEXT :EXTERNAL-FORMAT #<EXTERNAL-FORMAT :ISO-8859-1/:UNIX #x302001C9C8ED> :ELEMENT-TYPE CHARACTER)

(test-bivalence (make-sock :format :binary)) ;  => (:WRITE-BYTE 95 :WRITE-CHAR #\G :FORMAT :BIVALENT :EXTERNAL-FORMAT  #<EXTERNAL-FORMAT :ISO-8859-1/:UNIX #x302001C9C8ED> :ELEMENT-TYPE (UNSIGNED-BYTE 8))

(test-bivalence (make-sock :format :bivalent)) ;  => (:WRITE-BYTE 95 :WRITE-CHAR #\G :FORMAT :TEXT :EXTERNAL-FORMAT #<EXTERNAL-FORMAT :ISO-8859-1/:UNIX #x302001C9C8ED> :ELEMENT-TYPE CHARACTER)
parent d96fe38d
......@@ -80,11 +80,13 @@
(defun to-format (element-type protocol)
(cond ((null element-type)
(ecase protocol ; default value of different protocol
(:stream :text)
(:stream ;;:text
(:datagram :binary)))
((subtypep element-type 'character)
(t :binary)))
(t ;; :binary
(defun socket-connect (host port &key (protocol :stream) element-type
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment