Apply the fix for feof()

This commit is contained in:
Sascha Schumann 1999-05-20 13:56:19 +00:00
parent 3facf7cb7c
commit 27fc61c4dc
3 changed files with 35 additions and 13 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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