[ cl-cookbook-Bugs-546193 ] sockets example newline error
[email protected] Thu, 06 Jun 2002 23:31:03 -0700
| Newsgroups | gmane.lisp.cookbook |
|---|---|
| Message-ID | <[email protected]> |
Bugs item #546193, was opened at 2002-04-19 11:30
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=447472&aid=546193&group_id=46815
Category: None
Group: None
>Status: Open
Resolution: Fixed
Priority: 5
Submitted By: John Wiseman (jjwiseman)
Assigned to: Alberto Riva (albertoriva)
Summary: sockets example newline error
Initial Comment:
The sockets http example makes a common mistake by
using read-line for reading lines and ~% to output
newlines.
HTTP lines are terminated by CR LF. ~% may output LF
on a unix system, CR on a Mac, and CR LF in Windows.
Similarly, read-line will consider a line to be
terminated by diffrent characters or sequences of
characters on different systems.
----------------------------------------------------------------------
>Comment By: John Wiseman (jjwiseman)
Date: 2002-06-07 01:31
Message:
Logged In: YES
user_id=374464
The code still uses read-line to read HTTP requests, and
uses #\Newline when sending HTTP requests.
I think the most portable replacement for #\Return and
#\Newline (which is actually a carriage return on Mac OS
before 10, e.g.) is to use (code-char 13) and (code-char 10).
I've attached code I've used to read telnet-style
CRLF-terminated lines in several lisps, you might want to
use something like this.
(defun read-telnet-line (stream eof-error-p eof)
"Read a CRLF-terminated line"
(if (stream-eof-p stream)
eof
(let ((line (make-array 10 :element-type 'character
:adjustable t :fill-pointer 0))
(char nil))
(do () ((or (eq eof (setq char (read-char stream
eof-error-p eof)))
(and (eql char *cr*) (eql (peek-char nil
stream) *lf*)))
(when (not (eq char eof)) (read-char stream))
(values line (null char)))
(vector-push-extend char line)))))
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=447472&aid=546193&group_id=46815
_______________________________________________________________
Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm