Prashanth
Prashanth

Reputation: 320

Timertimeout not happening

I am trying to make timertimeout at client side ,when we delayed msgreply from server to client

printing proper without timertimeout even we delayed

client_code: if (TimerTimeout(CLOCK_REALTIME, _NTO_TIMEOUT_SEND | _NTO_TIMEOUT_REPLY, &event, &timeout, NULL) == -1) { perror("TimerTimeout failed"); return EXIT_FAILURE; } else { printf("✅ TimerTimeout successfully set.\n"); } printf("🚀 Client sending message: %d\n", msg.data);

    // Send the message and wait for a response
    int status = MsgSend(coid, &msg, sizeof(msg), &msg, sizeof(msg));

    if (status == -1) {
        if (errno == ETIMEDOUT) {
            printf("⏳Message send timed out! No response from server.\n");
        }

server_code:

while (1) {
        struct my_msg_t msg;
        int rcvid = MsgReceive(attach->chid, &msg, 
        sizeof(msg),NULL);
        if (rcvid == -1) {
            perror("MsgReceive failed");
            continue;
        }

        printf("📩 Server received message: %d, delaying response...\n", msg.data);
        sleep(10);  // Simulate 10-sec delay (longer than the 2-sec timeout in client)

       if (MsgReply(rcvid, 0, &msg, sizeof(msg)) == -1) {
            perror("MsgReply failed");
        } else {
            printf("✅ Reply sent to client.\n");
        }
    }

why timertimeout not happening? could you please help me ?

Upvotes: 1

Views: 43

Answers (2)

Will Miles
Will Miles

Reputation: 316

The problem here is that your server is not handling the unblock pulse generated by the TimerTimeout() call. In QNX, the server must participate in the timeout handling. This is because it is not always safe to interrupt an operation in progress on the server side.

TimerTimeout, when it triggers on a REPLY-blocked thread, is implemented by the kernel sending a pulse with _PULSE_CODE_UNBLOCK to the channel opened on the server process with _NTO_CHF_UNBLOCK. The server is expected to MsgReceive this pulse, do whatever is necessary to abort the client call, and then promptly unblock the specified client by calling MsgReply or MsgError. The expectation is that the server either only blocks on MsgReceive (ie. 'long delay' operations are implemented by having something else like ionotify send a pulse back to the original channel to inform the server that the operation is complete), or uses multiple threads so some other thread can wake up if an unblock is requested and deal with the thread that's "stuck".

Unfortunately it seems that the QNX 8 documentation no longer has a good primer on writing a message server that includes unblock handling. For more details, take a look at the "Getting Started With QNX Neutrino" book included in the QNX documentation for QNX 6 and 7. A good place to start is here: https://www.qnx.com/developers/docs/7.1/#com.qnx.doc.neutrino.getting_started/topic/s1_timer_Kernel_timeouts_with_messages.html

Upvotes: 0

Mohith R Achar
Mohith R Achar

Reputation: 1

Your TimerTimeout function call is correctly setting the timeout, but it may not be applied to the MsgSend operation as expected. The following areas should be focused to fix the issue,

  1. Ensure Timeout is Set Before MsgSend The TimerTimeout function sets a timeout for a specific thread, but it applies to the next blocking operation on that thread. If TimerTimeout is called but another blocking operation occurs before MsgSend, the timeout might not be applied. Make sure TimerTimeout is called immediately before MsgSend.

  2. Check Server Delay Your server sleeps for 10 seconds, but your client timeout is 2 seconds. If TimerTimeout is properly set, MsgSend should return with ETIMEDOUT

Upvotes: -1

Related Questions