EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024  Index 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: [Merge] ~dirk.zimoch/epics-base:iocLogClientFixesTry2 into epics-base:7.0
From: Dirk Zimoch via Core-talk <[email protected]>
To: [email protected]
Date: Thu, 19 Sep 2019 14:48:25 -0000
Hm, the in-diff comments become kind of hidden with a new push.
About epicsSocketCountUnsentBytes() [or whatever we call it] returning size_t instead of int: In vxWorks and Windows all socket operations use int for size and Windows does not have ssize_t.


Diff comments:

> diff --git a/modules/libcom/src/log/iocLog.c b/modules/libcom/src/log/iocLog.c
> index e62da20..8cb1349 100644
> --- a/modules/libcom/src/log/iocLog.c
> +++ b/modules/libcom/src/log/iocLog.c
> @@ -89,6 +99,10 @@ static logClientId iocLogClientInit (void)
>          return NULL;
>      }
>      id = logClientCreate (addr, port);
> +    if (id != NULL) {
> +        errlogAddListener (logClientSendMessage, id);

logClientSendMessage is marked "deprecated" (by comment only) but used multiple times in iocLog.c. I think I'll remove the commend and make it static as you suggested.

> +        epicsAtExit (iocLogClientDestroy, id);
> +    }
>      return id;
>  }
>  
> diff --git a/modules/libcom/src/log/logClient.c b/modules/libcom/src/log/logClient.c
> index 99ee671..6671d27 100644
> --- a/modules/libcom/src/log/logClient.c
> +++ b/modules/libcom/src/log/logClient.c
> @@ -176,60 +175,59 @@ static void sendMessageChunk(logClient * pClient, const char * message) {
>          unsigned msgBufBytesLeft = 
>              sizeof ( pClient->msgBuf ) - pClient->nextMsgIndex;
>  
> -        if ( strSize > msgBufBytesLeft ) {
> -            int status;
> -
> -            if ( ! pClient->connected ) {
> -                break;
> -            }
> -
> -            if ( msgBufBytesLeft > 0u ) {
> -                memcpy ( & pClient->msgBuf[pClient->nextMsgIndex],
> -                    message, msgBufBytesLeft );
> -                pClient->nextMsgIndex += msgBufBytesLeft;
> -                strSize -= msgBufBytesLeft;
> -                message += msgBufBytesLeft;
> -            }
> -
> -            status = send ( pClient->sock, pClient->msgBuf, 
> -                pClient->nextMsgIndex, 0 );
> -            if ( status > 0 ) {
> -                unsigned nSent = (unsigned) status;
> -                if ( nSent < pClient->nextMsgIndex ) {
> -                    unsigned newNextMsgIndex = pClient->nextMsgIndex - nSent;
> -                    memmove ( pClient->msgBuf, & pClient->msgBuf[nSent], 
> -                        newNextMsgIndex );
> -                    pClient->nextMsgIndex = newNextMsgIndex;
> -                }
> -                else {
> -                    pClient->nextMsgIndex = 0u;
> -                }
> -            }
> -            else {
> -                if ( ! pClient->shutdown ) {
> -                    char sockErrBuf[64];
> -                    if ( status ) {
> -                        epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) );
> -                    }
> -                    else {
> -                        strcpy ( sockErrBuf, "server initiated disconnect" );
> -                    }
> -                    fprintf ( stderr, "log client: lost contact with log server at \"%s\" because \"%s\"\n", 
> -                        pClient->name, sockErrBuf );
> -                }
> -                logClientClose ( pClient );
> -                break;
> -            }
> +        if ( msgBufBytesLeft < strSize && pClient->nextMsgIndex != 0u && pClient->connected)
> +        {
> +            /* buffer is full, thus flush it */
> +            logClientFlush ( pClient );
> +            msgBufBytesLeft = sizeof ( pClient->msgBuf ) - pClient->nextMsgIndex;
>          }
> -        else {
> -            memcpy ( & pClient->msgBuf[pClient->nextMsgIndex],
> -                message, strSize );
> -            pClient->nextMsgIndex += strSize;
> +        if ( msgBufBytesLeft == 0u ) {
> +            fprintf ( stderr, "log client: messages to \"%s\" are lost\n",
> +                pClient->name );
>              break;
>          }
> +        if ( msgBufBytesLeft > strSize) msgBufBytesLeft = strSize;
> +        memcpy ( & pClient->msgBuf[pClient->nextMsgIndex],
> +            message, msgBufBytesLeft );
> +        pClient->nextMsgIndex += msgBufBytesLeft;
> +        strSize -= msgBufBytesLeft;
> +        message += msgBufBytesLeft;
>      }
>  }
>  
> +/*
> + * epicsSockCountUnsentBytes ()
> + * Should go to osd socket support

About funtion name length: compare to epicsSocketSystemCallInterruptMechanismQuery()

> + */
> +#if defined (_WIN32) && WINVER >= _WIN32_WINNT_WIN10
> +#include <mstcpip.h>
> +#endif
> +
> +static int epicsSockCountUnsentBytes(SOCKET sock) {
> +#if defined (_WIN32) && WINVER >= _WIN32_WINNT_WIN10
> +/* Windows 10 Version 1703 / Server 2016 */
> +/* https://docs.microsoft.com/en-us/windows/win32/api/mstcpip/ns-mstcpip-tcp_info_v0 */
> +    DWORD infoVersion = 0, bytesReturned;
> +    TCP_INFO_v0 tcpInfo;
> +    int status;
> +    if ((status = WSAIoctl(sock, SIO_TCP_INFO, &infoVersion, sizeof(infoVersion),
> +        &tcpInfo, sizeof(tcpInfo), &bytesReturned, NULL, NULL)) == 0)
> +        return tcpInfo.BytesInFlight;
> +#elif defined (SO_NWRITE)
> +/* macOS / iOS */
> +/* https://www.unix.com/man-page/osx/2/setsockopt/ */
> +    int unsent;
> +    if (getsockopt(sock, SOL_SOCKET, SO_NWRITE, &unsent) == 0)
> +        return unsent;
> +#elif defined (TIOCOUTQ)
> +/* Linux */
> +/* https://linux.die.net/man/7/tcp */
> +    int unsent;
> +    if (ioctl(sock, TIOCOUTQ, &unsent) == 0)
> +        return unsent;
> +#endif
> +    return 0;
> +}
>  
>  /* 
>   * logClientSend ()


-- 
https://code.launchpad.net/~dirk.zimoch/epics-base/+git/epics-base/+merge/372925
Your team EPICS Core Developers is subscribed to branch epics-base:7.0.

References:
[Merge] ~dirk.zimoch/epics-base:iocLogClientFixesTry2 into epics-base:7.0 Dirk Zimoch via Core-talk

Navigate by Date:
Prev: Build completed: EPICS Base base-3.15-456 AppVeyor via Core-talk
Next: Build failed: EPICS Base base-7.0-425 AppVeyor via Core-talk
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: [Merge] ~dirk.zimoch/epics-base:iocLogClientFixesTry2 into epics-base:7.0 Dirk Zimoch via Core-talk
Next: Re: [Merge] ~dirk.zimoch/epics-base:iocLogClientFixesTry2 into epics-base:7.0 Andrew Johnson via Core-talk
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  <20192020  2021  2022  2023  2024 
ANJ, 19 Sep 2019 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·