From abalashov@evaristesys.com Mon Oct 11 12:28:45 2010 From: Alex Balashov To: sr-dev@lists.kamailio.org Subject: Re: [sr-dev] git:master: mqueue: return false if queue is empty Date: Mon, 11 Oct 2010 06:28:39 -0400 Message-ID: <4CB2E6D7.4070001@evaristesys.com> In-Reply-To: <20101011102114.1D156EF8076@rimmer> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1415381020==" --===============1415381020== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Can this be backported into the 3.1.0 branch? Or is that not the=20 usual custom? It would be very inconvenient to apply this patch to=20 every new installation, but now that I am using it it is important. :-) On 10/11/2010 06:21 AM, Elena-Ramona Modroiu wrote: > Module: sip-router > Branch: master > Commit: e6fa8ae004f5d487e1c64471bf282931e4b9e901 > URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=3Dcommit= ;h=3De6fa8ae004f5d487e1c64471bf282931e4b9e901 > > Author: Elena-Ramona Modroiu > Committer: Elena-Ramona Modroiu > Date: Mon Oct 11 12:20:24 2010 +0200 > > mqueue: return false if queue is empty > > - return code -2 > - reported by Alex Balashov > > --- > > modules/mqueue/README | 11 +++++++---- > modules/mqueue/doc/mqueue_admin.xml | 8 ++++++-- > modules/mqueue/mqueue_api.c | 22 +++++++++++++--------- > modules/mqueue/mqueue_mod.c | 7 +++++-- > 4 files changed, 31 insertions(+), 17 deletions(-) > > diff --git a/modules/mqueue/README b/modules/mqueue/README > index 4c439a4..f876b2a 100644 > --- a/modules/mqueue/README > +++ b/modules/mqueue/README > @@ -10,7 +10,7 @@ Elena-Ramona Modroiu > > > > - Copyright =EF=BF=BD 2010 Elena-Ramona Modroiu (asipto.com) > + Copyright =C2=A9 2010 Elena-Ramona Modroiu (asipto.com) > __________________________________________________________________ > > Table of Contents > @@ -94,7 +94,7 @@ Chapter 1. Admin Guide > > Definition of memory queue > > - Default value is "none". > + Default value is =E2=80=9Cnone=E2=80=9D. > > Value must be a list of parameters: attr=3Dvalue;... The attribute 'na= me' > is mandatory, defining the name of the queue. Optional attribute 'size' > @@ -128,8 +128,11 @@ mq_add("myq", "$rU", "call from $fU"); > > 4.2. mq_fetch(queue) > > - Take oldest item from que and fill $mqk(queue) and $mqv(queue) pseudo > - variables. Return true on success. > + Take oldest item from queue and fill $mqk(queue) and $mqv(queue) pseudo > + variables. > + > + Return: true on success (1); false on failure (-1) or no item fetched > + (-2). > > Example 1.3. mq_fetch usage > ... > diff --git a/modules/mqueue/doc/mqueue_admin.xml b/modules/mqueue/doc/mqueu= e_admin.xml > index e02ca38..d1b924a 100644 > --- a/modules/mqueue/doc/mqueue_admin.xml > +++ b/modules/mqueue/doc/mqueue_admin.xml > @@ -118,8 +118,12 @@ mq_add("myq", "$rU", "call from $fU"); > mq_fetch(queue) > > > - Take oldest item from que and fill $mqk(queue) and $mqv(queue) pseudo > - variables. Return true on success. > + Take oldest item from queue and fill $mqk(queue) and > + $mqv(queue) pseudo variables. > + > + > + Return: true on success (1); false on failure (-1) or > + no item fetched (-2). > > > <function>mq_fetch</function> usage > diff --git a/modules/mqueue/mqueue_api.c b/modules/mqueue/mqueue_api.c > index f75f23a..6007ef0 100644 > --- a/modules/mqueue/mqueue_api.c > +++ b/modules/mqueue/mqueue_api.c > @@ -254,17 +254,21 @@ int mq_head_fetch(str *name) > return -1; > lock_get(&mh->lock); > > - if(mh->ifirst!=3DNULL) > + if(mh->ifirst=3D=3DNULL) > { > - mp->item =3D mh->ifirst; > - mh->ifirst =3D mh->ifirst->next; > - if(mh->ifirst=3D=3DNULL) { > - mh->ilast =3D NULL; > - } else { > - mh->ifirst->prev =3D NULL; > - } > - mh->csize--; > + /* empty queue */ > + lock_release(&mh->lock); > + return -2; > + } > + > + mp->item =3D mh->ifirst; > + mh->ifirst =3D mh->ifirst->next; > + if(mh->ifirst=3D=3DNULL) { > + mh->ilast =3D NULL; > + } else { > + mh->ifirst->prev =3D NULL; > } > + mh->csize--; > > lock_release(&mh->lock); > return 0; > diff --git a/modules/mqueue/mqueue_mod.c b/modules/mqueue/mqueue_mod.c > index 922f02e..5a74f58 100644 > --- a/modules/mqueue/mqueue_mod.c > +++ b/modules/mqueue/mqueue_mod.c > @@ -109,8 +109,11 @@ static void mod_destroy(void) > > static int w_mq_fetch(struct sip_msg* msg, char* mq, char* str2) > { > - if(mq_head_fetch((str*)mq)<0) > - return -1; > + int ret; > + > + ret =3D mq_head_fetch((str*)mq); > + if(ret<0) > + return ret; > return 1; > } > > > > > > > _______________________________________________ > sr-dev mailing list > sr-dev(a)lists.sip-router.org > http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev --=20 Alex Balashov - Principal Evariste Systems LLC 1170 Peachtree Street 12th Floor, Suite 1200 Atlanta, GA 30309 Tel: +1-678-954-0670 Fax: +1-404-961-1892 Web: http://www.evaristesys.com/ --===============1415381020==--