php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8722 non blocking sockets reading doesn't work on WIN32
Submitted: 2001-01-15 14:50 UTC Modified: 2001-05-13 19:21 UTC
From: christophe at winamp dot com Assigned:
Status: Closed Package: Sockets related
PHP Version: 4.0.4pl1 OS: Any Windows OS
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: christophe at winamp dot com
New email:
PHP Version: OS:

 

 [2001-01-15 14:50 UTC] christophe at winamp dot com
i have the following script:

  $g_ssock=fsockopen($server,$port,$errno,$errstr,30);
  socket_set_blocking($g_ssock,0);
  while(!feof($g_ssock))
    echo fgets($g_ssock,4096);

if you uncomment the socket_set_blocking line it will work fine on win32, but with non blocking sockets,  feof will always return true. by digging through the code, it appears that fsock.c uses the errno() function for determining any socket error as seen in function php_sockread_internal:

	} else if(nr_bytes == 0 || (nr_bytes < 0 && errno != EWOULDBLOCK)) {
		sock->eof = 1;
	}

the problem is that win32 doesn't report socket errors with _errno() but with WSAGetLastError() so here is my fix:

in fsock.c, line 46, replace:

#ifdef PHP_WIN32
#include <winsock.h>
#else

with:

#ifdef PHP_WIN32
#include <winsock.h>
#undef errno
#define errno (WSAGetLastError())
#else


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-04-16 06:38 UTC] jmoore@php.net
Ill test the patch and commit if it works well. It looks right to me.

-James
 [2001-05-13 19:21 UTC] jmoore@php.net
This appears to be fixed in latest CVS. (I cant reproduce this with or without your patch). Please try this with latest cvs and reopen if this is not the case.

- James
 [2002-06-27 05:21 UTC] laurent at searchlores dot org
i am experiencing the same bug with php 4.2.1 under win98. 
Just tried latest CVS (4.3.0-dev, build today) and it's still there. 

applying christophe's patch to network.c (php_sockread_internal() has been moved from fsock.c to php_sock_stream_read_internal() in network.c) seems to solve the bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC