Skip to content

Commit

Permalink
- CS 104 master: fixed potential race condition when new connection c…
Browse files Browse the repository at this point in the history
…loses because of a protocol error
  • Loading branch information
mzillgith committed May 4, 2018
1 parent 09756ce commit 7c5f1e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions lib60870-C/examples/cs101_master_balanced/master_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ main(int argc, char** argv)

CS101_Master master = CS101_Master_create(port, NULL, NULL, IEC60870_LINK_LAYER_BALANCED);


CS101_Master_setOwnAddress(master, 3);

/* Set the address of the slave (optional for balanced master */
CS101_Master_useSlaveAddress(master, 3);

Expand Down
19 changes: 13 additions & 6 deletions lib60870-C/src/iec60870/cs104/cs104_slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -1968,17 +1968,21 @@ MasterConnection_create(CS104_Slave slave, Socket socket, MessageQueue lowPrioQu
self->highPrioQueue = highPrioQueue;

self->outstandingTestFRConMessages = 0;

Thread newThread =
Thread_create((ThreadExecutionFunction) connectionHandlingThread,
(void*) self, true);

Thread_start(newThread);
}

return self;
}

static void
MasterConnection_start(MasterConnection self)
{
Thread newThread =
Thread_create((ThreadExecutionFunction) connectionHandlingThread,
(void*) self, true);

Thread_start(newThread);
}

void
MasterConnection_close(MasterConnection self)
{
Expand Down Expand Up @@ -2077,6 +2081,9 @@ serverThread (void* parameter)
#if (CONFIG_USE_THREADS)
Semaphore_post(self->openConnectionsLock);
#endif

/* now start the connection handling (thread) */
MasterConnection_start(connection);
}
else
DEBUG_PRINT("Connection attempt failed!");
Expand Down

0 comments on commit 7c5f1e3

Please sign in to comment.