× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hello,

Am 02.01.2022 um 18:59 schrieb Patrik Schindler <poc@xxxxxxxxxx>:

Aside from creating a loop in my applications to simply try again to allocate a socket and sleep some seconds after failure, instead of just exiting — which other options can you recommend?

Thanks for all who responded with ideas.

I'll take the route described above. It seems to be the most clean one to me. A long sleep has the disadvantage to delay overall IPL time or at least the SBS start. Pinging localhost would be another approach, but just trying socket() with a 1 second sleep in between is done easier than an external ping, code-wise.

Code-Snippets for the interested:


Before:
if ( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) {
Qp0zLprintf("socket(): %s", strerror(errno));
exit(1);
}


After:
/* Keep trying to socket for 15 mins, so TCP/IP has enough time to start. */
for ( i = 0; i++; i <= 900 ) {
if ( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) {
sleep(1);
} else {
Qp0zLprintf("socket() succeeded after %d tries.\n", i);
break;
}
}
if ( i >= 900 ) {
Qp0zLprintf("Tried socket() %d times, giving up. Last error was %s.\n",
i, strerror(errno));
exit(1);
}

:wq! PoC


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.