/* Create new timer event to report daemon status */
{
- struct timeval one_sec = { 1, 0 };
+ struct timeval one_sec = { .tv_sec = 1, .tv_usec = 0 };
status_ev = event_new(ev_base, -1, EV_PERSIST, &periodicUpdate, NULL);
if (status_ev == NULL)
**** PUBLISH
***/
-static tr_tracker_event const TRACKER_EVENT_INIT = { 0, 0, 0, 0, 0, 0 };
+static tr_tracker_event const TRACKER_EVENT_INIT =
+{
+ .messageType = TR_TRACKER_WARNING,
+ .text = NULL,
+ .tracker = NULL,
+ .pex = NULL,
+ .pexCount = 0,
+ .seedProbability = 0
+};
static void publishMessage(tr_tier* tier, char const* msg, int type)
{
#include "tr-assert.h"
#include "utils.h" /* tr_new0() */
-tr_bitfield const TR_BITFIELD_INIT = { NULL, 0, 0, 0, false, false };
+tr_bitfield const TR_BITFIELD_INIT =
+{
+ .bits = NULL,
+ .alloc_count = 0,
+ .bit_count = 0,
+ .true_count = 0,
+ .have_all_hint = false,
+ .have_none_hint = false
+};
/****
*****
static void fileset_construct(struct tr_fileset* set, int n)
{
- struct tr_cached_file const TR_CACHED_FILE_INIT = { false, TR_BAD_SYS_FILE, 0, 0, 0 };
+ struct tr_cached_file const TR_CACHED_FILE_INIT =
+ {
+ .is_writable = false,
+ .fd = TR_BAD_SYS_FILE,
+ .torrent_id = 0,
+ .file_index = 0,
+ .used_at = 0
+ };
set->begin = tr_new(struct tr_cached_file, n);
set->end = set->begin + n;
#include "platform.h"
#include "utils.h"
-static tr_list const TR_LIST_CLEAR = { NULL, NULL, NULL };
+static tr_list const TR_LIST_CLEAR =
+{
+ .data = NULL,
+ .next = NULL,
+ .prev = NULL
+};
static tr_list* recycled_nodes = NULL;
#define IN_MULTICAST(a) (((a) & 0xf0000000) == 0xe0000000)
#endif
-tr_address const tr_in6addr_any = { TR_AF_INET6, { IN6ADDR_ANY_INIT } };
-tr_address const tr_inaddr_any = { TR_AF_INET, { { { { INADDR_ANY, 0x00, 0x00, 0x00 } } } } };
+tr_address const tr_in6addr_any =
+{
+ .type = TR_AF_INET6,
+ .addr.addr6 = IN6ADDR_ANY_INIT
+};
+
+tr_address const tr_inaddr_any =
+{
+ .type = TR_AF_INET,
+ .addr.addr4.s_addr = INADDR_ANY
+};
char* tr_net_strerror(char* buf, size_t buflen, int err)
{
static struct tr_datatype* datatype_pool = NULL;
-static struct tr_datatype const TR_DATATYPE_INIT = { NULL, 0, false };
+static struct tr_datatype const TR_DATATYPE_INIT =
+{
+ .next = NULL,
+ .length = 0,
+ .isPieceData = false
+};
static struct tr_datatype* datatype_new(void)
{
CANCEL_HISTORY_SEC = 60
};
-tr_peer_event const TR_PEER_EVENT_INIT = { 0, 0, NULL, 0, 0, 0, 0 };
+tr_peer_event const TR_PEER_EVENT_INIT =
+{
+ .eventType = TR_PEER_CLIENT_GOT_BLOCK,
+ .pieceIndex = 0,
+ .bitfield = NULL,
+ .offset = 0,
+ .length = 0,
+ .err = 0,
+ .port = 0
+};
-tr_swarm_stats const TR_SWARM_STATS_INIT = { { 0, 0 }, 0, 0, { 0, 0, 0, 0, 0, 0, 0 } };
+tr_swarm_stats const TR_SWARM_STATS_INIT =
+{
+ .activePeerCount = { 0, 0 },
+ .activeWebseedCount = 0,
+ .peerCount = 0,
+ .peerFromCount = { 0, 0, 0, 0, 0, 0, 0 }
+};
/**
***
#include "rpcimpl.h"
#include "session.h"
#include "session-id.h"
+#include "stats.h"
#include "torrent.h"
#include "tr-assert.h"
#include "utils.h"
int running = 0;
int total = 0;
tr_variant* d;
- tr_session_stats currentStats = { 0.0f, 0, 0, 0, 0, 0 };
- tr_session_stats cumulativeStats = { 0.0f, 0, 0, 0, 0, 0 };
+ tr_session_stats currentStats = TR_SESSION_STATS_INIT;
+ tr_session_stats cumulativeStats = TR_SESSION_STATS_INIT;
tr_torrent* tor = NULL;
while ((tor = tr_torrentNext(session, tor)) != NULL)
****
***/
-static struct tr_session_stats const STATS_INIT = { 0.0f, 0, 0, 0, 0, 0 };
+struct tr_session_stats const TR_SESSION_STATS_INIT =
+{
+ .ratio = 0.0f,
+ .uploadedBytes = 0,
+ .downloadedBytes = 0,
+ .filesAdded = 0,
+ .sessionCount = 0,
+ .secondsActive = 0
+};
/** @brief Opaque, per-session data structure for bandwidth use statistics */
struct tr_stats_handle
if (h != NULL && h->isDirty)
{
- tr_session_stats cumulative = STATS_INIT;
+ tr_session_stats cumulative = TR_SESSION_STATS_INIT;
tr_sessionGetCumulativeStats(session, &cumulative);
saveCumulativeStats(session, &cumulative);
h->isDirty = false;
void tr_sessionGetCumulativeStats(tr_session const* session, tr_session_stats* setme)
{
struct tr_stats_handle const* stats = getStats(session);
- tr_session_stats current = STATS_INIT;
+ tr_session_stats current = TR_SESSION_STATS_INIT;
if (stats != NULL)
{
#pragma once
+extern struct tr_session_stats const TR_SESSION_STATS_INIT;
+
void tr_statsInit(tr_session* session);
void tr_statsClose(tr_session* session);
void tr_statsSaveDirty(tr_session* session);
int tr_dhtStatus(tr_session* session, int af, int* nodes_return)
{
- struct getstatus_closure closure = { af, -1, -1 };
+ struct getstatus_closure closure = { .af = af, .status = -1, .count = -1 };
if (!tr_dhtEnabled(session) || (af == AF_INET && session->udp_socket == TR_BAD_SOCKET) ||
(af == AF_INET6 && session->udp6_socket == TR_BAD_SOCKET))
maxHashLen = lengthof(lpd_torStaticType->info.hashString)
};
- struct lpd_protocolVersion ver = { -1, -1 };
+ struct lpd_protocolVersion ver = { .major = -1, .minor = -1 };
char value[maxValueLen] = { 0 };
char hashString[maxHashLen] = { 0 };
int res = 0;
#define BACKEND_UPCAST(b) ((tr_watchdir_generic*)(b))
/* Non-static and mutable for unit tests */
-struct timeval tr_watchdir_generic_interval = { 10, 0 };
+struct timeval tr_watchdir_generic_interval = { .tv_sec = 10, .tv_usec = 0 };
/***
****
tr_watchdir_t const handle = context;
tr_watchdir_kqueue* const backend = BACKEND_UPCAST(tr_watchdir_get_backend(handle));
struct kevent ke;
- struct timespec const ts = { 0, 0 };
+ struct timespec const ts = { .tv_sec = 0, .tv_nsec = 0 };
if (kevent(backend->kq, NULL, 0, &ke, 1, &ts) == -1)
{
extern struct timeval tr_watchdir_retry_start_interval;
extern struct timeval tr_watchdir_retry_max_interval;
-static struct timeval const FIFTY_MSEC = { 0, 50000 };
-static struct timeval const ONE_HUNDRED_MSEC = { 0, 100000 };
-static struct timeval const TWO_HUNDRED_MSEC = { 0, 200000 };
+static struct timeval const FIFTY_MSEC = { .tv_sec = 0, .tv_usec = 50000 };
+static struct timeval const ONE_HUNDRED_MSEC = { .tv_sec = 0, .tv_usec = 100000 };
+static struct timeval const TWO_HUNDRED_MSEC = { .tv_sec = 0, .tv_usec = 200000 };
static void process_events(void)
{
/* Non-static and mutable for unit tests */
unsigned int tr_watchdir_retry_limit = 3;
-struct timeval tr_watchdir_retry_start_interval = { 1, 0 };
-struct timeval tr_watchdir_retry_max_interval = { 10, 0 };
+struct timeval tr_watchdir_retry_start_interval = { .tv_sec = 1, .tv_usec = 0 };
+struct timeval tr_watchdir_retry_max_interval = { .tv_sec = 10, .tv_usec = 0 };
#define tr_watchdir_retries_init(r) (void)0
#define tr_watchdir_retries_destroy(r) tr_ptrArrayDestruct((r), (PtrArrayForeachFunc) & tr_watchdir_retry_free)