note 21856 added to ref.pcntl

From: Date: Wed, 29 May 2002 14:10:16 +0000
Subject: note 21856 added to ref.pcntl
Groups: php.notes 
Request: Send a blank email to php-notes+get-31150@lists.php.net to get a copy of this message
You have to use socket_select before socket_accept, so your code will wait for connection with select. socket_select can be interrupted by signals easily. Below is an example from my library (methods of class TNetSocket): //-- select function select($aread=NULL,$awrite=NULL,$aexcept=NULL,$timeout=NULL) { while(1) { $res=""; $res=socket_select($aread, $awrite, $aexcept, $timeout); // if errno===0 it means what select was interrrupted by SysV signal if($res===false && socket_last_error($this->socket())!==0) { // error occured, interrupted not by a signal $this->set_socket_error(__LINE__); return(false); } break; } return(true); } //-- accept, wait for incomming connection function accept() { $this->clear_socket_error(); $this->set_io_socket(_SOCKET_); $socket=$this->socket(); $aread=array($socket); if ($this->select($a=&$aread)===false) return(false); $child_socket=socket_accept($this->socket); if($child_socket <= 0) { // error occured $this->set_socket_error(__LINE__); return(false); } $this->child_socket=$child_socket; $this->sockets[_CHILD_SOCKET_]=&$this->child_socket; $this->set_io_socket(_CHILD_SOCKET_); $a=&$this->peername; $res=socket_getpeername($child_socket,$a); if($res <= 0) { // error occured $this->set_socket_error(__LINE__); return(false); } $this->get_address_and_port(_CHILD_SOCKET_); TLogManager::phpserv("Connection accepted. ADDRESS $this->address, PORT $this->port","net_socket",__FILE__,__LINE__); $this->connected=true; return(true); // return new object of TNetSocket type } -- http://www.php.net/manual/en/ref.pcntl.php http://master.php.net/manage/user-notes.php?action=edit+21856 http://master.php.net/manage/user-notes.php?action=delete+21856 http://master.php.net/manage/user-notes.php?action=reject+21856

« previous php.notes (#31150) next »