AIX socket don't have MSG_DONTWAIT tag #294

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

Comments

Projects
None yet
3 participants
@poulacou

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

This comment has been minimized.

Show comment
Hide comment
@poulacou

poulacou Oct 30, 2015

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;

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 added a commit to poulacou/libmodbus that referenced this issue Oct 30, 2015

poulacou added a commit to poulacou/libmodbus that referenced this issue Oct 30, 2015

@stephane

This comment has been minimized.

Show comment
Hide comment
@stephane

stephane Nov 16, 2015

Owner

@poulacou what do you think about my patch?

Owner

stephane commented Nov 16, 2015

@poulacou what do you think about my patch?

@stephane stephane self-assigned this Nov 16, 2015

@stephane stephane added the needinfo label Nov 16, 2015

@stephane stephane added this to the v3.2.0 milestone Nov 16, 2015

@karlp

This comment has been minimized.

Show comment
Hide comment
@karlp

karlp Nov 17, 2015

Contributor

👍

Contributor

karlp commented Nov 17, 2015

👍

@stephane

This comment has been minimized.

Show comment
Hide comment
@stephane

stephane Dec 3, 2015

Owner

Merged.

Owner

stephane commented Dec 3, 2015

Merged.

@stephane stephane closed this Dec 3, 2015

@poulacou

This comment has been minimized.

Show comment
Hide comment
@poulacou

poulacou Dec 3, 2015

Thanks ;-)

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

poulacou commented Dec 3, 2015

Thanks ;-)

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

@stephane

This comment has been minimized.

Show comment
Hide comment
@stephane

stephane Dec 4, 2015

Owner

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

Owner

stephane commented Dec 4, 2015

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

georgidimov added a commit to georgidimov/libmodbus that referenced this issue Jul 24, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment