|
55 | 55 | # if HAVE_IF_NAMETOINDEX
|
56 | 56 | # include <net/if.h>
|
57 | 57 | # endif
|
| 58 | +# ifdef SO_MEMINFO |
| 59 | +# include <linux/sock_diag.h> |
| 60 | +# endif |
58 | 61 | #endif
|
59 | 62 |
|
60 | 63 | #include <stddef.h>
|
@@ -550,6 +553,9 @@ static PHP_MINIT_FUNCTION(sockets)
|
550 | 553 | #ifdef SO_INCOMING_CPU
|
551 | 554 | REGISTER_LONG_CONSTANT("SO_INCOMING_CPU", SO_INCOMING_CPU, CONST_CS | CONST_PERSISTENT);
|
552 | 555 | #endif
|
| 556 | +#ifdef SO_MEMINFO |
| 557 | + REGISTER_LONG_CONSTANT("SO_MEMINFO", SO_MEMINFO, CONST_CS | CONST_PERSISTENT); |
| 558 | +#endif |
553 | 559 | #ifdef TCP_NODELAY
|
554 | 560 | REGISTER_LONG_CONSTANT("TCP_NODELAY", TCP_NODELAY, CONST_CS | CONST_PERSISTENT);
|
555 | 561 | #endif
|
@@ -1833,6 +1839,37 @@ PHP_FUNCTION(socket_get_option)
|
1833 | 1839 | add_assoc_long(return_value, "sec", tv.tv_sec);
|
1834 | 1840 | add_assoc_long(return_value, "usec", tv.tv_usec);
|
1835 | 1841 | return;
|
| 1842 | +#ifdef SO_MEMINFO |
| 1843 | + case SO_MEMINFO: { |
| 1844 | + uint32_t minfo[SK_MEMINFO_VARS]; |
| 1845 | + optlen = sizeof(minfo); |
| 1846 | + |
| 1847 | + if (getsockopt(php_sock->bsd_socket, level, optname, (char*)minfo, &optlen) != 0) { |
| 1848 | + PHP_SOCKET_ERROR(php_sock, "Unable to retrieve socket option", errno); |
| 1849 | + RETURN_FALSE; |
| 1850 | + } |
| 1851 | + |
| 1852 | + if (UNEXPECTED(optlen != sizeof(minfo))) { |
| 1853 | + // unlikely since the kernel fills up the whole array if getsockopt succeeded |
| 1854 | + // but just an extra precaution in case. |
| 1855 | + php_error_docref(NULL, E_WARNING, "Unable to retrieve all socket meminfo data"); |
| 1856 | + RETURN_FALSE; |
| 1857 | + } |
| 1858 | + |
| 1859 | + array_init(return_value); |
| 1860 | + |
| 1861 | + add_assoc_long(return_value, "rmem_alloc", minfo[SK_MEMINFO_RMEM_ALLOC]); |
| 1862 | + add_assoc_long(return_value, "rcvbuf", minfo[SK_MEMINFO_RCVBUF]); |
| 1863 | + add_assoc_long(return_value, "wmem_alloc", minfo[SK_MEMINFO_WMEM_ALLOC]); |
| 1864 | + add_assoc_long(return_value, "sndbuf", minfo[SK_MEMINFO_SNDBUF]); |
| 1865 | + add_assoc_long(return_value, "fwd_alloc", minfo[SK_MEMINFO_FWD_ALLOC]); |
| 1866 | + add_assoc_long(return_value, "wmem_queued", minfo[SK_MEMINFO_WMEM_QUEUED]); |
| 1867 | + add_assoc_long(return_value, "optmem", minfo[SK_MEMINFO_OPTMEM]); |
| 1868 | + add_assoc_long(return_value, "backlog", minfo[SK_MEMINFO_BACKLOG]); |
| 1869 | + add_assoc_long(return_value, "drops", minfo[SK_MEMINFO_DROPS]); |
| 1870 | + return; |
| 1871 | + } |
| 1872 | +#endif |
1836 | 1873 | #ifdef SO_ACCEPTFILTER
|
1837 | 1874 | case SO_ACCEPTFILTER: {
|
1838 | 1875 |
|
|
0 commit comments