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;
/* 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;
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);
* (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) {
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