Posted on: 2012-11-13 16:26:48.000
It's not quite like winning an Olympic Gold Medal or anything, but it's a nice feeling.
I was having a very intermittent problem with long posts being truncated. Most posts are short enough that they didn't encounter this problem, but longer posts with code would sometimes just cut off randomly. The weird thing is that if I went back and refreshed the page they would go through. It wasn't predictable at all. Those kind of bugs are the
most annoying!
Basically I had some old code that followed a similar technique that Dragonfly used:
(when (> (peek (device)) 0)
(if (and (read (device) post-buffer $MAX_POST_LENGTH) post-buffer) ; grab all post data, put it in variable 'post-buffer'
(parse-get-or-post post-buffer $POST)
)
)
The idea is that you're reading from (device) into a variable called post-buffer. Hard to figure out what's going wrong in there!
Not sure how to fix this, I went and looked at the code in Artful Code's A Better newLISP Web Library:
http://www.artfulcode.net/articles/a-better-newlisp-web-library/
The author had taken a slightly different approach, which I adapted into my framework:
(let ((buffer "") (post-buffer ""))
(unless (zero? (peek (device)))
(while (read (device) buffer $MAX_POST_LENGTH)
(write post-buffer buffer))
(parse-get-or-post post-buffer $POST)))
Basically, instead of just reading the (device) once, it CONTINUES to read the (device) and copies whatever it finds into a temporary variable "buffer" that gets appended to the variable "post-buffer" until there is nothing left to read.
It's nice when things get fixed like this. It makes me very happy.