+static gpointer
+directtcp_listen_thread(
+ gpointer data)
+{
+ XferSourceRecovery *self = XFER_SOURCE_RECOVERY(data);
+ XferElement *elt = XFER_ELEMENT(self);
+ int result;
+
+ DBG(1, "(this is directtcp_listen_thread)");
+
+ /* we need to make an outgoing connection to downstream; we do this while
+ * holding the start_part_mutex, so that a part doesn't get started until
+ * we're finished with the device */
+ g_mutex_lock(self->start_part_mutex);
+
+ if (elt->cancelled) {
+ g_mutex_unlock(self->start_part_mutex);
+ goto send_done;
+ }
+
+ g_assert(self->device != NULL); /* have a device */
+ g_assert(elt->downstream->input_listen_addrs != NULL); /* downstream listening */
+
+ DBG(2, "making DirectTCP connection on device %s", self->device->device_name);
+ result = device_connect(self->device, FALSE,
+ elt->downstream->input_listen_addrs,
+ &self->conn, &elt->cancelled,
+ self->start_part_mutex, self->abort_cond);
+ if (result == 1 && !elt->cancelled) {
+ xfer_cancel_with_error(elt,
+ _("error making DirectTCP connection: %s"),
+ device_error_or_status(self->device));
+ g_mutex_unlock(self->start_part_mutex);
+ wait_until_xfer_cancelled(elt->xfer);
+ goto send_done;
+ } else if (result == 2 || elt->cancelled) {
+ g_mutex_unlock(self->start_part_mutex);
+ wait_until_xfer_cancelled(elt->xfer);
+ goto send_done;
+ }
+ DBG(2, "DirectTCP connect succeeded");
+
+ return directtcp_common_thread(self);
+
+send_done:
+ xfer_queue_message(elt->xfer, xmsg_new(elt, XMSG_DONE, 0));