Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6876:ed6693fc06d6 HEAD
FreeBSD: If connect() fails with EADDRINUSE or EACCES, try again max. 3 times.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 29 Nov 2007 07:23:48 +0200 |
parents | a9e4221d5c0b |
children | a5a7d38b6df7 |
files | src/lib/network.c |
diffstat | 1 files changed, 29 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/network.c Thu Nov 29 07:21:58 2007 +0200 +++ b/src/lib/network.c Thu Nov 29 07:23:48 2007 +0200 @@ -129,6 +129,35 @@ return 0; } +#ifdef __FreeBSD__ +static int net_connect_ip_freebsd(const struct ip_addr *ip, unsigned int port, + const struct ip_addr *my_ip); + +int net_connect_ip(const struct ip_addr *ip, unsigned int port, + const struct ip_addr *my_ip) +{ + int fd, try; + + for (try = 0;;) { + fd = net_connect_ip_freebsd(ip, port, my_ip); + if (fd != -1 || ++try == 5 || + (errno != EADDRINUSE && errno != EACCES)) + break; + /* + This may be just a temporary problem: + + EADDRINUSE: busy + EACCES: pf may cause this if another connection used + the same port recently + */ + } + return fd; +} +/* then some kludging: */ +#define net_connect_ip net_connect_ip_freebsd +static +#endif + int net_connect_ip(const struct ip_addr *ip, unsigned int port, const struct ip_addr *my_ip) {