Skip to content

Commit 27dcc91

Browse files
committed
dnf-context: Modify DnfContext struct to support timeout and
implemented getters and setters for it dnf-repo: Call to librepo for network wait api call Add network-wait support by calling in API's from librepo
1 parent 8913804 commit 27dcc91

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

libdnf/dnf-context.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ typedef struct
158158
gchar *user_agent;
159159
gchar *arch;
160160
guint cache_age; /*seconds*/
161+
guint network_wait_timeout_secs;
161162
gboolean cacheOnly{false};
162163
gboolean check_disk_space;
163164
gboolean check_transaction;
@@ -1106,6 +1107,22 @@ dnf_context_get_cache_age(DnfContext *context)
11061107
return priv->cache_age;
11071108
}
11081109

1110+
/**
1111+
* dnf_context_get_network_timeout_seconds:
1112+
* @context: a #DnfContext instance.
1113+
*
1114+
* Gets the number seconds to wait for the network timeout.
1115+
*
1116+
* Returns: network timout in seconds
1117+
*
1118+
**/
1119+
guint
1120+
dnf_context_get_network_timeout_seconds(DnfContext *context)
1121+
{
1122+
DnfContextPrivate *priv = GET_PRIVATE(context);
1123+
return priv->network_wait_timeout_secs;
1124+
}
1125+
11091126
/**
11101127
* dnf_context_get_installonly_pkgs:
11111128
* @context: a #DnfContext instance.
@@ -1634,6 +1651,20 @@ dnf_context_set_cache_age(DnfContext *context, guint cache_age)
16341651
priv->cache_age = cache_age;
16351652
}
16361653

1654+
/**
1655+
* dnf_context_set_network_timeout_seconds:
1656+
* @context: a #DnfContext instance.
1657+
* @seconds: Number of seconds
1658+
*
1659+
* Sets the number of seconds to wait till network timeout.
1660+
**/
1661+
void
1662+
dnf_context_set_network_timeout_seconds(DnfContext *context, guint seconds)
1663+
{
1664+
DnfContextPrivate *priv = GET_PRIVATE(context);
1665+
priv->network_wait_timeout_secs = seconds;
1666+
}
1667+
16371668
/**
16381669
* dnf_context_set_os_release:
16391670
**/

libdnf/dnf-context.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ gboolean dnf_context_get_zchunk (DnfContext *context
142142
gboolean dnf_context_get_write_history (DnfContext *context);
143143
guint dnf_context_get_cache_age (DnfContext *context);
144144
guint dnf_context_get_installonly_limit (DnfContext *context);
145+
guint dnf_context_get_network_timeout_seconds(DnfContext *context);
145146
const gchar *dnf_context_get_http_proxy (DnfContext *context);
146147
gboolean dnf_context_get_enable_filelists (DnfContext *context);
147148
GPtrArray *dnf_context_get_repos (DnfContext *context);
@@ -205,6 +206,8 @@ void dnf_context_set_write_history (DnfContext *context
205206
gboolean value);
206207
void dnf_context_set_cache_age (DnfContext *context,
207208
guint cache_age);
209+
void dnf_context_set_network_timeout_seconds(DnfContext *context,
210+
guint seconds);
208211

209212
void dnf_context_set_rpm_macro (DnfContext *context,
210213
const gchar *key,

libdnf/dnf-repo.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,6 +1866,10 @@ dnf_repo_update(DnfRepo *repo,
18661866
goto out;
18671867
}
18681868

1869+
ret = lr_handle_network_wait(priv->repo_handle, error, dnf_context_get_network_timeout_seconds(priv->context), NULL);
1870+
if(!ret)
1871+
goto out;
1872+
18691873
lr_result_clear(priv->repo_result);
18701874
dnf_state_action_start(state_local,
18711875
DNF_STATE_ACTION_DOWNLOAD_METADATA, NULL);
@@ -2247,6 +2251,10 @@ dnf_repo_download_packages(DnfRepo *repo,
22472251
directory_slash = g_build_filename(directory, "/", NULL);
22482252
}
22492253

2254+
ret = lr_handle_network_wait(priv->repo_handle, error, dnf_context_get_network_timeout_seconds(priv->context), NULL);
2255+
if(!ret)
2256+
goto out;
2257+
22502258
global_data.download_size = dnf_package_array_get_download_size(packages);
22512259
for (i = 0; i < packages->len; i++) {
22522260
auto pkg = static_cast<DnfPackage *>(packages->pdata[i]);

0 commit comments

Comments
 (0)