<p>Hmm, maybe it will be correctly?</p>

<p>void worker_loop(int id)<br>
{<br>
    dmq_worker_t* worker;<br>
    dmq_job_t* current_job;<br>
    peer_reponse_t peer_response;<br>
    int ret_value;<br>
    int not_parsed;<br>
    dmq_node_t *dmq_node = NULL;</p>

<pre><code>worker = &workers[id];
for(;;) {
    LM_DBG("dmq_worker [%d %d] getting lock\n", id, my_pid());
    lock_get(&worker->lock);
    LM_DBG("dmq_worker [%d %d] lock acquired\n", id, my_pid());
    /* multiple lock_release calls might be performed, so remove
     * from queue until empty */
    do {
        /* fill the response with 0's */
        memset(&peer_response, 0, sizeof(peer_response));
        current_job = job_queue_pop(worker->queue);
        /* job_queue_pop might return NULL if queue is empty */
        if(current_job) {
            /* extract the from uri */
            if (current_job->msg->from->parsed) {
                not_parsed = 0;
            } else {
                not_parsed = 1;
            }
            if (parse_from_header(current_job->msg) < 0) {
                LM_ERR("bad sip message or missing From hdr\n");
            } else {
                dmq_node = find_dmq_node_uri(node_list, &((struct to_body*)current_job->msg->from->parsed)->uri);
            }

            ret_value = current_job->f(current_job->msg, &peer_response, dmq_node);
            if(ret_value < 0) {
                LM_ERR("running job failed\n");
                continue;
            }
            /* add the body to the reply */
            if(peer_response.body.s) {
                if(set_reply_body(current_job->msg, &peer_response.body,
                            &peer_response.content_type) < 0) {
                    LM_ERR("error adding lumps\n");
                    continue;
                }
            }
            /* send the reply */
            if(slb.freply(current_job->msg, peer_response.resp_code,
                        &peer_response.reason) < 0)
            {
                LM_ERR("error sending reply\n");
            }

            /* if body given, free the lumps and free the body */
            if(peer_response.body.s) {
                del_nonshm_lump_rpl(&current_job->msg->reply_lump);
                pkg_free(peer_response.body.s);
            }
            if((current_job->msg->from->parsed)&&(not_parsed)){
                free_to(current_job->msg->from->parsed);
            }

            LM_DBG("sent reply\n");
            shm_free(current_job->msg);
            shm_free(current_job);
            worker->jobs_processed++;
        }
    } while(job_queue_size(worker->queue) > 0);
}
</code></pre>

<p>}</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br>Reply to this email directly or <a href="https://github.com/kamailio/kamailio/pull/59#issuecomment-72451753">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AF36Zcndid6UE93BUZR-fqrFtc5YZ2Xvks5nn2fHgaJpZM4DY1s8.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
  <div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
    <link itemprop="url" href="https://github.com/kamailio/kamailio/pull/59#issuecomment-72451753"></link>
    <meta itemprop="name" content="View Pull Request"></meta>
  </div>
  <meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>