track total number of open sockets, and print "too many sockets" if
there are too many
int alloc_id;
int num_outgoing;
int last_recv;
+ int num_sockets;
fr_packet_socket_t sockets[MAX_SOCKETS];
};
{
fr_packet_socket_t *ps;
- if (!pl) return 0;
+ if (!pl) {
+ fr_strerror_printf("Invalid argument");
+ return 0;
+ }
ps = fr_socket_find(pl, sockfd);
- if (!ps) return 0;
+ if (!ps) {
+ fr_strerror_printf("No such socket");
+ return 0;
+ }
ps->dont_use = 1;
return 1;
if (ps->num_outgoing != 0) return 0;
ps->sockfd = -1;
+ pl->num_sockets--;
if (pctx) *pctx = ps->ctx;
return 1;
return 0;
}
+ if (pl->num_sockets >= MAX_SOCKETS) {
+ fr_strerror_printf("Too many open sockets");
+ return 0;
+ }
+
ps = NULL;
i = start = SOCK2OFFSET(sockfd);
* As the last step before returning.
*/
ps->sockfd = sockfd;
+ pl->num_sockets++;
return 1;
}