X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=ndmp-src%2Fndmpconnobj.c;h=1fe040a922b6548e75f077f33bcc502f82118de6;hb=3f2539260c201b5e594bf8ce89b583ebde6a63d1;hp=d5a5bf2bb3b7677bfb4558e4be7644727578c187;hpb=fd48f3e498442f0cbff5f3606c7c403d0566150e;p=debian%2Famanda diff --git a/ndmp-src/ndmpconnobj.c b/ndmp-src/ndmpconnobj.c index d5a5bf2..1fe040a 100644 --- a/ndmp-src/ndmpconnobj.c +++ b/ndmp-src/ndmpconnobj.c @@ -19,6 +19,7 @@ */ #include "amanda.h" +#include "sockaddr-util.h" #include "ndmpconnobj.h" /* @@ -480,8 +481,9 @@ ndmp_connection_mover_listen( *addrs = g_new0(DirectTCPAddr, naddrs+1); for (i = 0; i < naddrs; i++) { ndmp4_tcp_addr *na = &reply->connect_addr.ndmp4_addr_u.tcp_addr.tcp_addr_val[i]; - (*addrs)[i].ipv4 = na->ip_addr; - (*addrs)[i].port = na->port; + (*addrs)[i].sin.sin_family = AF_INET; + (*addrs)[i].sin.sin_addr.s_addr = htonl(na->ip_addr); + SU_SET_PORT(addrs[i], na->port); } } NDMP_FREE(); @@ -489,6 +491,39 @@ ndmp_connection_mover_listen( return TRUE; } +ndmp_connection_mover_connect( + NDMPConnection *self, + ndmp9_mover_mode mode, + DirectTCPAddr *addrs) +{ + unsigned int naddrs, i; + ndmp4_tcp_addr *na; + + g_assert(!self->startup_err); + + /* count addrs */ + g_assert(addrs); + for (naddrs = 0; SU_GET_FAMILY(&addrs[naddrs]) != 0; naddrs++) ; + + /* convert addrs to an ndmp4_tcp_addr */ + na = g_new0(ndmp4_tcp_addr, naddrs); + for (i = 0; i < naddrs; i++) { + na[i].ip_addr = ntohl(addrs[i].sin.sin_addr.s_addr); + na[i].port = SU_GET_PORT(&addrs[i]); + } + + + NDMP_TRANS(self, ndmp4_mover_connect) + request->mode = mode; + request->addr.addr_type = NDMP4_ADDR_TCP; + request->addr.ndmp4_addr_u.tcp_addr.tcp_addr_len = naddrs; + request->addr.ndmp4_addr_u.tcp_addr.tcp_addr_val = na; + NDMP_CALL(self); + NDMP_FREE(); + NDMP_END + return TRUE; +} + gboolean ndmp_connection_mover_abort( NDMPConnection *self) @@ -643,6 +678,9 @@ ndmp_connection_wait_for_notify( while (1) { gboolean found = FALSE; + int fd; + SELECT_ARG_TYPE readset; + int nfound; /* if any desired notifications have been received, then we're * done */ @@ -671,7 +709,18 @@ ndmp_connection_wait_for_notify( return TRUE; /* otherwise, wait for an incoming packet and handle it, then try - * again */ + * again. There's some select trickery here to avoid hogging the + * ndmlib_mutex - basically, we want to block as long as possible + * outside of the ndmlib_mutex critical section. This will also be + * useful to allow the wait to be aborted. */ + fd = self->conn->chan.fd; + FD_ZERO(&readset); + FD_SET(fd, &readset); + nfound = select(fd+1, &readset, NULL, NULL, NULL); + + /* fall on through, blind to any errors - presumably the same error + * condition will be caught by ndmconn_recv_nmb. */ + g_static_mutex_lock(&ndmlib_mutex); NDMOS_MACRO_ZEROFILL(&nmb); nmb.protocol_version = NDMP4VER;