new logging, SIGPIPE and other handled
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
/* Author: Matej Sekoranja Date: 2011.2.1 */
|
||||
|
||||
#include <pv/clientFactory.h>
|
||||
#include <errlog.h>
|
||||
#include <logger.h>
|
||||
#include <epicsSignal.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
@@ -12,6 +13,9 @@ ClientContextImpl::shared_pointer ClientFactory::m_context;
|
||||
|
||||
void ClientFactory::start()
|
||||
{
|
||||
epicsSignalInstallSigAlarmIgnore ();
|
||||
epicsSignalInstallSigPipeIgnore ();
|
||||
|
||||
Lock guard(m_mutex);
|
||||
|
||||
if (m_context.get()) return;
|
||||
@@ -22,9 +26,9 @@ void ClientFactory::start()
|
||||
ChannelProvider::shared_pointer provider = m_context->getProvider();
|
||||
registerChannelProvider(provider);
|
||||
} catch (std::exception &e) {
|
||||
errlogSevPrintf(errlogMajor, "Unhandled exception caught at %s:%d: %s", __FILE__, __LINE__, e.what());
|
||||
LOG(logLevelError, "Unhandled exception caught at %s:%d: %s", __FILE__, __LINE__, e.what());
|
||||
} catch (...) {
|
||||
errlogSevPrintf(errlogMajor, "Unhandled exception caught at %s:%d.", __FILE__, __LINE__);
|
||||
LOG(logLevelError, "Unhandled exception caught at %s:%d.", __FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include <pv/lock.h>
|
||||
|
||||
/* EPICSv3 */
|
||||
#include <errlog.h>
|
||||
#include <logger.h>
|
||||
|
||||
/* standard */
|
||||
#include <set>
|
||||
@@ -28,8 +28,8 @@ namespace epics {
|
||||
namespace pvAccess {
|
||||
|
||||
#define EXCEPTION_GUARD(code) try { code; } \
|
||||
catch (std::exception &e) { errlogSevPrintf(errlogMajor, "Unhandled exception caught from code at %s:%d: %s", __FILE__, __LINE__, e.what()); } \
|
||||
catch (...) { errlogSevPrintf(errlogMajor, "Unhandled exception caught from code at %s:%d.", __FILE__, __LINE__); }
|
||||
catch (std::exception &e) { LOG(logLevelError, "Unhandled exception caught from code at %s:%d: %s", __FILE__, __LINE__, e.what()); } \
|
||||
catch (...) { LOG(logLevelError, "Unhandled exception caught from code at %s:%d.", __FILE__, __LINE__); }
|
||||
|
||||
BlockingClientTCPTransport::BlockingClientTCPTransport(
|
||||
Context::shared_pointer const & context, SOCKET channel,
|
||||
@@ -105,7 +105,7 @@ namespace epics {
|
||||
|
||||
char ipAddrStr[48];
|
||||
ipAddrToDottedIP(&_socketAddress.ia, ipAddrStr, sizeof(ipAddrStr));
|
||||
errlogSevPrintf(errlogInfo, "Acquiring transport to %s.", ipAddrStr);
|
||||
LOG(logLevelDebug, "Acquiring transport to %s.", ipAddrStr);
|
||||
|
||||
Lock lock2(_ownersMutex);
|
||||
// TODO double check? if(_closed) return false;
|
||||
@@ -134,8 +134,8 @@ namespace epics {
|
||||
if(refs>0) {
|
||||
char ipAddrStr[48];
|
||||
ipAddrToDottedIP(&_socketAddress.ia, ipAddrStr, sizeof(ipAddrStr));
|
||||
errlogSevPrintf(
|
||||
errlogInfo,
|
||||
LOG(
|
||||
logLevelDebug,
|
||||
"Transport to %s still has %d client(s) active and closing...",
|
||||
ipAddrStr, refs);
|
||||
|
||||
@@ -161,7 +161,7 @@ namespace epics {
|
||||
char ipAddrStr[48];
|
||||
ipAddrToDottedIP(&_socketAddress.ia, ipAddrStr, sizeof(ipAddrStr));
|
||||
|
||||
errlogSevPrintf(errlogInfo, "Releasing transport to %s.", ipAddrStr);
|
||||
LOG(logLevelDebug, "Releasing transport to %s.", ipAddrStr);
|
||||
|
||||
Lock lock2(_ownersMutex);
|
||||
_owners.erase(clientID);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include <pv/byteBuffer.h>
|
||||
|
||||
/* EPICSv3 */
|
||||
#include <errlog.h>
|
||||
#include <logger.h>
|
||||
|
||||
/* standard */
|
||||
#include <map>
|
||||
@@ -49,8 +49,8 @@ namespace epics {
|
||||
char ipAddrStr[64];
|
||||
ipAddrToDottedIP(&_socketAddress.ia, ipAddrStr, sizeof(ipAddrStr));
|
||||
|
||||
errlogSevPrintf(
|
||||
errlogInfo,
|
||||
LOG(
|
||||
logLevelDebug,
|
||||
"Transport to %s still has %u channel(s) active and closing...",
|
||||
ipAddrStr, (unsigned int)_channels.size());
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <pv/epicsException.h>
|
||||
|
||||
/* EPICSv3 */
|
||||
#include <errlog.h>
|
||||
#include <logger.h>
|
||||
#include <osiSock.h>
|
||||
#include <epicsThread.h>
|
||||
|
||||
@@ -55,14 +55,14 @@ namespace epics {
|
||||
int tryCount = 0;
|
||||
while(tryCount<2) {
|
||||
|
||||
errlogSevPrintf(errlogInfo, "Creating acceptor to %s.", ipAddrStr);
|
||||
LOG(logLevelDebug, "Creating acceptor to %s.", ipAddrStr);
|
||||
|
||||
_serverSocketChannel = epicsSocketCreate(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if(_serverSocketChannel==INVALID_SOCKET) {
|
||||
epicsSocketConvertErrnoToString(strBuffer, sizeof(strBuffer));
|
||||
ostringstream temp;
|
||||
temp<<"Socket create error: "<<strBuffer;
|
||||
errlogSevPrintf(errlogMajor, "%s", temp.str().c_str());
|
||||
LOG(logLevelError, "%s", temp.str().c_str());
|
||||
THROW_BASE_EXCEPTION(temp.str().c_str());
|
||||
}
|
||||
else {
|
||||
@@ -73,12 +73,12 @@ namespace epics {
|
||||
int retval = ::bind(_serverSocketChannel, &_bindAddress.sa, sizeof(sockaddr));
|
||||
if(retval<0) {
|
||||
epicsSocketConvertErrnoToString(strBuffer, sizeof(strBuffer));
|
||||
errlogSevPrintf(errlogMinor, "Socket bind error: %s", strBuffer);
|
||||
LOG(logLevelDebug, "Socket bind error: %s", strBuffer);
|
||||
if(_bindAddress.ia.sin_port!=0) {
|
||||
// failed to bind to specified bind address,
|
||||
// try to get port dynamically, but only once
|
||||
errlogSevPrintf(
|
||||
errlogMinor,
|
||||
LOG(
|
||||
logLevelDebug,
|
||||
"Configured TCP port %d is unavailable, trying to assign it dynamically.",
|
||||
port);
|
||||
_bindAddress.ia.sin_port = htons(0);
|
||||
@@ -99,11 +99,11 @@ namespace epics {
|
||||
if(retval<0) {
|
||||
// error obtaining port number
|
||||
epicsSocketConvertErrnoToString(strBuffer, sizeof(strBuffer));
|
||||
errlogSevPrintf(errlogMinor, "getsockname error: %s", strBuffer);
|
||||
LOG(logLevelDebug, "getsockname error: %s", strBuffer);
|
||||
}
|
||||
else {
|
||||
errlogSevPrintf(
|
||||
errlogInfo,
|
||||
LOG(
|
||||
logLevelInfo,
|
||||
"Using dynamically assigned TCP port %d.",
|
||||
ntohs(_bindAddress.ia.sin_port));
|
||||
}
|
||||
@@ -114,7 +114,7 @@ namespace epics {
|
||||
epicsSocketConvertErrnoToString(strBuffer, sizeof(strBuffer));
|
||||
ostringstream temp;
|
||||
temp<<"Socket listen error: "<<strBuffer;
|
||||
errlogSevPrintf(errlogMajor, "%s", temp.str().c_str());
|
||||
LOG(logLevelError, "%s", temp.str().c_str());
|
||||
THROW_BASE_EXCEPTION(temp.str().c_str());
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace epics {
|
||||
// rise level if port is assigned dynamically
|
||||
char ipAddrStr[48];
|
||||
ipAddrToDottedIP(&_bindAddress.ia, ipAddrStr, sizeof(ipAddrStr));
|
||||
errlogSevPrintf(errlogInfo, "Accepting connections at %s.", ipAddrStr);
|
||||
LOG(logLevelDebug, "Accepting connections at %s.", ipAddrStr);
|
||||
|
||||
bool socketOpen = true;
|
||||
char strBuffer[64];
|
||||
@@ -163,21 +163,21 @@ namespace epics {
|
||||
if(newClient!=INVALID_SOCKET) {
|
||||
// accept succeeded
|
||||
ipAddrToDottedIP(&address.ia, ipAddrStr, sizeof(ipAddrStr));
|
||||
errlogSevPrintf(errlogInfo, "Accepted connection from CA client: %s", ipAddrStr);
|
||||
LOG(logLevelDebug, "Accepted connection from CA client: %s", ipAddrStr);
|
||||
|
||||
// enable TCP_NODELAY (disable Nagle's algorithm)
|
||||
int optval = 1; // true
|
||||
int retval = ::setsockopt(newClient, IPPROTO_TCP, TCP_NODELAY, &optval, sizeof(int));
|
||||
if(retval<0) {
|
||||
epicsSocketConvertErrnoToString(strBuffer, sizeof(strBuffer));
|
||||
errlogSevPrintf(errlogMinor, "Error setting TCP_NODELAY: %s", strBuffer);
|
||||
LOG(logLevelDebug, "Error setting TCP_NODELAY: %s", strBuffer);
|
||||
}
|
||||
|
||||
// enable TCP_KEEPALIVE
|
||||
retval = ::setsockopt(newClient, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(int));
|
||||
if(retval<0) {
|
||||
epicsSocketConvertErrnoToString(strBuffer, sizeof(strBuffer));
|
||||
errlogSevPrintf(errlogMinor, "Error setting SO_KEEPALIVE: %s", strBuffer);
|
||||
LOG(logLevelDebug, "Error setting SO_KEEPALIVE: %s", strBuffer);
|
||||
}
|
||||
|
||||
// TODO tune buffer sizes?!
|
||||
@@ -197,14 +197,14 @@ namespace epics {
|
||||
// validate connection
|
||||
if(!validateConnection(transport, ipAddrStr)) {
|
||||
transport->close(true);
|
||||
errlogSevPrintf(
|
||||
errlogInfo,
|
||||
LOG(
|
||||
logLevelDebug,
|
||||
"Connection to CA client %s failed to be validated, closing it.",
|
||||
ipAddrStr);
|
||||
return;
|
||||
}
|
||||
|
||||
errlogSevPrintf(errlogInfo, "Serving to CA client: %s", ipAddrStr);
|
||||
LOG(logLevelDebug, "Serving to CA client: %s", ipAddrStr);
|
||||
|
||||
}// accept succeeded
|
||||
else
|
||||
@@ -217,7 +217,7 @@ namespace epics {
|
||||
transport->verify();
|
||||
return true;
|
||||
} catch(...) {
|
||||
errlogSevPrintf(errlogInfo, "Validation of %s failed.", address);
|
||||
LOG(logLevelDebug, "Validation of %s failed.", address);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -234,7 +234,7 @@ namespace epics {
|
||||
if(_serverSocketChannel!=INVALID_SOCKET) {
|
||||
char ipAddrStr[48];
|
||||
ipAddrToDottedIP(&_bindAddress.ia, ipAddrStr, sizeof(ipAddrStr));
|
||||
errlogSevPrintf(errlogInfo, "Stopped accepting connections at %s.", ipAddrStr);
|
||||
LOG(logLevelDebug, "Stopped accepting connections at %s.", ipAddrStr);
|
||||
|
||||
epicsSocketDestroy(_serverSocketChannel);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
#include <epicsThread.h>
|
||||
#include <osiSock.h>
|
||||
#include <errlog.h>
|
||||
#include <logger.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
@@ -41,7 +41,7 @@ namespace epics {
|
||||
|
||||
for(int tryCount = 0; tryCount<tries; tryCount++) {
|
||||
|
||||
errlogSevPrintf(errlogInfo,
|
||||
LOG(logLevelDebug,
|
||||
"Opening socket to CA server %s, attempt %d.",
|
||||
strBuffer, tryCount+1);
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace epics {
|
||||
if (socket == INVALID_SOCKET)
|
||||
{
|
||||
epicsSocketConvertErrnoToString(strBuffer, sizeof(strBuffer));
|
||||
errlogSevPrintf(errlogMinor, "Socket create error: %s", strBuffer);
|
||||
LOG(logLevelWarn, "Socket create error: %s", strBuffer);
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
else {
|
||||
@@ -59,7 +59,7 @@ namespace epics {
|
||||
else {
|
||||
epicsSocketDestroy (socket);
|
||||
epicsSocketConvertErrnoToString(strBuffer, sizeof(strBuffer));
|
||||
errlogSevPrintf(errlogMinor, "Socket connect error: %s", strBuffer);
|
||||
LOG(logLevelDebug, "Socket connect error: %s", strBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,9 +81,9 @@ namespace epics {
|
||||
Transport::shared_pointer tt = context->getTransportRegistry()->get("TCP", &address, priority);
|
||||
BlockingClientTCPTransport::shared_pointer transport = std::tr1::static_pointer_cast<BlockingClientTCPTransport>(tt);
|
||||
if(transport.get()) {
|
||||
errlogSevPrintf(errlogInfo,
|
||||
"Reusing existing connection to CA server: %s",
|
||||
ipAddrStr);
|
||||
LOG(logLevelDebug,
|
||||
"Reusing existing connection to CA server: %s",
|
||||
ipAddrStr);
|
||||
if (transport->acquire(client))
|
||||
return transport;
|
||||
}
|
||||
@@ -95,27 +95,27 @@ namespace epics {
|
||||
tt = context->getTransportRegistry()->get("TCP", &address, priority);
|
||||
transport = std::tr1::static_pointer_cast<BlockingClientTCPTransport>(tt);
|
||||
if(transport.get()) {
|
||||
errlogSevPrintf(errlogInfo,
|
||||
"Reusing existing connection to CA server: %s",
|
||||
ipAddrStr);
|
||||
LOG(logLevelDebug,
|
||||
"Reusing existing connection to CA server: %s",
|
||||
ipAddrStr);
|
||||
if (transport->acquire(client))
|
||||
return transport;
|
||||
}
|
||||
|
||||
errlogSevPrintf(errlogInfo, "Connecting to CA server: %s", ipAddrStr);
|
||||
|
||||
LOG(logLevelDebug, "Connecting to CA server: %s", ipAddrStr);
|
||||
|
||||
socket = tryConnect(address, 3);
|
||||
|
||||
// verify
|
||||
if(socket==INVALID_SOCKET) {
|
||||
errlogSevPrintf(errlogMajor,
|
||||
LOG(logLevelDebug,
|
||||
"Connection to CA server %s failed.", ipAddrStr);
|
||||
ostringstream temp;
|
||||
temp<<"Failed to verify TCP connection to '"<<ipAddrStr<<"'.";
|
||||
THROW_BASE_EXCEPTION(temp.str().c_str());
|
||||
}
|
||||
|
||||
errlogSevPrintf(errlogInfo, "Socket connected to CA server: %s.", ipAddrStr);
|
||||
LOG(logLevelDebug, "Socket connected to CA server: %s.", ipAddrStr);
|
||||
|
||||
// enable TCP_NODELAY (disable Nagle's algorithm)
|
||||
int optval = 1; // true
|
||||
@@ -124,7 +124,7 @@ namespace epics {
|
||||
if(retval<0) {
|
||||
char errStr[64];
|
||||
epicsSocketConvertErrnoToString(errStr, sizeof(errStr));
|
||||
errlogSevPrintf(errlogMajor, "Error setting TCP_NODELAY: %s", errStr);
|
||||
LOG(logLevelWarn, "Error setting TCP_NODELAY: %s", errStr);
|
||||
}
|
||||
|
||||
// enable TCP_KEEPALIVE
|
||||
@@ -134,7 +134,7 @@ namespace epics {
|
||||
{
|
||||
char errStr[64];
|
||||
epicsSocketConvertErrnoToString(errStr, sizeof(errStr));
|
||||
errlogSevPrintf(errlogMinor, "Error setting SO_KEEPALIVE: %s", errStr);
|
||||
LOG(logLevelWarn, "Error setting SO_KEEPALIVE: %s", errStr);
|
||||
}
|
||||
|
||||
// TODO tune buffer sizes?! Win32 defaults are 8k, which is OK
|
||||
@@ -146,8 +146,8 @@ namespace epics {
|
||||
|
||||
// verify
|
||||
if(!transport->waitUntilVerified(3.0)) {
|
||||
errlogSevPrintf(
|
||||
errlogMinor,
|
||||
LOG(
|
||||
logLevelDebug,
|
||||
"Connection to CA server %s failed to be validated, closing it.",
|
||||
ipAddrStr);
|
||||
ostringstream temp;
|
||||
@@ -157,13 +157,11 @@ namespace epics {
|
||||
|
||||
// TODO send security token
|
||||
|
||||
errlogSevPrintf(errlogInfo, "Connected to CA server: %s", ipAddrStr);
|
||||
LOG(logLevelDebug, "Connected to CA server: %s", ipAddrStr);
|
||||
|
||||
_namedLocker.releaseSynchronizationObject(&address);
|
||||
return transport;
|
||||
} catch(std::exception& ex) {
|
||||
// TODO
|
||||
printf("ex %s\n", ex.what());
|
||||
if(transport.get())
|
||||
transport->close(true);
|
||||
else if(socket!=INVALID_SOCKET) epicsSocketDestroy(socket);
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <osdSock.h>
|
||||
#include <osiSock.h>
|
||||
#include <epicsThread.h>
|
||||
#include <errlog.h>
|
||||
#include <logger.h>
|
||||
|
||||
/* standard */
|
||||
#include <sys/types.h>
|
||||
@@ -133,7 +133,7 @@ namespace epics {
|
||||
_socketSendBufferSize = MAX_TCP_RECV;
|
||||
char errStr[64];
|
||||
epicsSocketConvertErrnoToString(errStr, sizeof(errStr));
|
||||
errlogSevPrintf(errlogMinor,
|
||||
LOG(logLevelDebug,
|
||||
"Unable to retrieve socket send buffer size: %s",
|
||||
errStr);
|
||||
}
|
||||
@@ -143,7 +143,7 @@ namespace epics {
|
||||
if(retval<0) {
|
||||
char errStr[64];
|
||||
epicsSocketConvertErrnoToString(errStr, sizeof(errStr));
|
||||
errlogSevPrintf(errlogMajor,
|
||||
LOG(logLevelError,
|
||||
"Error fetching socket remote address: %s",
|
||||
errStr);
|
||||
}
|
||||
@@ -177,7 +177,7 @@ namespace epics {
|
||||
//
|
||||
|
||||
String threadName = "TCP-receive " + socketAddressString;
|
||||
errlogSevPrintf(errlogInfo, "Starting thread: %s", threadName.c_str());
|
||||
LOG(logLevelDebug, "Starting thread: %s", threadName.c_str());
|
||||
|
||||
_rcvThreadId = epicsThreadCreate(threadName.c_str(),
|
||||
epicsThreadPriorityMedium,
|
||||
@@ -189,7 +189,7 @@ namespace epics {
|
||||
//
|
||||
|
||||
threadName = "TCP-send " + socketAddressString;
|
||||
errlogSevPrintf(errlogInfo, "Starting thread: %s",threadName.c_str());
|
||||
LOG(logLevelDebug, "Starting thread: %s",threadName.c_str());
|
||||
|
||||
_sendThreadId = epicsThreadCreate(threadName.c_str(),
|
||||
epicsThreadPriorityMedium,
|
||||
@@ -258,7 +258,7 @@ namespace epics {
|
||||
{
|
||||
char errStr[64];
|
||||
epicsSocketConvertErrnoToString(errStr, sizeof(errStr));
|
||||
errlogSevPrintf(errlogMajor,
|
||||
LOG(logLevelError,
|
||||
"Socket getsockopt SO_RCVBUF error: %s",
|
||||
errStr);
|
||||
}
|
||||
@@ -394,7 +394,7 @@ namespace epics {
|
||||
|
||||
// no more data and we have some payload left => read buffer
|
||||
if(_storedPayloadSize>=size) {
|
||||
//errlogSevPrintf(errlogInfo,
|
||||
//LOG(logLevelInfo,
|
||||
// "storedPayloadSize >= size, remaining: %d",
|
||||
// _socketBuffer->getRemaining());
|
||||
|
||||
@@ -516,8 +516,8 @@ namespace epics {
|
||||
_magicAndVersion = _socketBuffer->getShort();
|
||||
if((short)(_magicAndVersion&0xFFF0)!=CA_MAGIC_AND_MAJOR_VERSION) {
|
||||
// error... disconnect
|
||||
errlogSevPrintf(
|
||||
errlogMinor,
|
||||
LOG(
|
||||
logLevelError,
|
||||
"Invalid header received from client %s, disconnecting...",
|
||||
inetAddressToString(_socketAddress).c_str());
|
||||
close(true);
|
||||
@@ -565,8 +565,8 @@ namespace epics {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
errlogSevPrintf(
|
||||
errlogMajor,
|
||||
LOG(
|
||||
logLevelError,
|
||||
"Unknown packet type %d, received from client %s, disconnecting...",
|
||||
type,
|
||||
inetAddressToString(_socketAddress).c_str());
|
||||
@@ -667,7 +667,7 @@ namespace epics {
|
||||
_sendBuffer->setLimit(_sendBuffer->getSize());
|
||||
}
|
||||
//} catch(std::exception& e) {
|
||||
// errlogSevPrintf(errlogMajor, "%s", e.what());
|
||||
// LOG(logLevelError, "%s", e.what());
|
||||
// // error, release lock
|
||||
// clearAndReleaseBuffer();
|
||||
} catch(...) {
|
||||
@@ -689,7 +689,7 @@ namespace epics {
|
||||
int limit = buffer->getLimit();
|
||||
int bytesToSend = limit-buffer->getPosition();
|
||||
|
||||
//errlogSevPrintf(errlogInfo,"Total bytes to send: %d", bytesToSend);
|
||||
//LOG(logLevelInfo,"Total bytes to send: %d", bytesToSend);
|
||||
|
||||
// limit sending
|
||||
if(bytesToSend>maxBytesToSend) {
|
||||
@@ -697,7 +697,7 @@ namespace epics {
|
||||
buffer->setLimit(buffer->getPosition()+bytesToSend);
|
||||
}
|
||||
|
||||
//errlogSevPrintf(errlogInfo,
|
||||
//LOG(logLevelInfo,
|
||||
// "Sending %d of total %d bytes in the packet to %s.",
|
||||
// bytesToSend, limit,
|
||||
// inetAddressToString(_socketAddress).c_str());
|
||||
@@ -730,14 +730,14 @@ namespace epics {
|
||||
epicsSocketConvertErrnoToString(errStr, sizeof(errStr));
|
||||
ostringstream temp;
|
||||
temp<<"error in sending TCP data: "<<errStr;
|
||||
//errlogSevPrintf(errlogMajor, "%s", temp.str().c_str());
|
||||
//LOG(logLevelError, "%s", temp.str().c_str());
|
||||
THROW_BASE_EXCEPTION(temp.str().c_str());
|
||||
}
|
||||
else if(bytesSent==0) {
|
||||
|
||||
// TODO WINSOCK indicates disconnect by returning zero here !!!
|
||||
|
||||
//errlogSevPrintf(errlogInfo,
|
||||
//LOG(logLevelInfo,
|
||||
// "Buffer full, position %d of total %d bytes.",
|
||||
// buffer->getPosition(), limit);
|
||||
|
||||
@@ -746,7 +746,7 @@ namespace epics {
|
||||
*/
|
||||
if(bytesSent==maxBytesToSend) buffer->setLimit(limit);
|
||||
|
||||
//errlogSevPrintf(errlogInfo,
|
||||
//LOG(logLevelInfo,
|
||||
// "Send buffer full for %s, waiting...",
|
||||
// inetAddressToString(_socketAddress));
|
||||
return false;
|
||||
@@ -766,7 +766,7 @@ namespace epics {
|
||||
buffer->setLimit(buffer->getPosition()+bytesToSend);
|
||||
}
|
||||
|
||||
//errlogSevPrintf(errlogInfo,
|
||||
//LOG(logLevelInfo,
|
||||
// "Sent, position %d of total %d bytes.",
|
||||
// buffer->getPosition(), limit);
|
||||
} // while
|
||||
@@ -843,7 +843,7 @@ namespace epics {
|
||||
endMessage(false);// automatic end (to set payload)
|
||||
|
||||
} catch(std::exception &e) {
|
||||
errlogSevPrintf(errlogMajor, "%s", e.what());
|
||||
//LOG(logLevelError, "%s", e.what());
|
||||
_sendBuffer->setPosition(_lastMessageStartPosition);
|
||||
} catch(...) {
|
||||
_sendBuffer->setPosition(_lastMessageStartPosition);
|
||||
@@ -860,7 +860,7 @@ namespace epics {
|
||||
void BlockingTCPTransport::freeConnectionResorces() {
|
||||
freeSendBuffers();
|
||||
|
||||
errlogSevPrintf(errlogInfo, "Connection to %s closed.",
|
||||
LOG(logLevelDebug, "Connection to %s closed.",
|
||||
inetAddressToString(_socketAddress).c_str());
|
||||
|
||||
if(_channel!=INVALID_SOCKET) {
|
||||
@@ -902,7 +902,7 @@ printf("rcvThreadRunnner exception\n");
|
||||
try {
|
||||
obj->processSendQueue();
|
||||
} catch (std::exception& ex) {
|
||||
printf("sendThreadRunnner exception %s\n", ex.what());
|
||||
printf("sendThreadRunnner exception %s\n", ex.what()); // TODO
|
||||
} catch (...) {
|
||||
printf("sendThreadRunnner exception\n");
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <pv/remote.h>
|
||||
|
||||
/* EPICSv3 */
|
||||
#include <errlog.h>
|
||||
#include <logger.h>
|
||||
#include <osiSock.h>
|
||||
|
||||
/* standard */
|
||||
@@ -26,14 +26,14 @@ namespace epics {
|
||||
auto_ptr<ResponseHandler>& responseHandler, osiSockAddr& bindAddress,
|
||||
short transportRevision, int16 priority) {
|
||||
|
||||
errlogSevPrintf(errlogInfo, "Creating datagram socket to: %s",
|
||||
LOG(logLevelDebug, "Creating datagram socket to: %s",
|
||||
inetAddressToString(bindAddress).c_str());
|
||||
|
||||
SOCKET socket = epicsSocketCreate(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if(socket==INVALID_SOCKET) {
|
||||
char errStr[64];
|
||||
epicsSocketConvertErrnoToString(errStr, sizeof(errStr));
|
||||
errlogSevPrintf(errlogMajor, "Error creating socket: %s", errStr);
|
||||
LOG(logLevelError, "Error creating socket: %s", errStr);
|
||||
return Transport::shared_pointer();
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace epics {
|
||||
{
|
||||
char errStr[64];
|
||||
epicsSocketConvertErrnoToString(errStr, sizeof(errStr));
|
||||
errlogSevPrintf(errlogMajor, "Error setting SO_BROADCAST: %s", errStr);
|
||||
LOG(logLevelError, "Error setting SO_BROADCAST: %s", errStr);
|
||||
epicsSocketDestroy (socket);
|
||||
return Transport::shared_pointer();
|
||||
}
|
||||
@@ -60,7 +60,7 @@ namespace epics {
|
||||
if(retval<0) {
|
||||
char errStr[64];
|
||||
epicsSocketConvertErrnoToString(errStr, sizeof(errStr));
|
||||
errlogSevPrintf(errlogMajor, "Error binding socket: %s", errStr);
|
||||
LOG(logLevelError, "Error binding socket: %s", errStr);
|
||||
epicsSocketDestroy (socket);
|
||||
return Transport::shared_pointer();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
/* EPICSv3 */
|
||||
#include <osdSock.h>
|
||||
#include <osiSock.h>
|
||||
#include <errlog.h>
|
||||
#include <logger.h>
|
||||
#include <epicsThread.h>
|
||||
|
||||
/* standard */
|
||||
@@ -57,11 +57,11 @@ namespace epics {
|
||||
timeout.tv_sec = 1;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
if (setsockopt (_channel, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)) < 0)
|
||||
if (::setsockopt (_channel, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)) < 0)
|
||||
{
|
||||
char errStr[64];
|
||||
epicsSocketConvertErrnoToString(errStr, sizeof(errStr));
|
||||
errlogSevPrintf(errlogMajor,
|
||||
LOG(logLevelError,
|
||||
"Failed to set SO_RCVTIMEO for UDP socket %s: %s.",
|
||||
inetAddressToString(_bindAddress).c_str(), errStr);
|
||||
}
|
||||
@@ -84,7 +84,7 @@ namespace epics {
|
||||
void BlockingUDPTransport::start() {
|
||||
|
||||
String threadName = "UDP-receive "+inetAddressToString(_bindAddress);
|
||||
errlogSevPrintf(errlogInfo, "Starting thread: %s",threadName.c_str());
|
||||
LOG(logLevelDebug, "Starting thread: %s",threadName.c_str());
|
||||
|
||||
_threadId = epicsThreadCreate(threadName.c_str(),
|
||||
epicsThreadPriorityMedium,
|
||||
@@ -102,7 +102,7 @@ namespace epics {
|
||||
if(_closed) return;
|
||||
_closed = true;
|
||||
|
||||
errlogSevPrintf(errlogInfo,
|
||||
LOG(logLevelDebug,
|
||||
"UDP socket %s closed.",
|
||||
inetAddressToString(_bindAddress).c_str());
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace epics {
|
||||
{
|
||||
if (!_shutdownEvent.wait(5.0))
|
||||
{
|
||||
errlogSevPrintf(errlogMajor,
|
||||
LOG(logLevelError,
|
||||
"Receive thread for UDP socket %s has not exited.",
|
||||
inetAddressToString(_bindAddress).c_str());
|
||||
}
|
||||
@@ -233,7 +233,7 @@ namespace epics {
|
||||
{
|
||||
char errStr[64];
|
||||
epicsSocketConvertErrnoToString(errStr, sizeof(errStr));
|
||||
errlogSevPrintf(errlogMajor, "Socket recvfrom error: %s", errStr);
|
||||
LOG(logLevelError, "Socket recvfrom error: %s", errStr);
|
||||
}
|
||||
|
||||
close(true, false);
|
||||
@@ -248,7 +248,7 @@ namespace epics {
|
||||
|
||||
char threadName[40];
|
||||
epicsThreadGetName(_threadId, threadName, 40);
|
||||
errlogSevPrintf(errlogInfo, "Thread '%s' exiting", threadName);
|
||||
LOG(logLevelDebug, "Thread '%s' exiting", threadName);
|
||||
|
||||
_shutdownEvent.signal();
|
||||
}
|
||||
@@ -300,7 +300,7 @@ namespace epics {
|
||||
{
|
||||
char errStr[64];
|
||||
epicsSocketConvertErrnoToString(errStr, sizeof(errStr));
|
||||
errlogSevPrintf(errlogMajor, "Socket sendto error: %s", errStr);
|
||||
LOG(logLevelDebug, "Socket sendto error: %s", errStr);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ namespace epics {
|
||||
{
|
||||
char errStr[64];
|
||||
epicsSocketConvertErrnoToString(errStr, sizeof(errStr));
|
||||
errlogSevPrintf(errlogMajor, "Socket sendto error: %s", errStr);
|
||||
LOG(logLevelDebug, "Socket sendto error: %s", errStr);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -342,7 +342,7 @@ namespace epics {
|
||||
{
|
||||
char errStr[64];
|
||||
epicsSocketConvertErrnoToString(errStr, sizeof(errStr));
|
||||
errlogSevPrintf(errlogMajor, "Socket getsockopt SO_RCVBUF error: %s", errStr);
|
||||
LOG(logLevelError, "Socket getsockopt SO_RCVBUF error: %s", errStr);
|
||||
}
|
||||
|
||||
return sockBufSize;
|
||||
|
||||
@@ -304,7 +304,7 @@ void SearchTimer::callback()
|
||||
|
||||
{
|
||||
Lock guard(_volMutex);
|
||||
_startSequenceNumber = _chanSearchManager->getSequenceNumber() + 1;
|
||||
_startSequenceNumber = _chanSearchManager->getSequenceNumber();
|
||||
_searchAttempts = 0;
|
||||
_searchRespones = 0;
|
||||
}
|
||||
@@ -337,6 +337,12 @@ void SearchTimer::callback()
|
||||
|
||||
bool requestSent = true;
|
||||
bool allowNewFrame = (framesSent+1) < _framesPerTry;
|
||||
|
||||
{
|
||||
Lock guard(_volMutex);
|
||||
_endSequenceNumber = _chanSearchManager->getSequenceNumber() + 1;
|
||||
}
|
||||
|
||||
bool frameWasSent = _chanSearchManager->generateSearchRequestMessage(channel, allowNewFrame);
|
||||
if(frameWasSent)
|
||||
{
|
||||
@@ -392,6 +398,12 @@ void SearchTimer::callback()
|
||||
// flush out the search request buffer
|
||||
if(triesInFrame > 0)
|
||||
{
|
||||
|
||||
{
|
||||
Lock guard(_volMutex);
|
||||
_endSequenceNumber = _chanSearchManager->getSequenceNumber() + 1;
|
||||
}
|
||||
|
||||
_chanSearchManager->flushSendBuffer();
|
||||
framesSent++;
|
||||
}
|
||||
@@ -400,6 +412,7 @@ void SearchTimer::callback()
|
||||
{
|
||||
Lock guard(_volMutex);
|
||||
_endSequenceNumber = _chanSearchManager->getSequenceNumber();
|
||||
//printf("[%d] sn %d -> %d\n", _timerIndex, _startSequenceNumber, _endSequenceNumber);
|
||||
|
||||
// reschedule
|
||||
canceled = _canceled;
|
||||
@@ -424,8 +437,10 @@ void SearchTimer::searchResponse(int32 responseSequenceNumber, bool isSequenceNu
|
||||
|
||||
if(isSequenceNumberValid)
|
||||
{
|
||||
validResponse = _startSequenceNumber <= _chanSearchManager->getSequenceNumber() && _chanSearchManager->getSequenceNumber() <= _endSequenceNumber;
|
||||
validResponse = _startSequenceNumber <= responseSequenceNumber && responseSequenceNumber <= _endSequenceNumber;
|
||||
}
|
||||
//if (!validResponse)
|
||||
// printf("[%d] not valid response %d < %d < %d\n", _timerIndex, _startSequenceNumber,responseSequenceNumber, _endSequenceNumber);
|
||||
}
|
||||
|
||||
|
||||
@@ -582,7 +597,7 @@ void ChannelSearchManager::searchResponse(int32 cid, int32 seqNo, int8 minorRevi
|
||||
now.getCurrent();
|
||||
_timers[timerIndex]->searchResponse(seqNo, seqNo != 0, now.getMilliseconds());
|
||||
|
||||
// then notify SearchInstance
|
||||
// then noftify SearchInstance
|
||||
si->searchResponse(minorRevision, serverAddress);
|
||||
//si->release();
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <pv/clientContextImpl.h>
|
||||
#include <pv/configuration.h>
|
||||
#include <pv/beaconHandler.h>
|
||||
#include <errlog.h>
|
||||
#include <logger.h>
|
||||
#include <pv/bitSetUtil.h>
|
||||
|
||||
using std::tr1::dynamic_pointer_cast;
|
||||
@@ -46,8 +46,8 @@ namespace epics {
|
||||
|
||||
|
||||
#define EXCEPTION_GUARD(code) try { code; } \
|
||||
catch (std::exception &e) { errlogSevPrintf(errlogMajor, "Unhandled exception caught from client code at %s:%d: %s", __FILE__, __LINE__, e.what()); } \
|
||||
catch (...) { errlogSevPrintf(errlogMajor, "Unhandled exception caught from client code at %s:%d.", __FILE__, __LINE__); }
|
||||
catch (std::exception &e) { LOG(logLevelError, "Unhandled exception caught from client code at %s:%d: %s", __FILE__, __LINE__, e.what()); } \
|
||||
catch (...) { LOG(logLevelError, "Unhandled exception caught from client code at %s:%d.", __FILE__, __LINE__); }
|
||||
|
||||
struct delayed_destroyable_deleter
|
||||
{
|
||||
@@ -211,9 +211,9 @@ namespace epics {
|
||||
}
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
errlogSevPrintf(errlogMajor, "Unhandled exception caught from client code at %s:%d: %s", __FILE__, __LINE__, e.what());
|
||||
LOG(logLevelError, "Unhandled exception caught from client code at %s:%d: %s", __FILE__, __LINE__, e.what());
|
||||
}
|
||||
catch (...) { errlogSevPrintf(errlogMajor, "Unhandled exception caught from client code at %s:%d.", __FILE__, __LINE__);
|
||||
catch (...) { LOG(logLevelError, "Unhandled exception caught from client code at %s:%d.", __FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2286,7 +2286,7 @@ namespace epics {
|
||||
char ipAddrStr[48];
|
||||
ipAddrToDottedIP(&responseFrom->ia, ipAddrStr, sizeof(ipAddrStr));
|
||||
|
||||
errlogSevPrintf(errlogInfo,
|
||||
LOG(logLevelInfo,
|
||||
"Undecipherable message (bad response type %d) from %s.",
|
||||
command, ipAddrStr);
|
||||
}
|
||||
@@ -3207,7 +3207,7 @@ namespace epics {
|
||||
void disconnect(bool initiateSearch, bool remoteDestroy) {
|
||||
Lock guard(m_channelMutex);
|
||||
|
||||
if (m_connectionState != CONNECTED && !m_transport)
|
||||
if (m_connectionState != CONNECTED)
|
||||
return;
|
||||
|
||||
if (!initiateSearch) {
|
||||
@@ -4028,6 +4028,7 @@ TODO
|
||||
{
|
||||
try
|
||||
{
|
||||
// TODO we are creating a new response handler even-though we might not need a new transprot !!!
|
||||
ClientContextImpl::shared_pointer thisPointer = shared_from_this();
|
||||
auto_ptr<ResponseHandler> handler(new ClientResponseHandler(thisPointer));
|
||||
return m_connector->connect(client, handler, *serverAddress, minorRevision, priority);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <pv/introspectionRegistry.h>
|
||||
|
||||
#include <errlog.h>
|
||||
#include <logger.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include <pv/serverContext.h>
|
||||
@@ -78,7 +78,7 @@ void BeaconEmitter::send(ByteBuffer* buffer, TransportSendControl* control)
|
||||
}
|
||||
catch (...) {
|
||||
// we have to proctect internal code from external implementation...
|
||||
errlogSevPrintf(errlogMinor, "BeaconServerStatusProvider implementation thrown an exception.");
|
||||
LOG(logLevelDebug, "BeaconServerStatusProvider implementation thrown an exception.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <pv/byteBuffer.h>
|
||||
|
||||
#include <osiSock.h>
|
||||
#include <errlog.h>
|
||||
#include <logger.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
@@ -34,7 +34,7 @@ void ServerBadResponse::handleResponse(osiSockAddr* responseFrom,
|
||||
char ipAddrStr[48];
|
||||
ipAddrToDottedIP(&responseFrom->ia, ipAddrStr, sizeof(ipAddrStr));
|
||||
|
||||
errlogSevPrintf(errlogInfo,
|
||||
LOG(logLevelInfo,
|
||||
"Undecipherable message (bad response type %d) from %s.",
|
||||
command, ipAddrStr);
|
||||
|
||||
@@ -76,7 +76,7 @@ void ServerResponseHandler::handleResponse(osiSockAddr* responseFrom,
|
||||
{
|
||||
if(command<0||command>=(int8)m_handlerTable.size())
|
||||
{
|
||||
errlogSevPrintf(errlogMinor,
|
||||
LOG(logLevelDebug,
|
||||
"Invalid (or unsupported) command: %x.", (0xFF&command));
|
||||
|
||||
// TODO remove debug output
|
||||
@@ -216,14 +216,14 @@ void ServerChannelFindRequesterImpl::channelFindResult(const Status& status, Cha
|
||||
{
|
||||
if ((_responseCount+1) == _expectedResponseCount)
|
||||
{
|
||||
errlogSevPrintf(errlogMinor,"[ServerChannelFindRequesterImpl::channelFindResult] More responses received than expected fpr channel '%s'!", _name.c_str());
|
||||
LOG(logLevelDebug,"[ServerChannelFindRequesterImpl::channelFindResult] More responses received than expected fpr channel '%s'!", _name.c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (wasFound && _wasFound)
|
||||
{
|
||||
errlogSevPrintf(errlogMinor,"[ServerChannelFindRequesterImpl::channelFindResult] Channel '%s' is hosted by different channel providers!", _name.c_str());
|
||||
LOG(logLevelDebug,"[ServerChannelFindRequesterImpl::channelFindResult] Channel '%s' is hosted by different channel providers!", _name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ void ServerCreateChannelHandler::handleResponse(osiSockAddr* responseFrom,
|
||||
|
||||
char host[100];
|
||||
sockAddrToA(&transport->getRemoteAddress()->sa,host,100);
|
||||
errlogSevPrintf(errlogMinor,"Zero length channel name, disconnecting client: %s", host);
|
||||
LOG(logLevelDebug,"Zero length channel name, disconnecting client: %s", host);
|
||||
disconnect(transport);
|
||||
return;
|
||||
}
|
||||
@@ -299,7 +299,7 @@ void ServerCreateChannelHandler::handleResponse(osiSockAddr* responseFrom,
|
||||
{
|
||||
char host[100];
|
||||
sockAddrToA(&transport->getRemoteAddress()->sa,host,100);
|
||||
errlogSevPrintf(errlogMinor,"Unreasonable channel name length, disconnecting client: %s", host);
|
||||
LOG(logLevelDebug,"Unreasonable channel name length, disconnecting client: %s", host);
|
||||
disconnect(transport);
|
||||
return;
|
||||
}
|
||||
@@ -385,7 +385,7 @@ void ServerChannelRequesterImpl::channelCreated(const Status& status, Channel::s
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
errlogSevPrintf(errlogMinor, "Exception caught when creating channel: %s", _channelName.c_str());
|
||||
LOG(logLevelDebug, "Exception caught when creating channel: %s", _channelName.c_str());
|
||||
{
|
||||
Lock guard(_mutex);
|
||||
_status = Status(Status::STATUSTYPE_FATAL, "failed to create channel", e.what());
|
||||
@@ -396,7 +396,7 @@ void ServerChannelRequesterImpl::channelCreated(const Status& status, Channel::s
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
errlogSevPrintf(errlogMinor, "Exception caught when creating channel: %s", _channelName.c_str());
|
||||
LOG(logLevelDebug, "Exception caught when creating channel: %s", _channelName.c_str());
|
||||
{
|
||||
Lock guard(_mutex);
|
||||
_status = Status(Status::STATUSTYPE_FATAL, "failed to create channel");
|
||||
@@ -422,7 +422,7 @@ String ServerChannelRequesterImpl::getRequesterName()
|
||||
|
||||
void ServerChannelRequesterImpl::message(const String message, const MessageType messageType)
|
||||
{
|
||||
errlogSevPrintf(errlogMinor, "[%s] %s", messageTypeName[messageType].c_str(), message.c_str());
|
||||
LOG(logLevelDebug, "[%s] %s", messageTypeName[messageType].c_str(), message.c_str());
|
||||
}
|
||||
|
||||
void ServerChannelRequesterImpl::lock()
|
||||
@@ -498,7 +498,7 @@ void ServerDestroyChannelHandler::handleResponse(osiSockAddr* responseFrom,
|
||||
{
|
||||
char host[100];
|
||||
sockAddrToA(&responseFrom->sa,host,100);
|
||||
errlogSevPrintf(errlogMinor, "Trying to destroy a channel that no longer exists (SID: %d, CID %d, client: %s).", sid, cid, host);
|
||||
LOG(logLevelDebug, "Trying to destroy a channel that no longer exists (SID: %d, CID %d, client: %s).", sid, cid, host);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <pv/serverContext.h>
|
||||
#include <pv/responseHandlers.h>
|
||||
#include <epicsSignal.h>
|
||||
|
||||
using std::tr1::dynamic_pointer_cast;
|
||||
using std::tr1::static_pointer_cast;
|
||||
@@ -42,6 +43,10 @@ ServerContextImpl::ServerContextImpl():
|
||||
_beaconServerStatusProvider()
|
||||
|
||||
{
|
||||
// TODO maybe there is a better place for this (when there will be some factory)
|
||||
epicsSignalInstallSigAlarmIgnore ();
|
||||
epicsSignalInstallSigPipeIgnore ();
|
||||
|
||||
initializeLogger();
|
||||
loadConfiguration();
|
||||
}
|
||||
@@ -372,7 +377,7 @@ void ServerContextImpl::destroyAllTransports()
|
||||
if (size == 0)
|
||||
return;
|
||||
|
||||
errlogSevPrintf(errlogInfo, "Server context still has %d transport(s) active and closing...", size);
|
||||
LOG(logLevelInfo, "Server context still has %d transport(s) active and closing...", size);
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
@@ -384,12 +389,12 @@ void ServerContextImpl::destroyAllTransports()
|
||||
catch (std::exception &e)
|
||||
{
|
||||
// do all exception safe, log in case of an error
|
||||
errlogSevPrintf(errlogMajor, "Unhandled exception caught from client code at %s:%d: %s", __FILE__, __LINE__, e.what());
|
||||
LOG(logLevelError, "Unhandled exception caught from client code at %s:%d: %s", __FILE__, __LINE__, e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// do all exception safe, log in case of an error
|
||||
errlogSevPrintf(errlogMajor, "Unhandled exception caught from client code at %s:%d.", __FILE__, __LINE__);
|
||||
LOG(logLevelError, "Unhandled exception caught from client code at %s:%d.", __FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include <pv/beaconEmitter.h>
|
||||
#include <pv/logger.h>
|
||||
|
||||
#include <errlog.h>
|
||||
#include <logger.h>
|
||||
|
||||
namespace epics {
|
||||
namespace pvAccess {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include <osiSock.h>
|
||||
#include <ellLib.h>
|
||||
#include <epicsAssert.h>
|
||||
#include <errlog.h>
|
||||
#include <logger.h>
|
||||
|
||||
/* standard */
|
||||
#include <vector>
|
||||
@@ -94,7 +94,7 @@ namespace epics {
|
||||
*/
|
||||
pIfreqList = new ifreq[nelem];
|
||||
if(!pIfreqList) {
|
||||
errlogSevPrintf(errlogMajor,
|
||||
LOG(logLevelError,
|
||||
"getBroadcastAddresses(): no memory to complete request");
|
||||
addDefaultBroadcastAddress(retVector, defaultPort);
|
||||
return retVector;
|
||||
@@ -106,7 +106,7 @@ namespace epics {
|
||||
memset(ifconf.ifc_req, 0, ifconf.ifc_len);
|
||||
status = ioctl(sock, SIOCGIFCONF, &ifconf);
|
||||
if(status<0||ifconf.ifc_len==0) {
|
||||
errlogSevPrintf(errlogMinor,
|
||||
LOG(logLevelDebug,
|
||||
"getBroadcastAddresses(): unable to fetch network interface configuration");
|
||||
delete[] pIfreqList;
|
||||
addDefaultBroadcastAddress(retVector, defaultPort);
|
||||
@@ -138,8 +138,8 @@ namespace epics {
|
||||
sizeof(ifrBuff.ifr_name));
|
||||
status = ioctl(sock, SIOCGIFFLAGS, &ifrBuff);
|
||||
if(status) {
|
||||
errlogSevPrintf(
|
||||
errlogMinor,
|
||||
LOG(
|
||||
logLevelDebug,
|
||||
"getBroadcastAddresses(): net intf flags fetch for \"%s\" failed",
|
||||
pifreq->ifr_name);
|
||||
continue;
|
||||
@@ -170,8 +170,8 @@ namespace epics {
|
||||
sizeof(ifrBuff.ifr_name));
|
||||
status = ioctl(sock, SIOCGIFBRDADDR, &ifrBuff);
|
||||
if(status) {
|
||||
errlogSevPrintf(
|
||||
errlogMinor,
|
||||
LOG(
|
||||
logLevelDebug,
|
||||
"getBroadcastAddresses(): net intf \"%s\": bcast addr fetch fail",
|
||||
pifreq->ifr_name);
|
||||
continue;
|
||||
@@ -184,8 +184,8 @@ namespace epics {
|
||||
sizeof(ifrBuff.ifr_name));
|
||||
status = ioctl(sock, SIOCGIFDSTADDR, &ifrBuff);
|
||||
if(status) {
|
||||
errlogSevPrintf(
|
||||
errlogMinor,
|
||||
LOG(
|
||||
logLevelDebug,
|
||||
"getBroadcastAddresses(): net intf \"%s\": pt to pt addr fetch fail",
|
||||
pifreq->ifr_name);
|
||||
continue;
|
||||
@@ -194,8 +194,8 @@ namespace epics {
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
errlogSevPrintf(
|
||||
errlogMinor,
|
||||
LOG(
|
||||
logLevelDebug,
|
||||
"getBroadcastAddresses(): net intf \"%s\": not point to point or bcast?",
|
||||
pifreq->ifr_name);
|
||||
continue;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <pv/pvType.h>
|
||||
|
||||
#include <epicsExit.h>
|
||||
#include <errlog.h>
|
||||
#include <logger.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@@ -24,8 +24,43 @@ using std::ofstream;
|
||||
using std::ios;
|
||||
using std::endl;
|
||||
|
||||
#include <errlog.h>
|
||||
|
||||
#include <epicsTime.h>
|
||||
|
||||
namespace epics {
|
||||
namespace pvAccess {
|
||||
|
||||
#define TIMETEXTLEN 32
|
||||
|
||||
static pvAccessLogLevel g_pvAccessLogLevel = logLevelDebug; //logLevelInfo;
|
||||
|
||||
void pvAccessLog(pvAccessLogLevel level, const char* format, ...)
|
||||
{
|
||||
// TODO lock
|
||||
if (level >= g_pvAccessLogLevel)
|
||||
{
|
||||
char timeText[TIMETEXTLEN];
|
||||
epicsTimeStamp tsNow;
|
||||
|
||||
epicsTimeGetCurrent(&tsNow);
|
||||
epicsTimeToStrftime(timeText, TIMETEXTLEN, "%Y-%m-%dT%H:%M:%S.%03f", &tsNow);
|
||||
|
||||
printf("%s ", timeText);
|
||||
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
vprintf(format, arg);
|
||||
va_end(arg);
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void pvAccessSetLogLevel(pvAccessLogLevel level)
|
||||
{
|
||||
g_pvAccessLogLevel = level;
|
||||
}
|
||||
|
||||
class FileLogger : public NoDefaultMethods {
|
||||
public:
|
||||
|
||||
@@ -10,9 +10,47 @@
|
||||
|
||||
#include <pv/pvType.h>
|
||||
|
||||
#include <errlog.h>
|
||||
|
||||
namespace epics {
|
||||
namespace pvAccess {
|
||||
|
||||
typedef enum { logLevelAll = 0, logLevelTrace, logLevelDebug, logLevelInfo,
|
||||
logLevelWarn, logLevelError, logLevelFatal, logLevelOff } pvAccessLogLevel;
|
||||
/*
|
||||
ALL
|
||||
The ALL has the lowest possible rank and is intended to turn on all logging.
|
||||
TRACE
|
||||
The TRACE Level designates finer-grained informational events than the DEBUG
|
||||
DEBUG
|
||||
The DEBUG Level designates fine-grained informational events that are most useful to debug an application.
|
||||
INFO
|
||||
The INFO level designates informational messages that highlight the progress of the application at coarse-grained level.
|
||||
WARN
|
||||
The WARN level designates potentially harmful situations.
|
||||
ERROR
|
||||
The ERROR level designates error events that might still allow the application to continue running.
|
||||
FATAL
|
||||
The FATAL level designates very severe error events that will presumably lead the application to abort.
|
||||
OFF
|
||||
The OFF has the highest possible rank and is intended to turn off logging.
|
||||
*/
|
||||
|
||||
|
||||
void pvAccessLog(pvAccessLogLevel level, const char* format, ...);
|
||||
void pvAccessSetLogLevel(pvAccessLogLevel level);
|
||||
|
||||
#define LOG(level, format, ...) pvAccessLog(level, format, ##__VA_ARGS__)
|
||||
#define SET_LOG_LEVEL(level) pvAccessSetLogLevel(level)
|
||||
|
||||
// EPICS errlog
|
||||
//#define LOG errlogSevPrintf
|
||||
//#define SET_LOG_LEVEL(level) errlogSetSevToLog(level)
|
||||
|
||||
// none
|
||||
//#define LOG(level, fmt, ...)
|
||||
//#define SET_LOG_LEVEL(level)
|
||||
|
||||
/**
|
||||
* Create a logger that will write to file indicated by the <tt>fname</tt>.
|
||||
* After creation you are free to use standard EPICSv3 functions from
|
||||
|
||||
@@ -14,6 +14,10 @@ PROD_HOST += testRemoteClientImpl
|
||||
testRemoteClientImpl_SRCS += testRemoteClientImpl.cpp
|
||||
testRemoteClientImpl_LIBS += pvData pvAccess Com
|
||||
|
||||
PROD_HOST += testChannelConnect
|
||||
testChannelConnect_SRCS += testChannelConnect.cpp
|
||||
testChannelConnect_LIBS += pvData pvAccess Com
|
||||
|
||||
#PROD_HOST += testBeaconEmitter
|
||||
testBeaconEmitter_SRCS += testBeaconEmitter.cpp
|
||||
testBeaconEmitter_LIBS += pvData pvAccess Com
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <stdio.h>
|
||||
#include <epicsStdlib.h>
|
||||
#include <epicsGetopt.h>
|
||||
#include <errlog.h>
|
||||
#include <logger.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@@ -559,8 +559,8 @@ int main (int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
// typedef enum {errlogInfo, errlogMinor, errlogMajor, errlogFatal} errlogSevEnum;
|
||||
errlogSetSevToLog(errlogMajor);
|
||||
// typedef enum {logLevelInfo, logLevelDebug, logLevelError, errlogFatal} errlogSevEnum;
|
||||
SET_LOG_LEVEL(logLevelError);
|
||||
|
||||
|
||||
ClientFactory::start();
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <stdio.h>
|
||||
#include <epicsStdlib.h>
|
||||
#include <epicsGetopt.h>
|
||||
#include <errlog.h>
|
||||
#include <logger.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@@ -605,8 +605,8 @@ int main (int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
// typedef enum {errlogInfo, errlogMinor, errlogMajor, errlogFatal} errlogSevEnum;
|
||||
errlogSetSevToLog(errlogMajor);
|
||||
// typedef enum {logLevelInfo, logLevelDebug, logLevelError, errlogFatal} errlogSevEnum;
|
||||
SET_LOG_LEVEL(logLevelError);
|
||||
|
||||
|
||||
ClientFactory::start();
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <pv/pvType.h>
|
||||
|
||||
#include <osiSock.h>
|
||||
#include <errlog.h>
|
||||
#include <logger.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
@@ -86,16 +86,16 @@ public:
|
||||
virtual ~DummyTransportClient() {
|
||||
}
|
||||
virtual void transportUnresponsive() {
|
||||
errlogSevPrintf(errlogInfo, "unresponsive");
|
||||
LOG(logLevelInfo, "unresponsive");
|
||||
}
|
||||
virtual void transportResponsive(Transport::shared_pointer const & transport) {
|
||||
errlogSevPrintf(errlogInfo, "responsive");
|
||||
LOG(logLevelInfo, "responsive");
|
||||
}
|
||||
virtual void transportChanged() {
|
||||
errlogSevPrintf(errlogInfo, "changed");
|
||||
LOG(logLevelInfo, "changed");
|
||||
}
|
||||
virtual void transportClosed() {
|
||||
errlogSevPrintf(errlogInfo, "closed");
|
||||
LOG(logLevelInfo, "closed");
|
||||
}
|
||||
virtual void acquire() {};
|
||||
virtual void release() {};
|
||||
|
||||
95
testApp/remote/testChannelConnect.cpp
Normal file
95
testApp/remote/testChannelConnect.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
|
||||
/* testChannelConnect.cpp */
|
||||
/* Author: Matej Sekoranja Date: 2011.8.24 */
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <pv/CDRMonitor.h>
|
||||
#include <epicsExit.h>
|
||||
#include <pv/clientContextImpl.h>
|
||||
#include <pv/clientFactory.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
|
||||
#define N_CHANNELS 10000
|
||||
|
||||
static Event g_event;
|
||||
|
||||
class ChannelRequesterImpl : public ChannelRequester
|
||||
{
|
||||
public:
|
||||
ChannelRequesterImpl() : count(0) {}
|
||||
private:
|
||||
int count;
|
||||
|
||||
virtual String getRequesterName()
|
||||
{
|
||||
return "ChannelRequesterImpl";
|
||||
};
|
||||
|
||||
virtual void message(String message,MessageType messageType)
|
||||
{
|
||||
std::cout << "[" << getRequesterName() << "] message(" << message << ", " << messageTypeName[messageType] << ")" << std::endl;
|
||||
}
|
||||
|
||||
virtual void channelCreated(const epics::pvData::Status& status, Channel::shared_pointer const & channel)
|
||||
{
|
||||
if (!status.isSuccess())
|
||||
{
|
||||
std::cout << "channelCreated(" << status.toString() << ", "
|
||||
<< (channel ? channel->getChannelName() : "(0)") << ")" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// always called from the same thread
|
||||
virtual void channelStateChange(Channel::shared_pointer const & c, Channel::ConnectionState connectionState)
|
||||
{
|
||||
if (connectionState == Channel::CONNECTED)
|
||||
{
|
||||
cout << c->getChannelName() << " CONNECTED: " << (count+1) << endl;
|
||||
if (++count == N_CHANNELS)
|
||||
g_event.signal();
|
||||
}
|
||||
else if (connectionState == Channel::DISCONNECTED)
|
||||
{
|
||||
--count;
|
||||
cout << c->getChannelName() << " DISCONNECTED: " << count << endl;
|
||||
}
|
||||
else
|
||||
cout << c->getChannelName() << " " << Channel::ConnectionStateNames[connectionState] << endl;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
{
|
||||
ClientFactory::start();
|
||||
ChannelProvider::shared_pointer provider = getChannelAccess()->getProvider("pvAccess");
|
||||
ChannelRequester::shared_pointer channelRequester(new ChannelRequesterImpl());
|
||||
|
||||
Channel::shared_pointer channels[N_CHANNELS];
|
||||
char buf[16];
|
||||
for (int i = 0; i < N_CHANNELS; i++)
|
||||
{
|
||||
sprintf(buf, "record%d", (i+1));
|
||||
channels[i] = provider->createChannel(buf, channelRequester);
|
||||
}
|
||||
|
||||
g_event.wait();
|
||||
|
||||
cout << "connected to all" << endl;
|
||||
|
||||
ClientFactory::stop();
|
||||
}
|
||||
|
||||
epicsThreadSleep ( 1.0 );
|
||||
std::cout << "-----------------------------------------------------------------------" << std::endl;
|
||||
epicsExitCallAtExits();
|
||||
CDRMonitor::get().show(stdout);
|
||||
return(0);
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include <pv/logger.h>
|
||||
|
||||
#include <errlog.h>
|
||||
#include <logger.h>
|
||||
#include <epicsExit.h>
|
||||
|
||||
#include <iostream>
|
||||
@@ -19,10 +19,10 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
createFileLogger("loggerTest.log");
|
||||
|
||||
errlogSetSevToLog(errlogMinor);
|
||||
errlogSevPrintf( errlogInfo, "This will not appear");
|
||||
errlogSevPrintf( errlogMajor, "This is a test %d", 42);
|
||||
errlogSevPrintf( errlogFatal, "This is another test %f", 3.14);
|
||||
SET_LOG_LEVEL(logLevelDebug);
|
||||
LOG( logLevelInfo, "This will not appear");
|
||||
LOG( logLevelError, "This is a test %d", 42);
|
||||
LOG( logLevelFatal, "This is another test %f", 3.14);
|
||||
|
||||
epicsExit(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user