aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-12-25 19:28:44 +0100
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-12-26 09:40:48 +0100
commit203845730ff3f3456698a497ab8fddec0faa6a50 (patch)
treed8faff6ce0f0799338a6d8aa64ecb9edf74ac890 /openbsc/src
parentf7e2389eb680b6459a20fb5ad6357d3d676705b2 (diff)
sms: Rewrite the queue to find SMS harder.
With the old code it was possible that we first saw SMS that we have already in the queue. In that case we had free slots available but have not filled them. With his new loop we try harder to find SMS we can send, it attempts (and should work) to detect a loop to break the loop before finding SMS to deliver.
Diffstat (limited to 'openbsc/src')
-rw-r--r--openbsc/src/sms_queue.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/openbsc/src/sms_queue.c b/openbsc/src/sms_queue.c
index e8e65846f..f6ac66090 100644
--- a/openbsc/src/sms_queue.c
+++ b/openbsc/src/sms_queue.c
@@ -217,11 +217,13 @@ static void sms_submit_pending(void *_data)
{
struct gsm_sms_queue *smsq = _data;
int attempts = smsq->max_pending - smsq->pending;
- int i;
+ int initialized = 0;
+ unsigned long long first_sub = 0;
+ int attempted = 0;
LOGP(DSMS, LOGL_NOTICE, "Attempting to send %d SMS\n", attempts);
- for (i = 0; i < attempts; ++i) {
+ do {
struct gsm_sms_pending *pending;
struct gsm_sms *sms;
@@ -230,6 +232,23 @@ static void sms_submit_pending(void *_data)
if (!sms)
break;
+ /*
+ * This code needs to detect a loop. It assumes that no SMS
+ * will vanish during the time this is executed. We will remember
+ * the id of the first GSM subscriber we see and then will
+ * compare this. The Database code should make sure that we will
+ * see all other subscribers first before seeing this one again.
+ *
+ * It is always scary to have an infinite loop like this.
+ */
+ if (!initialized) {
+ first_sub = sms->receiver->id;
+ initialized = 1;
+ } else if (first_sub == sms->receiver->id) {
+ sms_free(sms);
+ break;
+ }
+
/* no need to send a pending sms */
if (sms_is_in_pending(smsq, sms)) {
LOGP(DSMS, LOGL_DEBUG,
@@ -254,10 +273,13 @@ static void sms_submit_pending(void *_data)
continue;
}
+ attempted += 1;
smsq->pending += 1;
llist_add(&pending->entry, &smsq->pending_sms);
gsm411_send_sms_subscr(sms->receiver, sms);
- }
+ } while (attempted < attempts);
+
+ LOGP(DSMS, LOGL_DEBUG, "SMSqueue added %d messages\n", attempted);
}
/*