dovecot-2.0: liblib: Added net_connect_ip_blocking().
dovecot at dovecot.org
dovecot at dovecot.org
Mon Jul 12 02:33:16 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/5ea9394b5ced
changeset: 11794:5ea9394b5ced
user: Timo Sirainen <tss at iki.fi>
date: Mon Jul 12 00:32:30 2010 +0100
description:
liblib: Added net_connect_ip_blocking().
diffstat:
src/lib/network.c | 19 ++++++++++++++++---
src/lib/network.h | 6 +++++-
2 files changed, 21 insertions(+), 4 deletions(-)
diffs (61 lines):
diff -r 24e92489d7b7 -r 5ea9394b5ced src/lib/network.c
--- 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;
diff -r 24e92489d7b7 -r 5ea9394b5ced src/lib/network.h
--- a/src/lib/network.h Mon Jul 12 00:17:18 2010 +0100
+++ b/src/lib/network.h Mon Jul 12 00:32:30 2010 +0100
@@ -47,9 +47,13 @@
int net_ip_cmp(const struct ip_addr *ip1, const struct ip_addr *ip2);
unsigned int net_ip_hash(const struct ip_addr *ip);
-/* Connect to socket with ip address */
+/* Connect to socket with ip address. The socket and connect() is
+ non-blocking. */
int net_connect_ip(const struct ip_addr *ip, unsigned int port,
const struct ip_addr *my_ip);
+/* Like net_connect_ip(), but do a blocking connect(). */
+int net_connect_ip_blocking(const struct ip_addr *ip, unsigned int port,
+ const struct ip_addr *my_ip);
/* Returns 0 if we can bind() as given IP, -1 if not. */
int net_try_bind(const struct ip_addr *ip);
/* Connect to named UNIX socket */
More information about the dovecot-cvs
mailing list