From 2c06ef6ad49aed8990dab99b84c039322697bb90 Mon Sep 17 00:00:00 2001 From: iphydf Date: Sat, 2 Apr 2022 16:23:13 +0000 Subject: [PATCH] cleanup: Replace a series of `if` statements with a `switch`. --- .../docker/tox-bootstrapd.sha256 | 2 +- toxcore/Messenger.c | 31 ++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 7d90b8a8..8790c3a4 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -5796f74532156d61d5c715914b5013ae0544892f7d6dca237b1f6a828f49fc9c /usr/local/bin/tox-bootstrapd +139fe825b90c022bbefd3837c2a427ab9215be3ca62144ea7ff12ae7389c78ba /usr/local/bin/tox-bootstrapd diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index d4d6db2e..6042fd72 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -1266,20 +1266,27 @@ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber, } if (send_file_control_packet(m, friendnumber, inbound, file_number, control, nullptr, 0)) { - if (control == FILECONTROL_KILL) { - if (!inbound && (ft->status == FILESTATUS_TRANSFERRING || ft->status == FILESTATUS_FINISHED)) { - // We are actively sending that file, remove from list - --m->friendlist[friendnumber].num_sending_files; + switch (control) { + case FILECONTROL_KILL: { + if (!inbound && (ft->status == FILESTATUS_TRANSFERRING || ft->status == FILESTATUS_FINISHED)) { + // We are actively sending that file, remove from list + --m->friendlist[friendnumber].num_sending_files; + } + + ft->status = FILESTATUS_NONE; + break; } + case FILECONTROL_PAUSE: { + ft->paused |= FILE_PAUSE_US; + break; + } + case FILECONTROL_ACCEPT: { + ft->status = FILESTATUS_TRANSFERRING; - ft->status = FILESTATUS_NONE; - } else if (control == FILECONTROL_PAUSE) { - ft->paused |= FILE_PAUSE_US; - } else if (control == FILECONTROL_ACCEPT) { - ft->status = FILESTATUS_TRANSFERRING; - - if ((ft->paused & FILE_PAUSE_US) != 0) { - ft->paused ^= FILE_PAUSE_US; + if ((ft->paused & FILE_PAUSE_US) != 0) { + ft->paused ^= FILE_PAUSE_US; + } + break; } } } else {