Skip to content

Timeout for msg indications #95

@stephane

Description

@stephane

Copied from https://answers.launchpad.net/libmodbus/+question/193271

Hi, I just bumped into the same problem. In older versions, there was a timeout in the select() call, so it was possible to properly stop a thread waiting for an indication, update watchdog, whatever. The commit that changes this is:

commit 89d0dc0
Author: Stéphane Raimbault stephane.raimbault@gmail.com
Date: Fri May 6 19:06:59 2011 +0200

    Fix longstanding limitation of server to wait forever

    The change for serial on Windows is temporary. If you're interested of
    improving the situation for this, please have a look at the FIXME.

So, in some cases (like mine: ) this limitation was not so undesirable. Now in the code we have a hardcored value of NULL if we're waiting for an idication:

  if (msg_type == MSG_INDICATION) {
         /* Wait for a message, we don't know when the message will be
          * received */
        p_tv = NULL;
     } else {
         tv.tv_sec = ctx->response_timeout.tv_sec;
         tv.tv_usec = ctx->response_timeout.tv_usec;
         p_tv = &tv;
     }

I think it will be better to make this configurable, like the other timeouts. So, what do you think about changing it to somethink like:

  if (msg_type == MSG_INDICATION) {
         /* Wait for a message, we don't know when the message will be
          * received */
         if (ctx->indication_timeout.tv_usec==-1) {
         p_tv=NULL;
         } else {
         tv.tv_sec = ctx->indication_timeout.tv_sec;
         tv.tv_usec = ctx->indication_timeout.tv_usec;
         p_tv = &tv;
         }
     } else {
         tv.tv_sec = ctx->response_timeout.tv_sec;
         tv.tv_usec = ctx->response_timeout.tv_usec;
         p_tv = &tv;
     }

And the default value for indication_timeout can be NULL, so it will wait forever. But for some of us who need a timeout there will be a way to set it.

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions