mit-scheme-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MIT-Scheme-devel] fix problem with big data in swank.scm


From: Peter Feigl
Subject: [MIT-Scheme-devel] fix problem with big data in swank.scm
Date: Wed, 14 Nov 2012 15:39:19 +0100
User-agent: Notmuch/0.11+77~gad6d0d5 (http://notmuchmail.org) Emacs/24.1.50.2 (i686-pc-linux-gnu)

Dear fellow Schemers!

I've run into a problem with swank.scm, specifically READ-PACKET. It
seems it doesn't handle big data (more than about 4k) well. This comes
up when I put the cursor into any long list towards the end (such as
sxml files). Only the first ~4k are read, the rest is read the next time
through, which crashes, as STRING->NUMBER doesn't accept it.
The solution should be to loop and READ-SUBSTRING! until the length of
the entire message as specified has been read.

This should solve the problem (feel free to reformulate):

(define (read-packet in)
  (if (eof-object? (peek-char in))
      (disconnect))
  (let ((buffer
         (make-string
          (let ((buffer (make-string 6)))
            (read-string! buffer in)
            (string->number buffer 16 #t)))))
    ;; loop until all read
    (let loop ((start 0)
               (end (string-length buffer)))
      (if (= start end)
          buffer
          (let ((read-chars (read-substring! buffer start end in)))
            (loop
             (+ start read-chars)
             end))))))


Would anyone apply this to runtime/swank.scm?

Thank you :)

Peter



reply via email to

[Prev in Thread] Current Thread [Next in Thread]