| 195 번 글: [PHP] socket_connect_status |
| 글쓴이: 산이
[홈페이지]
|
글쓴날: 2009년 01월 27일 20:41:33 화(저녁) |
조회: 2839 |
php socket 관련 함수중에서 socket 상태를 체크하는 함수가
없어서...
get_socket_status() 의 파라메타는 stream 이기 때문에 socket 을
파라메터로 사용할 수 없음
----------------------------------
## chkeck socket is ESTABLISHED ?
## return value
## -1 : $sock is empty or is not resource
## 0 : $sock event happend(is not ESTABLISHED)
## 1 : $sock is ESTABLISHED
##
function socket_connect_status(&$sock)
{
if(!$sock || !@is_resource($sock)) return -1;
## 0 Success
## 1 Operation not permitted
## 56 Socket is already connected
## 106 Transport endpoint is already connected
##
$ecode = @socket_last_error($sock);
if($ecode!=106 && $ecode!=56) return 0; // is not connected
$r = array($sock);
$s = @socket_select($r,$w=NULL,$e=NULL,0);
## $s === 0 nothing interesting happened => ESTABLISHED
## $s > 0 some something interesting happened
## $s === FALSE socket_select() error
##
return ($s===0) ? 1 : 0;
}
----------------------------------
|
이전글 : [PHP] imitative Async I/O non-block exec
다음글 : [C] libevent 사용예제
|
from 211.212.239.50
JS(Redhands)Board 0.4 +@
|