Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding network-wait-timeout support #1573

Open
wants to merge 1 commit into
base: dnf-4-master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions libdnf/dnf-context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ typedef struct
gchar *user_agent;
gchar *arch;
guint cache_age; /*seconds*/
guint network_wait_timeout_secs;
gboolean cacheOnly{false};
gboolean check_disk_space;
gboolean check_transaction;
Expand Down Expand Up @@ -1106,6 +1107,22 @@ dnf_context_get_cache_age(DnfContext *context)
return priv->cache_age;
}

/**
* dnf_context_get_network_timeout_seconds:
* @context: a #DnfContext instance.
*
* Gets the number seconds to wait for the network timeout.
*
* Returns: network timout in seconds
*
**/
guint
dnf_context_get_network_timeout_seconds(DnfContext *context)
{
DnfContextPrivate *priv = GET_PRIVATE(context);
return priv->network_wait_timeout_secs;
}

/**
* dnf_context_get_installonly_pkgs:
* @context: a #DnfContext instance.
Expand Down Expand Up @@ -1634,6 +1651,20 @@ dnf_context_set_cache_age(DnfContext *context, guint cache_age)
priv->cache_age = cache_age;
}

/**
* dnf_context_set_network_timeout_seconds:
* @context: a #DnfContext instance.
* @seconds: Number of seconds
*
* Sets the number of seconds to wait till network timeout.
**/
void
dnf_context_set_network_timeout_seconds(DnfContext *context, guint seconds)
{
DnfContextPrivate *priv = GET_PRIVATE(context);
priv->network_wait_timeout_secs = seconds;
}

/**
* dnf_context_set_os_release:
**/
Expand Down
3 changes: 3 additions & 0 deletions libdnf/dnf-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ gboolean dnf_context_get_zchunk (DnfContext *context
gboolean dnf_context_get_write_history (DnfContext *context);
guint dnf_context_get_cache_age (DnfContext *context);
guint dnf_context_get_installonly_limit (DnfContext *context);
guint dnf_context_get_network_timeout_seconds(DnfContext *context);
const gchar *dnf_context_get_http_proxy (DnfContext *context);
gboolean dnf_context_get_enable_filelists (DnfContext *context);
GPtrArray *dnf_context_get_repos (DnfContext *context);
Expand Down Expand Up @@ -205,6 +206,8 @@ void dnf_context_set_write_history (DnfContext *context
gboolean value);
void dnf_context_set_cache_age (DnfContext *context,
guint cache_age);
void dnf_context_set_network_timeout_seconds(DnfContext *context,
guint seconds);

void dnf_context_set_rpm_macro (DnfContext *context,
const gchar *key,
Expand Down
8 changes: 8 additions & 0 deletions libdnf/dnf-repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,10 @@ dnf_repo_update(DnfRepo *repo,
goto out;
}

ret = lr_handle_network_wait(priv->repo_handle, error, dnf_context_get_network_timeout_seconds(priv->context), NULL);
if(!ret)
goto out;

lr_result_clear(priv->repo_result);
dnf_state_action_start(state_local,
DNF_STATE_ACTION_DOWNLOAD_METADATA, NULL);
Expand Down Expand Up @@ -2247,6 +2251,10 @@ dnf_repo_download_packages(DnfRepo *repo,
directory_slash = g_build_filename(directory, "/", NULL);
}

ret = lr_handle_network_wait(priv->repo_handle, error, dnf_context_get_network_timeout_seconds(priv->context), NULL);
if(!ret)
goto out;

global_data.download_size = dnf_package_array_get_download_size(packages);
for (i = 0; i < packages->len; i++) {
auto pkg = static_cast<DnfPackage *>(packages->pdata[i]);
Expand Down