Switch to unified view

a/upmpd/mpdcli.cxx b/upmpd/mpdcli.cxx
...
...
17
#include "mpdcli.hxx"
17
#include "mpdcli.hxx"
18
18
19
#include <mpd/client.h>
19
#include <mpd/client.h>
20
20
21
#include <stddef.h>                     // for NULL
21
#include <stddef.h>                     // for NULL
22
22
#include <unistd.h>
23
#include <iostream>                     // for endl, etc
23
#include <iostream>                     // for endl, etc
24
24
25
#include "libupnpp/log.hxx"             // for LOGDEB, LOGERR, LOGINF
25
#include "libupnpp/log.hxx"             // for LOGDEB, LOGERR, LOGINF
26
26
27
struct mpd_status;
27
struct mpd_status;
...
...
108
108
109
#define RETRY_CMD(CMD) {                                \
109
#define RETRY_CMD(CMD) {                                \
110
    for (int i = 0; i < 2; i++) {                       \
110
    for (int i = 0; i < 2; i++) {                       \
111
        if ((CMD))                                      \
111
        if ((CMD))                                      \
112
            break;                                      \
112
            break;                                      \
113
        if (i == 1 || !showError(#CMD))                 \
114
            return false;                               \
115
    }                                                   \
116
    }
117
118
#define RETRY_CMD_WITH_SLEEP(CMD) {                     \
119
    for (int i = 0; i < 2; i++) {                       \
120
        if ((CMD))                                      \
121
            break;                                      \
122
        sleep(1);                                       \
113
        if (i == 1 || !showError(#CMD))                 \
123
        if (i == 1 || !showError(#CMD))                 \
114
            return false;                               \
124
            return false;                               \
115
    }                                                   \
125
    }                                                   \
116
    }
126
    }
117
127
...
...
475
        return -1;
485
        return -1;
476
486
477
    RETRY_CMD(mpd_run_clear(M_CONN));
487
    RETRY_CMD(mpd_run_clear(M_CONN));
478
    return true;
488
    return true;
479
}
489
}
490
480
bool MPDCli::deleteId(int id)
491
bool MPDCli::deleteId(int id)
481
{
492
{
482
    LOGDEB("MPDCli::deleteId " << id << endl);
493
    LOGDEB("MPDCli::deleteId " << id << endl);
483
    if (!ok())
494
    if (!ok())
484
        return -1;
495
        return -1;
485
496
    // It seems that mpd will sometimes get in a funny state, esp.
497
    // after failed statsongs. The exact mechanism is a mystery, but
498
    // retrying the failed deletes with a bit of wait seems to help a
499
    // lot, and this happens seldom enough that this is not a
500
    // significant performance issue
486
    RETRY_CMD(mpd_run_delete_id(M_CONN, (unsigned)id));
501
    RETRY_CMD_WITH_SLEEP(mpd_run_delete_id(M_CONN, (unsigned)id));
487
    return true;
502
    return true;
488
}
503
}
489
504
490
bool MPDCli::deletePosRange(unsigned int start, unsigned int end)
505
bool MPDCli::deletePosRange(unsigned int start, unsigned int end)
491
{
506
{