mirror of
https://github.com/php/php-src.git
synced 2024-11-25 10:54:15 +08:00
Apply the fix for feof()
This commit is contained in:
parent
3facf7cb7c
commit
27fc61c4dc
@ -703,7 +703,6 @@ PHP_FUNCTION(feof)
|
||||
int id, type;
|
||||
int issock=0;
|
||||
int socketd=0, *sock;
|
||||
unsigned int temp;
|
||||
|
||||
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) {
|
||||
WRONG_PARAM_COUNT;
|
||||
@ -721,7 +720,7 @@ PHP_FUNCTION(feof)
|
||||
/* we're at the eof if the file doesn't exist */
|
||||
RETURN_TRUE;
|
||||
}
|
||||
if ((issock?!(recv(socketd,(char *)&temp,1,MSG_PEEK)):feof(fp))) {
|
||||
if ((issock?(_php3_sock_eof(socketd)):feof(fp))) {
|
||||
RETURN_TRUE;
|
||||
} else {
|
||||
RETURN_FALSE;
|
||||
|
@ -93,6 +93,8 @@ struct php3i_sockbuf {
|
||||
|
||||
static struct php3i_sockbuf *phpsockbuf;
|
||||
|
||||
typedef struct php3i_sockbuf php3i_sockbuf;
|
||||
|
||||
static int php3_minit_fsock(INIT_FUNC_ARGS);
|
||||
static int php3_mshutdown_fsock(SHUTDOWN_FUNC_ARGS);
|
||||
static int php3_rshutdown_fsock(SHUTDOWN_FUNC_ARGS);
|
||||
@ -290,23 +292,43 @@ PHP_FUNCTION(pfsockopen)
|
||||
* (buffered data is not persistent)
|
||||
* - php3_fopen_url_wrapper() is still doing single-byte lookahead/read
|
||||
*/
|
||||
/* {{{ _php3_sock_fgets() */
|
||||
|
||||
int _php3_sock_fgets(char *buf, int maxlen, int socket)
|
||||
static php3i_sockbuf *_php3_sock_findsock(int socket)
|
||||
{
|
||||
struct php3i_sockbuf *sockbuf = NULL, *tmpsockbuf;
|
||||
int bytesread, toread, len, buflen, count = 0;
|
||||
char *nl;
|
||||
/* FIXME: O(n) could be improved */
|
||||
|
||||
tmpsockbuf = phpsockbuf;
|
||||
while (tmpsockbuf) {
|
||||
if (tmpsockbuf->socket == socket) {
|
||||
sockbuf = tmpsockbuf;
|
||||
php3i_sockbuf *buf = NULL, *tmp;
|
||||
|
||||
for(tmp = phpsockbuf; tmp; tmp = tmp->next)
|
||||
if(tmp->socket == socket) {
|
||||
buf = tmp;
|
||||
break;
|
||||
}
|
||||
tmpsockbuf = tmpsockbuf->next;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
int _php3_sock_eof(int socket)
|
||||
{
|
||||
php3i_sockbuf *sockbuf;
|
||||
int ret = 0;
|
||||
|
||||
sockbuf = _php3_sock_findsock(socket);
|
||||
if(sockbuf) {
|
||||
ret = (sockbuf->writepos - sockbuf->readpos) == 0 ? 1 : 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* {{{ _php3_sock_fgets() */
|
||||
int _php3_sock_fgets(char *buf, int maxlen, int socket)
|
||||
{
|
||||
struct php3i_sockbuf *sockbuf;
|
||||
int bytesread, toread, len, buflen, count = 0;
|
||||
char *nl;
|
||||
|
||||
sockbuf = _php3_sock_findsock(socket);
|
||||
|
||||
if (sockbuf) {
|
||||
toread = sockbuf->writepos - sockbuf->readpos;
|
||||
if (toread > maxlen) {
|
||||
|
@ -53,6 +53,7 @@ extern int lookup_hostname(const char *addr, struct in_addr *in);
|
||||
extern int _php3_sock_fgets(char *buf, int maxlen, int socket);
|
||||
extern int _php3_sock_fread(char *buf, int maxlen, int socket);
|
||||
extern int _php3_is_persistent_sock(int);
|
||||
int _php3_sock_eof(int socket);
|
||||
|
||||
#define phpext_fsock_ptr fsock_module_ptr
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user