Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout for msg indications #95

Closed
stephane opened this issue Feb 26, 2013 · 5 comments
Closed

Timeout for msg indications #95

stephane opened this issue Feb 26, 2013 · 5 comments
Assignees
Milestone

Comments

@stephane
Copy link
Owner

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 [email protected]
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.

@bertonimatias
Copy link

Dear Stephane,

i must add the parameter "ctx->indication_timeout.tv_usec" in the struct _modbus

I don´t know if this issus has relation with my issus #233

@jfieldhouse
Copy link

Is it possible for me to get this patch now? Instead of waiting for the next milestone? I need it to kick a watchdog in my modbus server application.

@stephane
Copy link
Owner Author

@jfieldhouse yep feel free to patch your Modbus server, the Open Source way!

@stephane
Copy link
Owner Author

Could someone review my patch?

@stephane
Copy link
Owner Author

Merged.

epsilonrt pushed a commit to epsilonrt/libmodbus that referenced this issue Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants