Edit report at https://bugs.php.net/bug.php?id=65260&edit=1
ID: 65260 Comment by: bugs dot php dot net at ss dot chernousov dot net Reported by: bugs dot php dot net at ss dot chernousov dot net Summary: socket_sendmsg/socket_recvmsg wrong number of file descriptors Status: Feedback Type: Bug Package: Sockets related Operating System: Gentoo Linux PHP Version: 5.5.0 Assigned To: cataphract Block user comment: N Private report: N New Comment: Works like a charm to me. Thank you so much. Previous Comments: ------------------------------------------------------------------------ [2013-07-14 23:54:43] cataphr...@php.net Can you test this branch: https://github.com/cataphract/php-src/tree/bug65260 ? Thanks ------------------------------------------------------------------------ [2013-07-14 09:10:18] bugs dot php dot net at ss dot chernousov dot net Description: ------------ Regardless of how many file descriptors were sent with socket_sendmsg(), socket_recvmsg() always receives fd/0 as the very first descriptor (even if it wasn't sent at all) and then maximum two descriptors that were really sent. Test script sends one descriptor $fd, but receives two, as described above. If we add more descriptors to send (let's say 5, and change third argument of socket_cmsg_space() to 5), only first two will be actually received, and extra fd/0 will precede them. I know these functions are still experimental, but they are like a manna from heaven many backend php-developers were seeking. Test script: --------------- https://gist.github.com/5lava/5993637 Similar PHP test https://github.com/cataphract/php-src/blob/sendrecvmsg/ext/sockets/tests/socket_cmsg_rights.phpt taken from here: https://wiki.php.net/rfc/sendrecvmsg Expected result: ---------------- One new file descriptors should be added after socket_recvmsg() call. Actual result: -------------- Two new file descriptors added. First is always referencing fd/0, and 2nd is the one which was actually sent. File descriptors before socket_recvmsg() call: 0 -> /etc/passwd <--- reopened fd/0 1 -> /dev/pts/3 <--- stdout 2 -> /dev/pts/3 <--- stderr 3 -> socket:[5819664] <--- $send_s 4 -> socket:[5819665] <--- $recv_s 5 -> /etc/group <--- $fd - the one we want to send 6 -> pipe:[5819666] <--- passthru() pipe File descriptors after socket_recvmsg() call: 0 -> /etc/passwd <--- reopened fd/0 1 -> /dev/pts/3 <--- stdout 2 -> /dev/pts/3 <--- stderr 3 -> socket:[5819664] <--- $send_s 4 -> socket:[5819665] <--- $recv_s 5 -> /etc/group <--- $fd - the one we sent 6 -> /etc/passwd <--- always the same as fd/0 - shouldn't be here at all 7 -> /etc/group <--- that's the only one we expected to receive 6 -> pipe:[5819666] <--- passthru() pipe $data contains two Resources: Array ( ... [control] => [0] => [data] => Array ( [0] => Resource id #10 [1] => Resource id #11 ) ... ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65260&edit=1