use epicsThread and Thread::Config

Catches errant c++ exceptions and is joinable
This commit is contained in:
Michael Davidsaver
2015-09-08 12:25:19 -04:00
parent b4048c3bfd
commit 6254525cba
6 changed files with 53 additions and 71 deletions

View File

@@ -33,7 +33,10 @@ namespace pvAccess {
_serverSocketChannel(INVALID_SOCKET),
_receiveBufferSize(receiveBufferSize),
_destroyed(false),
_threadId(0)
_thread(*this, "TCP-acceptor",
epicsThreadGetStackSize(
epicsThreadStackMedium),
epicsThreadPriorityMedium)
{
initialize(port);
}
@@ -118,14 +121,7 @@ namespace pvAccess {
THROW_BASE_EXCEPTION(temp.str().c_str());
}
_threadId
= epicsThreadCreate(
"TCP-acceptor",
epicsThreadPriorityMedium,
epicsThreadGetStackSize(
epicsThreadStackMedium),
BlockingTCPAcceptor::handleEventsRunner,
this);
_thread.start();
// all OK, return
return ntohs(_bindAddress.ia.sin_port);
@@ -139,7 +135,7 @@ namespace pvAccess {
THROW_BASE_EXCEPTION(temp.str().c_str());
}
void BlockingTCPAcceptor::handleEvents() {
void BlockingTCPAcceptor::run() {
// rise level if port is assigned dynamically
char ipAddrStr[48];
ipAddrToDottedIP(&_bindAddress.ia, ipAddrStr, sizeof(ipAddrStr));
@@ -235,10 +231,6 @@ namespace pvAccess {
}
}
void BlockingTCPAcceptor::handleEventsRunner(void* param) {
((BlockingTCPAcceptor*)param)->handleEvents();
}
void BlockingTCPAcceptor::destroy() {
Lock guard(_mutex);
if(_destroyed) return;