@@ -801,15 +801,22 @@ PHPAPI int php_network_get_sock_name(php_socket_t sock,
801801 * version of the address will be emalloc'd and returned.
802802 * */
803803
804- /* {{{ php_network_accept_incoming */
805- PHPAPI php_socket_t php_network_accept_incoming (php_socket_t srvsock ,
804+ /* Accept a client connection from a server socket,
805+ * using an optional timeout.
806+ * Returns the peer address in addr/addrlen (it will emalloc
807+ * these, so be sure to efree the result).
808+ * If you specify textaddr, a text-printable
809+ * version of the address will be emalloc'd and returned.
810+ * */
811+
812+ PHPAPI php_socket_t php_network_accept_incoming_ex (php_socket_t srvsock ,
806813 zend_string * * textaddr ,
807814 struct sockaddr * * addr ,
808815 socklen_t * addrlen ,
809816 struct timeval * timeout ,
810817 zend_string * * error_string ,
811818 int * error_code ,
812- int tcp_nodelay
819+ php_sockvals * sockvals
813820 )
814821{
815822 php_socket_t clisock = -1 ;
@@ -833,11 +840,19 @@ PHPAPI php_socket_t php_network_accept_incoming(php_socket_t srvsock,
833840 textaddr ,
834841 addr , addrlen
835842 );
836- if (tcp_nodelay ) {
837843#ifdef TCP_NODELAY
844+ if (PHP_SOCKVAL_IS_SET (sockvals , PHP_SOCKVAL_TCP_NODELAY )) {
845+ int tcp_nodelay = 1 ;
838846 setsockopt (clisock , IPPROTO_TCP , TCP_NODELAY , (char * )& tcp_nodelay , sizeof (tcp_nodelay ));
847+ }
839848#endif
849+ #ifdef TCP_KEEPALIVE
850+ /* MacOS does not inherit TCP_KEEPALIVE so it needs to be set */
851+ if (PHP_SOCKVAL_IS_SET (sockvals , PHP_SOCKVAL_TCP_KEEPIDLE )) {
852+ setsockopt (clisock , IPPROTO_TCP , TCP_KEEPALIVE ,
853+ (char * )& sockvals -> keepalive .keepidle , sizeof (sockvals -> keepalive .keepidle ));
840854 }
855+ #endif
841856 } else {
842857 error = php_socket_errno ();
843858 }
@@ -852,7 +867,22 @@ PHPAPI php_socket_t php_network_accept_incoming(php_socket_t srvsock,
852867
853868 return clisock ;
854869}
855- /* }}} */
870+
871+ PHPAPI php_socket_t php_network_accept_incoming (php_socket_t srvsock ,
872+ zend_string * * textaddr ,
873+ struct sockaddr * * addr ,
874+ socklen_t * addrlen ,
875+ struct timeval * timeout ,
876+ zend_string * * error_string ,
877+ int * error_code ,
878+ int tcp_nodelay
879+ )
880+ {
881+ php_sockvals sockvals = { .mask = tcp_nodelay ? PHP_SOCKVAL_TCP_NODELAY : 0 };
882+
883+ return php_network_accept_incoming_ex (srvsock , textaddr , addr , addrlen , timeout , error_string ,
884+ error_code , & sockvals );
885+ }
856886
857887/* Connect to a remote host using an interruptible connect with optional timeout.
858888 * Optionally, the connect can be made asynchronously, which will implicitly
0 commit comments