static size_t socket_info_max = 0;
+/*
+ * Allocate the socket array always on the limit value. We want it to be
+ * at least bigger than the default so if we reach the limit we can
+ * still deal with duplicate fds pointing to the same socket_info.
+ */
+static size_t socket_fds_max = SOCKET_WRAPPER_MAX_SOCKETS_LIMIT;
+
/* Hash table to map fds to corresponding socket_info index */
static int *socket_fds_idx;
return;
}
- tmp = (int *)calloc(SOCKET_WRAPPER_MAX_SOCKETS_DEFAULT, sizeof(int));
+ tmp = (int *)calloc(socket_fds_max, sizeof(int));
if (tmp == NULL) {
SWRAP_LOG(SWRAP_LOG_ERROR,
"Failed to allocate socket fds index array: %s",
exit(-1);
}
- for (i = 0; i < SOCKET_WRAPPER_MAX_SOCKETS_DEFAULT; i++) {
+ for (i = 0; i < socket_fds_max; i++) {
tmp[i] = -1;
}
return -1;
}
- if (fd >= SOCKET_WRAPPER_MAX_SOCKETS_DEFAULT) {
+ if (fd >= socket_fds_max) {
SWRAP_LOG(SWRAP_LOG_ERROR,
- "The max socket index limit of %u has been reached, "
+ "The max socket index limit of %zu has been reached, "
"trying to add %d",
- SOCKET_WRAPPER_MAX_SOCKETS_DEFAULT,
+ socket_fds_max,
fd);
return -1;
}
{
int idx;
- if (fd >= SOCKET_WRAPPER_MAX_SOCKETS_DEFAULT) {
+ if (fd >= socket_fds_max) {
SWRAP_LOG(SWRAP_LOG_ERROR,
- "The max socket index limit of %u has been reached, "
+ "The max socket index limit of %zu has been reached, "
"trying to add %d",
- SOCKET_WRAPPER_MAX_SOCKETS_DEFAULT,
+ socket_fds_max,
fd);
return -1;
}
size_t i;
if (socket_fds_idx != NULL) {
- for (i = 0; i < SOCKET_WRAPPER_MAX_SOCKETS_DEFAULT; ++i) {
+ for (i = 0; i < socket_fds_max; ++i) {
if (socket_fds_idx[i] != -1) {
swrap_close(i);
}