From: Stephen D. <sd...@gm...> - 2005-03-08 05:02:27
|
I don't think you need this. In 4.x all content is read fromt the network and buffered before your code ever runs. You're just copying it from one buffer to another. On Sat, 5 Mar 2005 10:38:09 +0100, Zoran Vasiljevic <zv...@ar...> wrote: > > What is [ns_conn discardcontent] used for? > > This I have made some years ago and it may not be > needed anymore today (not sure). What I ment with > that is: by processing the incoming request, I > look into http headers. If I decide to drop the > request because there is something in the headers > I don't like, I will handle all of the incoming > data from the client and just discard everything. > This is important for keepalive connections because > you have to be careful and read exactly the > contentLength bytes from the peer. I somehow could > not do that using existing ns_ commands so I invented > my own. Question: is there another way of doing this? > Look at the implementation I have now: > > static int > NsxDiscardCmd (cl, interp, objc, objv) > ClientData cl; > Tcl_Interp * interp; > int objc; > Tcl_Obj * CONST objv[]; > { > size_t buflen; > int nb; > char *buf; > Ns_Conn *conn; > > /* > * Syntax: nsx discardcontent > */ > > conn = Ns_TclGetConn(interp); > if (conn == NULL) { > Tcl_AppendResult(interp, "no connection", NULL); > return TCL_ERROR; > } > > buflen = 32*1024; > buf = (char*)Tcl_Alloc(buflen); > > /* > * Sink conn->contentLength bytes from connection > */ > > while(conn->contentLength > 0) { > nb = (conn->contentLength < buflen) ? conn->contentLength : buflen; > nb = Ns_ConnRead(conn, buf, nb); > if (nb == NS_ERROR) { > break; > } > conn->contentLength -= nb; > } > > Tcl_Free((char*)buf); > > return TCL_OK; > } |