avoid needless memmove calls

This commit is contained in:
2019-08-28 15:15:19 +02:00
committed by Martin Konrad
parent 06f1a8ec23
commit e000ea4913

View File

@@ -219,6 +219,8 @@ void epicsShareAPI logClientSend ( logClientId id, const char * message )
void epicsShareAPI logClientFlush ( logClientId id )
{
unsigned nSent = 0u;
logClient * pClient = ( logClient * ) id;
if ( ! pClient ) {
@@ -227,20 +229,11 @@ void epicsShareAPI logClientFlush ( logClientId id )
epicsMutexMustLock ( pClient->mutex );
while ( pClient->nextMsgIndex && pClient->connected ) {
int status = send ( pClient->sock, pClient->msgBuf,
pClient->nextMsgIndex, 0 );
while ( nSent < pClient->nextMsgIndex && pClient->connected ) {
int status = send ( pClient->sock, pClient->msgBuf + nSent,
pClient->nextMsgIndex - nSent, 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;
}
nSent += (unsigned) status;
}
else {
if ( ! pClient->shutdown ) {
@@ -258,6 +251,11 @@ void epicsShareAPI logClientFlush ( logClientId id )
break;
}
}
pClient->nextMsgIndex -= nSent;
if ( nSent > 0 && pClient->nextMsgIndex > 0 ) {
memmove ( pClient->msgBuf, & pClient->msgBuf[nSent],
pClient->nextMsgIndex );
}
epicsMutexUnlock ( pClient->mutex );
}