| 1818 | } |
| 1819 | |
| 1820 | static void open_socket(struct conn *c) |
| 1821 | { |
| 1822 | if (is_sink) { |
| 1823 | pthread_mutex_lock(&thread_lock); |
| 1824 | open_conns++; |
| 1825 | pthread_mutex_unlock(&thread_lock); |
| 1826 | |
| 1827 | submit_receive(&c->ring, c); |
| 1828 | } else { |
| 1829 | struct io_uring_sqe *sqe; |
| 1830 | int domain; |
| 1831 | |
| 1832 | if (ipv6) |
| 1833 | domain = AF_INET6; |
| 1834 | else |
| 1835 | domain = AF_INET; |
| 1836 | |
| 1837 | /* |
| 1838 | * If fixed_files is set, proxy will use fixed files for any new |
| 1839 | * file descriptors it instantiates. Fixd files, or fixed |
| 1840 | * descriptors, are io_uring private file descriptors. They |
| 1841 | * cannot be accessed outside of io_uring. io_uring holds a |
| 1842 | * fixed reference to them, which means that we do not need to |
| 1843 | * grab per-request references to them. Particularly for |
| 1844 | * threaded applications, grabbing and dropping file references |
| 1845 | * for each operation can be costly as the file table is shared. |
| 1846 | * This generally shows up as fget/fput related overhead in any |
| 1847 | * workload profiles. |
| 1848 | * |
| 1849 | * Fixed descriptors are passed in via the 'fd' field just like |
| 1850 | * regular descriptors, and then marked as such by setting the |
| 1851 | * IOSQE_FIXED_FILE flag in the sqe->flags field. Some helpers |
| 1852 | * do that automatically, like the below, others will need it |
| 1853 | * set manually if they don't have a *direct*() helper. |
| 1854 | * |
| 1855 | * For operations that instantiate them, like the opening of a |
| 1856 | * direct socket, the application may either ask the kernel to |
| 1857 | * find a free one (as is done below), or the application may |
| 1858 | * manage the space itself and pass in an index for a currently |
| 1859 | * free slot in the table. If the kernel is asked to allocate a |
| 1860 | * free direct descriptor, note that io_uring does not abide by |
| 1861 | * the POSIX mandated "lowest free must be returned". It may |
| 1862 | * return any free descriptor of its choosing. |
| 1863 | */ |
| 1864 | sqe = get_sqe(&c->ring); |
| 1865 | if (fixed_files) |
| 1866 | io_uring_prep_socket_direct_alloc(sqe, domain, SOCK_STREAM, 0, 0); |
| 1867 | else |
| 1868 | io_uring_prep_socket(sqe, domain, SOCK_STREAM, 0, 0); |
| 1869 | encode_userdata(sqe, c, __SOCK, 0, 0); |
| 1870 | } |
| 1871 | } |
| 1872 | |
| 1873 | /* |
| 1874 | * Start of connection, we got our in descriptor. |
no test coverage detected