/*
- * "$Id: client.c,v 1.91.2.75 2004/02/05 20:54:44 mike Exp $"
+ * "$Id: client.c,v 1.91.2.76 2004/02/25 16:22:01 mike Exp $"
*
* Client routines for the Common UNIX Printing System (CUPS) scheduler.
*
/* Time of last DoS attack */
- LogMessage(L_DEBUG2, "AcceptClient(%p) %d NumClients = %d",
+ LogMessage(L_DEBUG2, "AcceptClient(lis=%p) %d NumClients = %d",
lis, lis->fd, NumClients);
/*
LogMessage(L_DEBUG2, "CloseClient: %d Killing process ID %d...",
con->http.fd, con->pipe_pid);
kill(con->pipe_pid, SIGKILL);
-
- LogMessage(L_DEBUG2, "CloseClient: %d Removing fd %d from InputSet...",
- con->http.fd, con->file);
- FD_CLR(con->file, InputSet);
-
- LogMessage(L_DEBUG2, "CloseClient: %d Closing data file %d.",
- con->http.fd, con->file);
-
- close(con->file);
- con->file = 0;
}
- else if (con->file)
- {
- /*
- * Close the open data file...
- */
-
- LogMessage(L_DEBUG2, "CloseClient: %d Removing fd %d from InputSet.",
- con->http.fd, con->file);
-
- FD_CLR(con->file, InputSet);
+ if (con->file >= 0)
+ {
+ if (FD_ISSET(con->file, InputSet))
+ {
+ LogMessage(L_DEBUG2, "CloseClient: %d Removing fd %d from InputSet...",
+ con->http.fd, con->file);
+ FD_CLR(con->file, InputSet);
+ }
LogMessage(L_DEBUG2, "CloseClient: %d Closing data file %d.",
con->http.fd, con->file);
close(con->file);
- con->file = 0;
+ con->file = -1;
}
if (!partial)
con->http.data_remaining = 0;
con->operation = HTTP_WAITING;
con->bytes = 0;
- con->file = 0;
+ con->file = -1;
+ con->file_ready = 0;
con->pipe_pid = 0;
con->username[0] = '\0';
con->password[0] = '\0';
con->file);
close(con->file);
- con->file = 0;
+ con->file = -1;
unlink(con->filename);
ClearString(&con->filename);
con->http.fd, con->file, (int)filestats.st_size);
close(con->file);
- con->file = 0;
+ con->file = -1;
if (filestats.st_size > MaxRequestSize &&
MaxRequestSize > 0)
con->bytes += ippLength(con->request);
}
- if (con->file == 0 && con->http.state != HTTP_POST_SEND)
+ if (con->file < 0 && con->http.state != HTTP_POST_SEND)
{
/*
* Create a file as needed for the request data...
con->file);
close(con->file);
- con->file = 0;
+ con->file = -1;
unlink(con->filename);
ClearString(&con->filename);
if (con->http.state == HTTP_POST_SEND)
{
- if (con->file)
+ if (con->file >= 0)
{
fstat(con->file, &filestats);
con->http.fd, con->file, (int)filestats.st_size);
close(con->file);
- con->file = 0;
+ con->file = -1;
if (filestats.st_size > MaxRequestSize &&
MaxRequestSize > 0)
LogMessage(L_INFO, "Started \"%s\" (pid=%d)", command, con->pipe_pid);
- LogMessage(L_DEBUG, "SendCommand() %d file=%d", con->http.fd, con->file);
+ LogMessage(L_DEBUG, "SendCommand: %d file=%d", con->http.fd, con->file);
if (con->pipe_pid == 0)
return (0);
return (0);
}
+ con->file_ready = 0;
con->got_fields = 0;
con->field_col = 0;
ipp_state_t ipp_state; /* IPP state value */
+#ifdef DEBUG
+ LogMessage(L_DEBUG2, "WriteClient(con=%p) %d response=%p, file=%d pipe_pid=%d",
+ con, con->http.fd, con->response, con->file, con->pipe_pid);
+#endif /* DEBUG */
+
if (con->http.state != HTTP_GET_SEND &&
con->http.state != HTTP_POST_SEND)
return (1);
}
else if ((bytes = read(con->file, buf, HTTP_MAX_BUFFER)) > 0)
{
+#ifdef DEBUG
+ LogMessage(L_DEBUG2, "WriteClient: Read %d bytes from file %d...",
+ bytes, con->file);
+#endif /* DEBUG */
+
if (con->pipe_pid && !con->got_fields)
{
/*
*bufptr++ = '\0';
httpPrintf(HTTP(con), "%s\r\n", buf);
- LogMessage(L_DEBUG2, "WriteClient() %d %s", con->http.fd, buf);
+ LogMessage(L_DEBUG2, "WriteClient: %d %s", con->http.fd, buf);
/*
* Update buffer...
*/
bytes -= (bufptr - buf);
- memcpy(buf, bufptr, bytes + 1);
+ memmove(buf, bufptr, bytes + 1);
bufptr = buf - 1;
/*
con->http.state = HTTP_WAITING;
- LogMessage(L_DEBUG2, "WriteClient() Removing fd %d from OutputSet...",
+ LogMessage(L_DEBUG2, "WriteClient: Removing fd %d from OutputSet...",
con->http.fd);
FD_CLR(con->http.fd, OutputSet);
- if (con->file)
+ if (con->file >= 0)
{
- LogMessage(L_DEBUG2, "WriteClient() Removing fd %d from InputSet...",
- con->file);
- FD_CLR(con->file, InputSet);
-
+ if (FD_ISSET(con->file, InputSet))
+ {
+ LogMessage(L_DEBUG2, "WriteClient: Removing fd %d from InputSet...",
+ con->file);
+ FD_CLR(con->file, InputSet);
+ }
+
if (con->pipe_pid)
kill(con->pipe_pid, SIGTERM);
con->http.fd, con->file);
close(con->file);
- con->file = 0;
+ con->file = -1;
con->pipe_pid = 0;
}
return (0);
}
}
+ else
+ {
+ con->file_ready = 0;
+
+ if (con->pipe_pid && !FD_ISSET(con->file, InputSet))
+ {
+ LogMessage(L_DEBUG2, "WriteClient: Adding fd %d to InputSet...", con->file);
+ FD_SET(con->file, InputSet);
+ }
+ }
if (bytes >= 1024)
- LogMessage(L_DEBUG2, "WriteClient() %d %d bytes", con->http.fd, bytes);
+ LogMessage(L_DEBUG2, "WriteClient: %d %d bytes", con->http.fd, bytes);
con->http.activity = time(NULL);
/*
- * End of "$Id: client.c,v 1.91.2.75 2004/02/05 20:54:44 mike Exp $".
+ * End of "$Id: client.c,v 1.91.2.76 2004/02/25 16:22:01 mike Exp $".
*/
/*
- * "$Id: main.c,v 1.57.2.54 2003/11/19 16:54:07 mike Exp $"
+ * "$Id: main.c,v 1.57.2.55 2004/02/25 16:22:01 mike Exp $"
*
* Scheduler main loop for the Common UNIX Printing System (CUPS).
*
while (!stop_scheduler)
{
+#ifdef DEBUG
+ LogMessage(L_DEBUG2, "main: Top of loop, dead_children=%d, NeedReload=%d",
+ dead_children, NeedReload);
+#endif /* DEBUG */
+
/*
* Check if there are dead children to handle...
*/
* Write data as needed...
*/
+ if (con->pipe_pid && FD_ISSET(con->file, input))
+ {
+ /*
+ * Keep track of pending input from the file/pipe separately
+ * so that we don't needlessly spin on select() when the web
+ * client is not ready to receive data...
+ */
+
+ con->file_ready = 1;
+
+#ifdef DEBUG
+ LogMessage(L_DEBUG2, "main: Data ready file %d!", con->file);
+#endif /* DEBUG */
+
+ if (!FD_ISSET(con->http.fd, output))
+ {
+ LogMessage(L_DEBUG2, "main: Removing fd %d from InputSet...", con->file);
+ FD_CLR(con->file, InputSet);
+ }
+ }
+
if (FD_ISSET(con->http.fd, output) &&
- (!con->pipe_pid || FD_ISSET(con->file, input)))
+ (!con->pipe_pid || con->file_ready))
if (!WriteClient(con))
{
con --;
/*
- * End of "$Id: main.c,v 1.57.2.54 2003/11/19 16:54:07 mike Exp $".
+ * End of "$Id: main.c,v 1.57.2.55 2004/02/25 16:22:01 mike Exp $".
*/