static int php_roxen_low_ub_write(const char *str, uint str_length TSRMLS_DC) { int sent_bytes = 0; struct pike_string *to_write = NULL; #ifdef ROXEN_USE_ZTS GET_THIS(); #endif if(!MY_FD_OBJ->prog) { PG(connection_status) = PHP_CONNECTION_ABORTED; zend_bailout(); return -1; } to_write = make_shared_binary_string(str, str_length); push_string(to_write); safe_apply(MY_FD_OBJ, "write", 1); if(Pike_sp[-1].type == PIKE_T_INT) sent_bytes = Pike_sp[-1].u.integer; pop_stack(); if(sent_bytes != str_length) { /* This means the connection is closed. Dead. Gone. *sniff* */ php_handle_aborted_connection(); } return sent_bytes; }
static int sapi_thttpd_ub_write(const char *str, uint str_length TSRMLS_DC) { int n; uint sent = 0; if (TG(sbuf).c != 0) { smart_str_appendl_ex(&TG(sbuf), str, str_length, 1); return str_length; } while (str_length > 0) { PHP_SYS_CALL(n = send(TG(hc)->conn_fd, str, str_length, 0);); if (n == -1) { if (errno == EAGAIN) { smart_str_appendl_ex(&TG(sbuf), str, str_length, 1); return sent + str_length; } else php_handle_aborted_connection(); } TG(hc)->bytes_sent += n; str += n; sent += n; str_length -= n; }
static int php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) { apr_bucket *b; apr_bucket_brigade *bb; apr_bucket_alloc_t *ba; ap_filter_t *f; /* remaining output filters */ php_struct *ctx; ctx = SG(server_context); f = ctx->f; if (str_length == 0) return 0; ba = f->c->bucket_alloc; bb = apr_brigade_create(ctx->r->pool, ba); b = apr_bucket_transient_create(str, str_length, ba); APR_BRIGADE_INSERT_TAIL(bb, b); if (ap_pass_brigade(f->next, bb) != APR_SUCCESS || ctx->r->connection->aborted) { php_handle_aborted_connection(); } return str_length; /* we always consume all the data passed to us. */ }
static size_t sapi_cli_ub_write(const char *str, size_t str_length) /* {{{ */ { const char *ptr = str; size_t remaining = str_length; size_t ret; if (!str_length) { return 0; } if (cli_shell_callbacks.cli_shell_ub_write) { size_t ub_wrote; ub_wrote = cli_shell_callbacks.cli_shell_ub_write(str, str_length); if (ub_wrote != (size_t) -1) { return ub_wrote; } } while (remaining > 0) { ret = sapi_cli_single_write(ptr, remaining); if (!ret) { #ifndef PHP_CLI_WIN32_NO_CONSOLE php_handle_aborted_connection(); #endif break; } ptr += ret; remaining -= ret; } return (ptr - str); }
/* {{{ sapi_lsapi_flush */ static void sapi_lsapi_flush( void * server_context ) { if ( lsapi_mode ) { if ( LSAPI_Flush() == -1) { php_handle_aborted_connection(); } } }
static int sapi_tux_ub_write(const char *str, uint str_length TSRMLS_DC) { int n; int m; const char *estr; /* combine headers and body */ if (TG(number_vec)) { struct iovec *vec = TG(header_vec); n = TG(number_vec); vec[n].iov_base = (void *) str; vec[n++].iov_len = str_length; /* XXX: this might need more complete error handling */ if ((m = writev(TG(req)->sock, vec, n)) == -1 && errno == EPIPE) php_handle_aborted_connection(); if (m > 0) TG(req)->bytes_sent += str_length; TG(number_vec) = 0; return str_length; } estr = str + str_length; while (str < estr) { n = send(TG(req)->sock, str, estr - str, 0); if (n == -1 && errno == EPIPE) php_handle_aborted_connection(); if (n == -1 && errno == EAGAIN) continue; if (n <= 0) return n; str += n; } n = str_length - (estr - str); TG(req)->bytes_sent += n; return n; }
static int engine_ub_write(const char *str, uint str_length TSRMLS_DC) { engine_context *context = (engine_context *) SG(server_context); int written = context->write(context, str, str_length); if (written != str_length) { php_handle_aborted_connection(); } return written; }
static int sapi_uwsgi_ub_write(const char *str, uint str_length TSRMLS_DC) { struct wsgi_request *wsgi_req = (struct wsgi_request *) SG(server_context); wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, (char *) str, str_length); if (wsgi_req->write_errors > uwsgi.write_errors_tolerance) { php_handle_aborted_connection(); return -1; } return str_length; }
static void sapi_cli_flush(void *server_context) /* {{{ */ { /* Ignore EBADF here, it's caused by the fact that STDIN/STDOUT/STDERR streams * are/could be closed before fflush() is called. */ if (fflush(stdout)==EOF && errno!=EBADF) { #ifndef PHP_CLI_WIN32_NO_CONSOLE php_handle_aborted_connection(); #endif } }
static int sapi_isapi_ub_write(const char *str, uint str_length TSRMLS_DC) { DWORD num_bytes = str_length; LPEXTENSION_CONTROL_BLOCK ecb; ecb = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); if (ecb->WriteClient(ecb->ConnID, (char *) str, &num_bytes, HSE_IO_SYNC) == FALSE) { php_handle_aborted_connection(); } return num_bytes; }
/* * sapi_capi_ub_write: Write len bytes to the connection output. */ static int sapi_capi_ub_write(const char *str, unsigned int str_length TSRMLS_DC) { int retval; capi_request_context *rc; rc = (capi_request_context *) SG(server_context); retval = httpFwrite(rc->t, (char *) str, str_length); if (retval == -1 || retval == 0) php_handle_aborted_connection(); return retval; }
static int sapi_uwsgi_ub_write(const char *str, uint str_length TSRMLS_DC) #endif { struct wsgi_request *wsgi_req = (struct wsgi_request *) SG(server_context); uwsgi_response_write_body_do(wsgi_req, (char *) str, str_length); if (wsgi_req->write_errors > uwsgi.write_errors_tolerance) { php_handle_aborted_connection(); return -1; } return str_length; }
/* {{{ sapi_apache_ub_write */ static int sapi_apache_ub_write(const char *str, uint str_length TSRMLS_DC) { int ret=0; if (SG(server_context)) { ret = rwrite(str, str_length, (request_rec *) SG(server_context)); } if (ret != str_length) { php_handle_aborted_connection(); } return ret; }
static int php_phttpd_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) { int sent_bytes; sent_bytes = fd_write(PHG(cip)->fd, str, str_length); if (sent_bytes == -1) { php_handle_aborted_connection(); } return sent_bytes; }
static int zend_pi3web_ub_write(const char *str, uint str_length TSRMLS_DC) { DWORD num_bytes = str_length; LPCONTROL_BLOCK cb; cb = (LPCONTROL_BLOCK) SG(server_context); if ( !IWasLoaded ) return 0; cb->WriteClient(cb->ConnID, (char *) str, &num_bytes, 0 ); if (num_bytes != str_length) php_handle_aborted_connection(); return num_bytes; }
/* {{{ sapi_lsapi_ub_write */ static int sapi_lsapi_ub_write(const char *str, uint str_length TSRMLS_DC) { int ret; int remain; if ( lsapi_mode ) { ret = LSAPI_Write( str, str_length ); if ( ret < str_length ) { php_handle_aborted_connection(); return str_length - ret; } } else { remain = str_length; while( remain > 0 ) { ret = write( 1, str, remain ); if ( ret <= 0 ) { php_handle_aborted_connection(); return str_length - remain; } str += ret; remain -= ret; } } return str_length; }
static int php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC) { request_rec *r; php_struct *ctx; ctx = SG(server_context); r = ctx->r; if (ap_rwrite(str, str_length, r) < 0) { php_handle_aborted_connection(); } return str_length; /* we always consume all the data passed to us. */ }
static int sapi_nsapi_ub_write(const char *str, unsigned int str_length TSRMLS_DC) { int retval; nsapi_request_context *rc = (nsapi_request_context *)SG(server_context); if (!SG(headers_sent)) { sapi_send_headers(TSRMLS_C); } retval = net_write(rc->sn->csd, (char *)str, str_length); if (retval == IO_ERROR /* -1 */ || retval == IO_EOF /* 0 */) { php_handle_aborted_connection(); } return retval; }
static int writeBlock(cchar *str, uint len TSRMLS_DC) { MaConn *conn; int written; conn = (MaConn*) SG(server_context); if (conn == 0) { return -1; } written = maWriteBlock(conn->response->queue[MA_QUEUE_SEND].nextQ, str, len, 1); mprLog(mprGetMpr(0), 6, "php: write %d", written); if (written <= 0) { php_handle_aborted_connection(); } return written; }
static int writeBlock(cchar *str, uint len TSRMLS_DC) { HttpConn *conn; ssize written; conn = (HttpConn*) SG(server_context); if (conn == 0) { return -1; } written = httpWriteBlock(conn->tx->queue[HTTP_QUEUE_TX]->nextQ, str, len, HTTP_BLOCK); mprLog(6, "php: write %d", written); if (written <= 0) { php_handle_aborted_connection(); } return (int) written; }
static size_t php_embed_ub_write(const char *str, size_t str_length) { const char *ptr = str; size_t remaining = str_length; size_t ret; while (remaining > 0) { ret = php_embed_single_write(ptr, remaining); if (!ret) { php_handle_aborted_connection(); } ptr += ret; remaining -= ret; } return str_length; }
static int php_ns_sapi_ub_write(const char *str, uint str_length) { int n; uint sent = 0; while (str_length > 0) { n = Ns_ConnWrite(NSG(conn), (void *) str, str_length); if (n == -1) php_handle_aborted_connection(); str += n; sent += n; str_length -= n; } return sent; }
/* 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) { /* we have no context, so no flushing needed. This fixes a SIGSEGV on shutdown */ 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 NSAPI_VERSION >= 302 if (net_flush(rc->sn->csd) < 0) { php_handle_aborted_connection(); } #endif }
static void php_apache_sapi_flush(void *server_context) { php_struct *ctx; apr_bucket_brigade *bb; apr_bucket_alloc_t *ba; apr_bucket *b; ap_filter_t *f; /* output filters */ ctx = server_context; /* If we haven't registered a server_context yet, * then don't bother flushing. */ if (!server_context) return; sapi_send_headers(); ctx->r->status = SG(sapi_headers).http_response_code; SG(headers_sent) = 1; f = ctx->f; /* Send a flush bucket down the filter chain. The current default * handler seems to act on the first flush bucket, but ignores * all further flush buckets. */ ba = ctx->r->connection->bucket_alloc; bb = apr_brigade_create(ctx->r->pool, ba); b = apr_bucket_flush_create(ba); APR_BRIGADE_INSERT_TAIL(bb, b); if (ap_pass_brigade(f->next, bb) != APR_SUCCESS || ctx->r->connection->aborted) { php_handle_aborted_connection(); } }
static void php_embed_flush(void *server_context) { if (fflush(stdout)==EOF) { php_handle_aborted_connection(); } }