>From: Raoul Gough <[EMAIL PROTECTED]
>To: <[EMAIL PROTECTED]>
>Sent: Wednesday, August 23, 2000 12:22 PM
>Subject: JServOutputStream.flush()
>
> I've got a servlet that sends out a small amount of information at
irregular
> intervals. However, when I do a flush() on the ServletOutputStream, the
data
> doesn't get sent out to the client.
Since posting yesterday, I've got access to an MS compiler and I've tested a
few things out. I've got a three-line fix that goes into Apache
src/main/http_protocol.c which solves the problem (not in jserv_ajpv12 as I
originally suggested). The problem is in ap_send_fb_length where the code
buffers the output, even though it's just read the data off a socket,
indicating that the original sender has attempted to flush the data through.
This is unfortunately not local to the JServ code, so I'm not sure how
wide-reaching this change would be.
I've written a simple test servlet (at end of this post) that shows the
problem. When I access this servlet from a browser with Apache version 1.3
and JServ 1.1, the output arrives all at once after ten seconds. This
indicates that the call to flush() has no effect as far as the end-to-end
connection is concerned. By adding a call to ap_bflush at the appropriate
point in ap_send_fb_length, the data arrives one line at a time at
one-second intervals, which is what I would expect when I explicitly call
flush().
This looks to me like a bug, either in JServ or Apache http_protocol. I
mean, if the servlet *explicitly* flushes the output, then it has to flush
through somehow. Can anybody with better knowledge of the code please
comment on this?
Regards,
Raoul Gough.
====== begin testflush.java ========
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class testflush extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
// set header field first
res.setContentType("text/html");
// then get the writer and write the response data
PrintWriter out = res.getWriter();
out.println("<HEAD><TITLE>Flush test servlet</TITLE></HEAD><BODY>");
for (int count = 1; count <= 10; ++count)
{
out.println("Line " + count + "<BR>");
out.flush();
try
{
Thread.sleep (1000);
}
catch (InterruptedException e)
{
}
}
out.println("</BODY>");
out.close();
}
}
======= end test servlet ========
--
----------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Archives and Other: <http://java.apache.org/main/mail.html>
Problems?: [EMAIL PROTECTED]