X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=ndmp-src%2Fndmpconnobj.c;fp=ndmp-src%2Fndmpconnobj.c;h=9f9a45274a615829b9aeb0fb5f92e54350ab3f0a;hb=b116e9366c7b2ea2c2eb53b0a13df4090e176235;hp=d5a5bf2bb3b7677bfb4558e4be7644727578c187;hpb=fd48f3e498442f0cbff5f3606c7c403d0566150e;p=debian%2Famanda diff --git a/ndmp-src/ndmpconnobj.c b/ndmp-src/ndmpconnobj.c index d5a5bf2..9f9a452 100644 --- a/ndmp-src/ndmpconnobj.c +++ b/ndmp-src/ndmpconnobj.c @@ -489,6 +489,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; addrs[naddrs].ipv4; 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 = addrs[i].ipv4; + na[i].port = addrs[i].port; + } + + + 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 +676,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 +707,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;