Mercurial > dovecot > core-2.2
diff src/lib/network.c @ 11794:5ea9394b5ced
liblib: Added net_connect_ip_blocking().
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 12 Jul 2010 00:32:30 +0100 |
parents | c24ee1ebb159 |
children | 4fb7e5327efc |
line wrap: on
line diff
--- a/src/lib/network.c Mon Jul 12 00:17:18 2010 +0100 +++ b/src/lib/network.c Mon Jul 12 00:32:30 2010 +0100 @@ -163,8 +163,8 @@ static #endif -int net_connect_ip(const struct ip_addr *ip, unsigned int port, - const struct ip_addr *my_ip) +static int net_connect_ip_full(const struct ip_addr *ip, unsigned int port, + const struct ip_addr *my_ip, bool blocking) { union sockaddr_union so; int fd, ret, opt = 1; @@ -187,7 +187,8 @@ /* set socket options */ setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof(opt)); - net_set_nonblock(fd, TRUE); + if (!blocking) + net_set_nonblock(fd, TRUE); /* set our own address */ if (my_ip != NULL) { @@ -217,6 +218,18 @@ return fd; } +int net_connect_ip(const struct ip_addr *ip, unsigned int port, + const struct ip_addr *my_ip) +{ + return net_connect_ip_full(ip, port, my_ip, FALSE); +} + +int net_connect_ip_blocking(const struct ip_addr *ip, unsigned int port, + const struct ip_addr *my_ip) +{ + return net_connect_ip_full(ip, port, my_ip, TRUE); +} + int net_try_bind(const struct ip_addr *ip) { union sockaddr_union so;