Skip to content

Commit

Permalink
Tidy up tag accounting
Browse files Browse the repository at this point in the history
  • Loading branch information
mubes committed Jun 14, 2024
1 parent 87ef4cc commit 6b467b8
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 251 deletions.
57 changes: 30 additions & 27 deletions Src/nwclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,40 +212,43 @@ void nwclientSend( struct nwclientsHandle *h, uint32_t len, const uint8_t *ipbuf
{
const struct timespec ts = {.tv_sec = 1, .tv_nsec = 0};

if ( _lock_with_timeout( &h->clientList, &ts ) < 0 )
{
genericsExit( -1, "Failed to acquire mutex" EOL );
}

/* Now kick all the clients that new data arrived for them to distribute */
volatile struct nwClient *n = h->firstClient;

while ( n )
if ( h && h->firstClient )
{
ssize_t t = len;
ssize_t sent = 0;
void *p = ( void * )ipbuffer;

while ( t && ( sent >= 0 ) )
if ( _lock_with_timeout( &h->clientList, &ts ) < 0 )
{
sent = send( n->portNo, p, t, MSG_NOSIGNAL );
p += sent;
t -= sent;
genericsExit( -1, "Failed to acquire mutex" EOL );
}

if ( t )
{
volatile struct nwClient *newn = n->nextClient;
_clientRemoveNoLock( n );
n = newn;
}
else
/* Now kick all the clients that new data arrived for them to distribute */
volatile struct nwClient *n = h->firstClient;

while ( n )
{
n = n->nextClient;
ssize_t t = len;
ssize_t sent = 0;
void *p = ( void * )ipbuffer;

while ( t && ( sent >= 0 ) )
{
sent = send( n->portNo, p, t, MSG_NOSIGNAL );
p += sent;
t -= sent;
}

if ( t )
{
volatile struct nwClient *newn = n->nextClient;
_clientRemoveNoLock( n );
n = newn;
}
else
{
n = n->nextClient;
}
}
}

pthread_mutex_unlock( &h->clientList );
pthread_mutex_unlock( &h->clientList );
}
}
// ====================================================================================================
struct nwclientsHandle *nwclientStart( int port )
Expand Down
Loading

0 comments on commit 6b467b8

Please sign in to comment.