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

AIX socket don't have MSG_DONTWAIT tag #294

Closed
poulacou opened this issue Oct 30, 2015 · 6 comments
Closed

AIX socket don't have MSG_DONTWAIT tag #294

poulacou opened this issue Oct 30, 2015 · 6 comments
Assignees
Labels
Milestone

Comments

@poulacou
Copy link

MSG_DONTWAIT could be replaced by MSG_NONBLOCK on AIX

** on Linux we have:

grep MSG_DONTWAIT /usr/include/bits/socket.h

MSG_DONTWAIT    = 0x40, /* Nonblocking IO.  */

define MSG_DONTWAIT MSG_DONTWAIT

** on AIX

grep MSG_NONBLOCK /usr/include/sys/socket.h

define MSG_NONBLOCK 0x4000 /* nonblocking request */

@poulacou
Copy link
Author

I propose this change
diff --git a/src/modbus-tcp.c b/src/modbus-tcp.c
index 00de11c..5c92743 100644
--- a/src/modbus-tcp.c
+++ b/src/modbus-tcp.c
@@ -440,9 +440,10 @@ static int _modbus_tcp_flush(modbus_t ctx)
do {
/
Extract the garbage from the socket */
char devnull[MODBUS_TCP_MAX_ADU_LENGTH];
-#ifndef OS_WIN32

  •    rc = recv(ctx->s, devnull, MODBUS_TCP_MAX_ADU_LENGTH, MSG_DONTWAIT);
    
    -#else
    +#ifdef _AIX
  •    rc = recv(ctx->s, devnull, MODBUS_TCP_MAX_ADU_LENGTH, MSG_NONBLOCK);
    
    +#ifdef OS_WIN32
    /* On Win32, it's a bit more complicated to not wait _/
    fd_set rset;
    struct timeval tv;
    @@ -460,6 +461,9 @@ static int modbus_tcp_flush(modbus_t *ctx)
    /
    There is data to flush */
    rc = recv(ctx->s, devnull, MODBUS_TCP_MAX_ADU_LENGTH, 0);
    }
    +#else
  •    rc = recv(ctx->s, devnull, MODBUS_TCP_MAX_ADU_LENGTH, MSG_DONTWAIT);
    
    #endif
    if (rc > 0) {
    rc_sum += rc;

poulacou pushed a commit to poulacou/libmodbus that referenced this issue Oct 30, 2015
poulacou pushed a commit to poulacou/libmodbus that referenced this issue Oct 30, 2015
@stephane
Copy link
Owner

@poulacou what do you think about my patch?

@stephane stephane self-assigned this Nov 16, 2015
@stephane stephane added this to the v3.2.0 milestone Nov 16, 2015
@karlp
Copy link
Contributor

karlp commented Nov 17, 2015

👍

@stephane
Copy link
Owner

stephane commented Dec 3, 2015

Merged.

@stephane stephane closed this as completed Dec 3, 2015
@poulacou
Copy link
Author

poulacou commented Dec 3, 2015

Thanks ;-)

I can't test it for the moment.
It looks ok from a functional point of view

@stephane
Copy link
Owner

stephane commented Dec 4, 2015

@poulacou I stay tuned, all feedback is always very appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants