amq_client_session_wait returns 0 when timeout expires
Forum » Ongoing Development / Problem reports » amq_client_session_wait returns 0 when timeout expires
started by: Jacobus GelukJacobus Geluk
on: 1193054323|%e %b %Y, %H:%M %Z|agohover
number of posts: 5
rss icon RSS: new posts
amq_client_session_wait returns 0 when timeout expires
Jacobus GelukJacobus Geluk 1193054323|%e %b %Y, %H:%M %Z|agohover

The following code is very similar to the example in the OpenAMQ docs:

if (amq_client_session_wait (implChannel, 5000)) {
    if (implChannel->alive) {
        logDebug << "Timeout expired" ;
    } else {
        logDebug << "Channel died" ;
    }
} else {
    logDebug << "Message(s) arrived" ;
}

My problem is that I never get the message "Timeout expired". The other two work.
The docs say that -1 will be returned when the timeout expired. This does not happen here. amq_client_session_wait always returns 0 when the timeout expires or when messages arrived.

Re: amq_client_session_wait returns 0 when timeout expires
martin_sustrikmartin_sustrik 1193281435|%e %b %Y, %H:%M %Z|agohover

You are right. The function returns 0 if message is received or timeout expires, -1 in case of error. However, the documentation states that "Returns zero if content arrived, or -1 if the timeout expired".

Looking at our applications I see they consider a call to wait timeouted if it returns 0 and there are no messages available. I suppose this is a bug in documentation.

Thoughts anyone?

Re: amq_client_session_wait returns 0 when timeout expires
pieterhpieterh 1193297132|%e %b %Y, %H:%M %Z|agohover

I think the documentation needs fixing; we always use -1 in our APIs to indicate an error status, and 'timeout expired' is not an error.

Re: amq_client_session_wait returns 0 when timeout expires
Jacobus GelukJacobus Geluk 1193303798|%e %b %Y, %H:%M %Z|agohover

Ok, I understand that -1 is for errors only and a timeout is not an error. But how do you then check if a timeout occurred and no messages have been received?

Re: amq_client_session_wait returns 0 when timeout expires
martin_sustrikmartin_sustrik 1193329675|%e %b %Y, %H:%M %Z|agohover

By checking whether there are any messages available. You can either try to get message straight away (amq_client_session_basic_arrived) - in that case return value of NULL means that no message is available - or you can check the number of pending messages (amq_client_session_get_basic_arrived_count).

Hope that helps.

new post