@@ -778,7 +778,7 @@ httpGetContentEncoding(http_t *http) // I - HTTP connection
778778 if (http && http -> fields [HTTP_FIELD_ACCEPT_ENCODING ])
779779 {
780780 int i ; // Looping var
781- char temp [HTTP_MAX_VALUE ], // Copy of Accepts-Encoding value
781+ char temp [_HTTP_MAX_VALUE ], // Copy of Accepts-Encoding value
782782 * start , // Start of coding value
783783 * end ; // End of coding value
784784 double qvalue ; // "qvalue" for coding
@@ -1190,7 +1190,7 @@ httpGets(http_t *http, // I - HTTP connection
11901190 return (NULL );
11911191 }
11921192
1193- bytes = http_read (http , http -> buffer + http -> used , (size_t )(HTTP_MAX_BUFFER - http -> used ));
1193+ bytes = http_read (http , http -> buffer + http -> used , (size_t )(_HTTP_MAX_BUFFER - http -> used ));
11941194
11951195 DEBUG_printf ("4httpGets: read " CUPS_LLFMT " bytes." , CUPS_LLCAST bytes );
11961196
@@ -1331,7 +1331,7 @@ httpGetSubField(http_t *http, // I - HTTP connection
13311331 size_t valuelen ) // I - Size of value buffer
13321332{
13331333 const char * fptr ; // Pointer into field
1334- char temp [HTTP_MAX_VALUE ], // Temporary buffer for name
1334+ char temp [_HTTP_MAX_VALUE ], // Temporary buffer for name
13351335 * ptr , // Pointer into string buffer
13361336 * end ; // End of value buffer
13371337
@@ -1629,9 +1629,9 @@ httpPeek(http_t *http, // I - HTTP connection
16291629
16301630 memset (& stream , 0 , sizeof (stream ));
16311631
1632- if (http -> used > 0 && ((z_stream * )http -> stream )-> avail_in < HTTP_MAX_BUFFER )
1632+ if (http -> used > 0 && ((z_stream * )http -> stream )-> avail_in < _HTTP_MAX_BUFFER )
16331633 {
1634- size_t buflen = HTTP_MAX_BUFFER - ((z_stream * )http -> stream )-> avail_in ;
1634+ size_t buflen = _HTTP_MAX_BUFFER - ((z_stream * )http -> stream )-> avail_in ;
16351635 // Number of bytes to copy
16361636
16371637 if (((z_stream * )http -> stream )-> avail_in > 0 && ((z_stream * )http -> stream )-> next_in > http -> sbuffer )
@@ -1830,7 +1830,7 @@ httpRead(http_t *http, // I - HTTP connection
18301830
18311831 if (bytes == 0 )
18321832 {
1833- ssize_t buflen = HTTP_MAX_BUFFER - (ssize_t )((z_stream * )http -> stream )-> avail_in ;
1833+ ssize_t buflen = _HTTP_MAX_BUFFER - (ssize_t )((z_stream * )http -> stream )-> avail_in ;
18341834 // Additional bytes for buffer
18351835
18361836 if (buflen > 0 )
@@ -2464,14 +2464,38 @@ bool // O - `true` to continue, `false` to stop
24642464_httpUpdate (http_t * http , // I - HTTP connection
24652465 http_status_t * status ) // O - Current HTTP status
24662466{
2467- char line [32768 ], // Line from connection...
2467+ char line [_HTTP_MAX_BUFFER ], // Line from connection...
24682468 * value ; // Pointer to value on line
24692469 http_field_t field ; // Field index
24702470 int major , minor ; // HTTP version numbers
24712471
24722472
24732473 DEBUG_printf ("_httpUpdate(http=%p, status=%p), state=%s" , (void * )http , (void * )status , httpStateString (http -> state ));
24742474
2475+ // When doing non-blocking I/O, make sure we have a whole line...
2476+ if (!http -> blocking )
2477+ {
2478+ ssize_t bytes ; // Bytes "peeked" from connection
2479+
2480+ // Peek at the incoming data...
2481+ if ((bytes = httpPeek (http , line , sizeof (line ) - 1 )) < 0 )
2482+ {
2483+ // Unable to peek, return an error...
2484+ * status = HTTP_STATUS_ERROR ;
2485+ return (0 );
2486+ }
2487+
2488+ // Nul-terminate the data and see if we have a newline...
2489+ line [bytes ] = '\0' ;
2490+
2491+ if (!strchr (line , '\n' ))
2492+ {
2493+ // Don't have a full line, tell the reader to try again when there is more data...
2494+ * status = HTTP_STATUS_CONTINUE ;
2495+ return (0 );
2496+ }
2497+ }
2498+
24752499 // Grab a single line from the connection...
24762500 if (!httpGets (http , line , sizeof (line )))
24772501 {
@@ -4088,15 +4112,15 @@ http_set_timeout(int fd, // I - File descriptor
40884112static void
40894113http_set_wait (http_t * http ) // I - HTTP connection
40904114{
4091- if (http -> blocking )
4092- {
4093- http -> wait_value = (int )(http -> timeout_value * 1000 );
4115+ http -> wait_value = (int )(http -> timeout_value * 1000 );
40944116
4095- if (http -> wait_value <= 0 )
4117+ if (http -> wait_value <= 0 )
4118+ {
4119+ if (http -> blocking )
40964120 http -> wait_value = 60000 ;
4121+ else
4122+ http -> wait_value = 1000 ;
40974123 }
4098- else
4099- http -> wait_value = 10000 ;
41004124}
41014125
41024126
0 commit comments