Skip to content

Commit 09f463d

Browse files
author
Sascha Schumann
committed
Add sapi_get_fd() and implement it for the Apache/thttpd SAPIs.
1 parent f0b6f54 commit 09f463d

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

main/SAPI.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,15 @@ SAPI_API char *sapi_getenv(char *name, size_t name_len TSRMLS_DC)
851851
}
852852
}
853853

854+
SAPI_API int sapi_get_fd(int *fd TSRMLS_DC)
855+
{
856+
if (sapi_module.get_fd) {
857+
return sapi_module.get_fd(fd TSRMLS_CC);
858+
} else {
859+
return -1;
860+
}
861+
}
862+
854863
/*
855864
* Local variables:
856865
* tab-width: 4

main/SAPI.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ SAPI_API void sapi_get_default_content_type_header(sapi_header_struct *default_h
186186
SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len TSRMLS_DC);
187187
SAPI_API void sapi_activate_headers_only(TSRMLS_D);
188188

189+
SAPI_API int sapi_get_fd(int *fd TSRMLS_DC);
190+
189191
struct _sapi_module_struct {
190192
char *name;
191193
char *pretty_name;
@@ -217,12 +219,16 @@ struct _sapi_module_struct {
217219

218220
void (*block_interruptions)(void);
219221
void (*unblock_interruptions)(void);
222+
220223

221224
void (*default_post_reader)(TSRMLS_D);
222225
void (*treat_data)(int arg, char *str, zval *destArray TSRMLS_DC);
223226
char *executable_location;
224227

225228
int php_ini_ignore;
229+
230+
int (*get_fd)(int *fd TSRMLS_DC);
231+
226232
};
227233

228234

sapi/apache/mod_php4.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,23 @@ static char *php_apache_getenv(char *name, size_t name_len TSRMLS_DC)
343343
}
344344
/* }}} */
345345

346+
/* {{{ sapi_apache_get_fd
347+
*/
348+
static int sapi_apache_get_fd(int *nfd TSRMLS_DC)
349+
{
350+
request_rec *r = SG(server_context);
351+
int fd;
352+
353+
fd = r->connection->client->fd;
354+
355+
if (fd >= 0) {
356+
if (nfd) *nfd = fd;
357+
return 0;
358+
}
359+
return -1;
360+
}
361+
/* }}} */
362+
346363
/* {{{ sapi_module_struct apache_sapi_module
347364
*/
348365
static sapi_module_struct apache_sapi_module = {
@@ -382,7 +399,11 @@ static sapi_module_struct apache_sapi_module = {
382399
unblock_alarms, /* Unblock interruptions */
383400
#endif
384401

385-
STANDARD_SAPI_MODULE_PROPERTIES
402+
NULL, /* default post reader */
403+
NULL, /* treat data */
404+
NULL, /* exe location */
405+
0, /* ini ignore */
406+
sapi_apache_get_fd
386407
};
387408
/* }}} */
388409

sapi/thttpd/thttpd.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,12 @@ static int php_thttpd_startup(sapi_module_struct *sapi_module)
382382
return SUCCESS;
383383
}
384384

385+
static int sapi_thttpd_get_fd(int *nfd TSRMLS_DC)
386+
{
387+
if (nfd) *nfd = TG(hc)->conn_fd;
388+
return 0;
389+
}
390+
385391
static sapi_module_struct thttpd_sapi_module = {
386392
"thttpd",
387393
"thttpd",
@@ -411,7 +417,11 @@ static sapi_module_struct thttpd_sapi_module = {
411417
NULL, /* Block interruptions */
412418
NULL, /* Unblock interruptions */
413419

414-
STANDARD_SAPI_MODULE_PROPERTIES
420+
NULL,
421+
NULL,
422+
NULL,
423+
0,
424+
sapi_thttpd_get_fd
415425
};
416426

417427
static void thttpd_module_main(int show_source TSRMLS_DC)

0 commit comments

Comments
 (0)