Gmane
Picon Favicon
From: Edi Weitz <edi <at> agharta.de>
Subject: Problem with READ-BYTE-SEQUENCE on Windows
Newsgroups: gmane.lisp.clisp.general
Date: 2004-01-15 12:26:21 GMT (4 years, 24 weeks, 4 days, 10 hours and 35 minutes ago)
The test code below works fine with binary downloads like, say,

  (foo "weitz.de" "/files/cl-interpol.tgz")

if I invoke it from Linux. But if I use it from Windows most of the
contents of the generated "out" file (towards the end) are nulls. Am I
doing something wrong or is this a bug? (Looks to me as if it acted
like the :NO-HANG argument were T.)

I had the same problem with the standard functions
READ-SEQUENCE/WRITE-SEQUENCE.

Both are CLISP 2.32. On Linux (SuSE 9.0) it was built from source, on
Windows (XP pro) I used the "clisp-2.32-win32.zip" binary from
Sourceforge.

Thanks,
Edi.

(defun foo (host url)
  (let ((stream (socket:socket-connect
                 80 host
                 :external-format
                 (ext:make-encoding :charset 'charset:iso-8859-1
                                    :line-terminator :unix))))
    (format stream "GET ~A HTTP/1.0~C~CHost: ~A~C~C~C~C"
            url #\Return #\Linefeed
            host #\Return #\Linefeed #\Return #\Linefeed)
    (force-output stream)
    (let (length)
      (loop for line = (read-line stream nil nil)
            until (or (null line)
                      (zerop (length line))
                      (eql (elt line 0) (code-char 13)))
            when (= (mismatch line "Content-length: "
                              :test #'char-equal)
                    16)
            do (setq length
                       (parse-integer line
                                      :start 15
                                      :junk-allowed t)))
      (unless length
        (error "No Content-Length header found"))
      (setf (stream-element-type stream) '(unsigned-byte 8))
      (with-open-file (out "out" :direction :output
                           :element-type '(unsigned-byte 8)
                           :if-exists :supersede)
        (let ((buf (make-array length
                               :element-type
                               (stream-element-type stream))))
          (ext:read-byte-sequence buf stream :no-hang nil)
          (ext:write-byte-sequence buf out)))
      (values))))

-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html