mirror of
https://github.com/php/php-src.git
synced 2025-08-20 17:34:35 +02:00
Improve robustness of sending routines
This commit is contained in:
parent
41da75d59f
commit
58c106cb06
1 changed files with 32 additions and 12 deletions
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
#include <unixlib/local.h>
|
#include <unixlib/local.h>
|
||||||
|
|
||||||
#define WEBJAMES_SAPI_VERSION "1.0.1"
|
#define WEBJAMES_SAPI_VERSION "1.0.2"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
struct connection *conn; /*structure holding all the details of the current request*/
|
struct connection *conn; /*structure holding all the details of the current request*/
|
||||||
|
@ -42,24 +42,44 @@ static php_webjames_globals webjames_globals;
|
||||||
static int sapi_webjames_ub_write(const char *str, uint str_length TSRMLS_DC)
|
static int sapi_webjames_ub_write(const char *str, uint str_length TSRMLS_DC)
|
||||||
/*unbuffered write - send data straight out to socket*/
|
/*unbuffered write - send data straight out to socket*/
|
||||||
{
|
{
|
||||||
int bytes;
|
int totalbytes = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
int bytes;
|
||||||
bytes = webjames_writebuffer(WG(conn),str,str_length);
|
bytes = webjames_writebuffer(WG(conn),str,str_length);
|
||||||
if (bytes<0) {
|
if (bytes<0) {
|
||||||
PG(connection_status) = PHP_CONNECTION_ABORTED;
|
PG(connection_status) = PHP_CONNECTION_ABORTED;
|
||||||
if (!PG(ignore_user_abort)) {
|
if (!PG(ignore_user_abort)) {
|
||||||
zend_bailout();
|
zend_bailout();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
str += bytes;
|
||||||
|
str_length -= bytes;
|
||||||
|
totalbytes += bytes;
|
||||||
|
} while (str_length);
|
||||||
|
return totalbytes;
|
||||||
|
}
|
||||||
|
|
||||||
static void sapi_webjames_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC)
|
static void sapi_webjames_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC)
|
||||||
/*send an HTTP header*/
|
/*send an HTTP header*/
|
||||||
{
|
{
|
||||||
|
char *header = sapi_header->header;
|
||||||
|
int len = sapi_header->header_len;
|
||||||
if (WG(conn)->flags.outputheaders) {
|
if (WG(conn)->flags.outputheaders) {
|
||||||
if (sapi_header)
|
while (sapi_header && len > 0) {
|
||||||
webjames_writebuffer(WG(conn), sapi_header->header, sapi_header->header_len);
|
int bytes;
|
||||||
|
bytes = webjames_writebuffer(WG(conn), header, len);
|
||||||
|
if (bytes<0) {
|
||||||
|
PG(connection_status) = PHP_CONNECTION_ABORTED;
|
||||||
|
if (!PG(ignore_user_abort)) {
|
||||||
|
zend_bailout();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
header += bytes;
|
||||||
|
len -= bytes;
|
||||||
|
}
|
||||||
webjames_writestring(WG(conn), "\r\n");
|
webjames_writestring(WG(conn), "\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue