Skip to content

Commit 84dc94f

Browse files
committed
dnf-context.cpp: Added network_wait seconds to struct DnfContext and implemented getters
and setters for it dnf-repo.cpp: Call to librepo for network wait api call Adding network wait support by callin in API's from librepo
1 parent 6529773 commit 84dc94f

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
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_cache_age:
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: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,7 @@ dnf_repo_update(DnfRepo *repo,
17641764
/* ensure we set the values from the keyfile */
17651765
if (!dnf_repo_set_keyfile_data(repo, TRUE, error))
17661766
return FALSE;
1767-
1767+
17681768
/* countme support */
17691769
libdnf::repoGetImpl(priv->repo)->addCountmeFlag(priv->repo_handle);
17701770

@@ -1866,10 +1866,14 @@ dnf_repo_update(DnfRepo *repo,
18661866
goto out;
18671867
}
18681868

1869+
ret = lr_handle_setopt(priv->repo_handle, error, LRO_NETWORK_WAIT, dnf_context_get_network_timeout_seconds(priv->context));
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);
1872-
ret = lr_handle_perform(priv->repo_handle,
1876+
ret = lr_handle_perform(priv->repo_handle,
18731877
priv->repo_result,
18741878
&error_local);
18751879
if (!ret) {
@@ -2247,6 +2251,12 @@ dnf_repo_download_packages(DnfRepo *repo,
22472251
directory_slash = g_build_filename(directory, "/", NULL);
22482252
}
22492253

2254+
ret = lr_handle_setopt(priv->repo_handle, error,
2255+
LRO_NETWORK_WAIT, dnf_context_get_network_timeout_seconds(priv->context));
2256+
2257+
if(!ret)
2258+
goto out;
2259+
22502260
global_data.download_size = dnf_package_array_get_download_size(packages);
22512261
for (i = 0; i < packages->len; i++) {
22522262
auto pkg = static_cast<DnfPackage *>(packages->pdata[i]);

0 commit comments

Comments
 (0)