cancel select() in _modbus_tcp_selec

81 views
Skip to first unread message

Sandro Stiller

unread,
Sep 25, 2015, 7:52:10 AM9/25/15
to libmodbus
Hello,


I am developing a linux-based modbus-tcp slace/device using libmodbus.
To to quit my application while modbus_receive() is running,  I call shutdown(socket, SHUT_RDWR). to cancel this call.
But in the file modbus-tcp.c the following code can be found in _modbus_tcp_select:
#####################
    while ((s_rc = select(ctx->s+1, rset, NULL, NULL, tv)) == -1) {
        if (errno == EINTR) {
            if (ctx->debug) {
                fprintf(stderr, "A non blocked signal was caught\n");
            }
            /* Necessary after an error */
            FD_ZERO(rset);
            FD_SET(ctx->s, rset);
        } else {
          */
            return -1;
        }
...
#####################

Thats why I can not cancel modbus_receive() and only get the message "A non blocked signal was caught".
My code works fine if I disable the special handling of EINTR.
Why is EINTR handled this way?
How can I quit my application while modbus_receive() is running?

Thanks,

Sandro

Stéphane Raimbault

unread,
Oct 15, 2015, 5:55:06 PM10/15/15
to libm...@googlegroups.com
I don't understand where you use shutdown(socket, SHUT_RDWR), in a signal handler?

The slave examples provided in modbus/tests can be interrupted by Ctrl+C signal for example.

Stéphane

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "libmodbus".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse libmodbus+...@googlegroups.com.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages