We are getting file descriptor (FD) value using the below BSD socket API in iOS 13.0+ devices.
fd = ::socket(ipVer == V4 ? PF_INET : PF_INET6, SOCK_STREAM, 0);
In our app, we use this to create a TLS connection in regular intervals, and we always close the previous connection before executing this. in this situation, we found sometimes the same FD value was returned in a subsequent execution of this socket API. Like FD value is getting value 27 in subsequent execution, But sometimes it keeps increasing and it exceeds 1024 value which is making socket execution blocked.
- What is the logic in iOS for setting this FD value?
- Even though we close the previous socket why FD value keep on increasing?
- Is there any way to control the MAX FD value, as it will never exceed 1000?
- Is there any relation with server and client connection time period, which may cause the FD value increase on the client-side in each new set of TLS connections by using the socket method even though the previous socket was closed?
Note: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/FD_SET.2.html The default size FD_SETSIZE (currently 1024) is somewhat smaller than the current kernel limit to the number of open files. However, in order to accommodate programs that might potentially use a larger number of open files with select, it is possible to increase this size within a program by providing a larger definition of FD_SETSIZE before the inclusion of <sys/types.h>.
- How to increase the limit of FD_SETSIZE beyond 1024 through overriding the FD_SetSize defined in the sys/types.h?