Thread: [cl-cookbook-contrib] [ cl-cookbook-Bugs-546193 ] sockets example newline error
Brought to you by:
jthing
From: <no...@so...> - 2002-04-19 16:30:26
|
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: None Priority: 5 Submitted By: John Wiseman (jjwiseman) Assigned to: Nobody/Anonymous (nobody) 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. ---------------------------------------------------------------------- You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=447472&aid=546193&group_id=46815 |
From: <no...@so...> - 2002-06-07 06:31:04
|
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 |
From: Lieven M. <ma...@wy...> - 2002-04-20 12:31:00
|
no...@so... writes: > 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: None > Priority: 5 > Submitted By: John Wiseman (jjwiseman) > Assigned to: Nobody/Anonymous (nobody) > 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. I usually work around this problem by using a MAKE-STREAM-CRLF-ENDED function that is implemented by using MOP and Gray streams. This could make an example for this kind of technique. In general, the cost of network latency makes this efficient enough for clients -- Lieven Marchand <ma...@wy...> She says, "Honey, you're a Bastard of great proportion." He says, "Darling, I plead guilty to that sin." Cowboy Junkies -- A few simple words |
From: Alberto R. <Alb...@TC...> - 2002-04-20 16:40:34
|
Lieven Marchand wrote: > > I usually work around this problem by using a MAKE-STREAM-CRLF-ENDED > function that is implemented by using MOP and Gray streams. This could > make an example for this kind of technique. In general, the cost of > network latency makes this efficient enough for clients Lieven, you're welcome to add an example of your technique to the page, or send it to me. My example was oversimplified since the page was already long enough. In real life, I've found that browsers have no problems accepting LF-terminated lines. In the other direction, I just strip the extra CR from the line returned by READ-LINE. I also have code (mostly provided by Franz for ACL 6) to support different line terminators using their own simple-streams. Maybe we could put the two solutions together in a new page about haw to deal with different encodings. Alberto -- Alberto Riva Children's Hospital Informatics Program |