]> granicus.if.org Git - php/commitdiff
Hallo release manager: This patch is not release critical (affects only NSAPI, but...
authorUwe Schindler <thetaphi@php.net>
Sat, 29 Nov 2008 14:51:45 +0000 (14:51 +0000)
committerUwe Schindler <thetaphi@php.net>
Sat, 29 Nov 2008 14:51:45 +0000 (14:51 +0000)
MFH: Implement flushing in NSAPI, fix some problems with output buffering if the response was not started (no headers sent) before doing something in ub_write() or flush() - Writing or flushing output will fail in NSAPI, if headers were not sent before.

sapi/nsapi/nsapi.c

index f742ac8dbb32332183a2c475050e1ca9ce6149ff..fdc8cb195523cbd6d3431573159fb1db1b4a4adf 100644 (file)
@@ -433,8 +433,6 @@ PHP_FUNCTION(nsapi_response_headers)
 
        array_init(return_value);
 
-       php_header(TSRMLS_C);
-
        for (i=0; i < rc->rq->srvhdrs->hsize; i++) {
                entry=rc->rq->srvhdrs->ht[i];
                while (entry) {
@@ -453,9 +451,12 @@ PHP_FUNCTION(nsapi_response_headers)
 static int sapi_nsapi_ub_write(const char *str, unsigned int str_length TSRMLS_DC)
 {
        int retval;
-       nsapi_request_context *rc;
+       nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
+       
+       if (!SG(headers_sent)) {
+               sapi_send_headers(TSRMLS_C);
+       }
 
-       rc = (nsapi_request_context *)SG(server_context);
        retval = net_write(rc->sn->csd, (char *)str, str_length);
        if (retval == IO_ERROR /* -1 */ || retval == IO_EOF /* 0 */) {
                php_handle_aborted_connection();
@@ -463,6 +464,28 @@ static int sapi_nsapi_ub_write(const char *str, unsigned int str_length TSRMLS_D
        return retval;
 }
 
+/* modified version of apache2 */
+static void sapi_nsapi_flush(void *server_context)
+{
+       nsapi_request_context *rc = (nsapi_request_context *)server_context;
+       TSRMLS_FETCH();
+
+       if (!rc) {
+               return;
+       }
+
+       if (!SG(headers_sent)) {
+               sapi_send_headers(TSRMLS_C);
+       }
+
+       /* flushing is only supported in iPlanet servers from version 6.1 on, make it conditional */
+#if defined(net_flush)
+       if (net_flush(rc->sn->csd) < 0) {
+               php_handle_aborted_connection();
+       }
+#endif
+}
+
 static int sapi_nsapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC)
 {
        char *header_name, *header_content, *p;
@@ -747,7 +770,7 @@ static sapi_module_struct nsapi_sapi_module = {
        NULL,                                   /* deactivate */
 
        sapi_nsapi_ub_write,                    /* unbuffered write */
-       NULL,                                   /* flush */
+       sapi_nsapi_flush,                       /* flush */
        NULL,                                   /* get uid */
        NULL,                                   /* getenv */