diff --git a/pvAccessApp/remote/blockingTCPTransport.cpp b/pvAccessApp/remote/blockingTCPTransport.cpp index a4778ec..8d3dd00 100644 --- a/pvAccessApp/remote/blockingTCPTransport.cpp +++ b/pvAccessApp/remote/blockingTCPTransport.cpp @@ -140,12 +140,14 @@ namespace epics { delete _sendQueueMutex; delete _verifiedMutex; delete _monitorMutex; + + delete _responseHandler; } void BlockingTCPTransport::start() { _sendThreadRunning = true; String threadName = "TCP-receive "+inetAddressToString( - _socketAddress); + * _socketAddress); errlogSevPrintf(errlogInfo, "Starting thread: %s", threadName.c_str()); @@ -155,7 +157,7 @@ namespace epics { epicsThreadStackMedium), BlockingTCPTransport::rcvThreadRunner, this); - threadName = "TCP-send "+inetAddressToString(_socketAddress); + threadName = "TCP-send "+inetAddressToString(*_socketAddress); errlogSevPrintf(errlogInfo, "Starting thread: %s", threadName.c_str()); @@ -506,7 +508,7 @@ namespace epics { errlogSevPrintf( errlogMinor, "Invalid header received from client %s, disconnecting...", - inetAddressToString(_socketAddress).c_str()); + inetAddressToString(*_socketAddress).c_str()); close(true); return; } @@ -552,7 +554,7 @@ namespace epics { errlogMajor, "Unknown packet type %d, received from client %s, disconnecting...", type, - inetAddressToString(_socketAddress).c_str()); + inetAddressToString(*_socketAddress).c_str()); close(true); return; } @@ -690,7 +692,7 @@ namespace epics { //errlogSevPrintf(errlogInfo, // "Sending %d of total %d bytes in the packet to %s.", // bytesToSend, limit, - // inetAddressToString(_socketAddress).c_str()); + // inetAddressToString(*_socketAddress).c_str()); while(buffer->getRemaining()>0) { ssize_t bytesSent = ::send(_channel, @@ -716,7 +718,7 @@ namespace epics { //errlogSevPrintf(errlogInfo, // "Send buffer full for %s, waiting...", - // inetAddressToString(_socketAddress)); + // inetAddressToString(*_socketAddress)); return false; } @@ -838,7 +840,7 @@ namespace epics { freeSendBuffers(); errlogSevPrintf(errlogInfo, "Connection to %s closed.", - inetAddressToString(_socketAddress).c_str()); + inetAddressToString(*_socketAddress).c_str()); if(_channel!=INVALID_SOCKET) { epicsSocketDestroy(_channel); diff --git a/pvAccessApp/remote/blockingUDPConnector.cpp b/pvAccessApp/remote/blockingUDPConnector.cpp index 6f66853..629df10 100644 --- a/pvAccessApp/remote/blockingUDPConnector.cpp +++ b/pvAccessApp/remote/blockingUDPConnector.cpp @@ -25,7 +25,7 @@ namespace epics { short transportRevision, int16 priority) { errlogSevPrintf(errlogInfo, "Creating datagram socket to: %s", - inetAddressToString(&bindAddress).c_str()); + inetAddressToString(bindAddress).c_str()); SOCKET socket = epicsSocketCreate(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if(socket==INVALID_SOCKET) { diff --git a/pvAccessApp/remote/blockingUDPTransport.cpp b/pvAccessApp/remote/blockingUDPTransport.cpp index 08a00db..ac47644 100644 --- a/pvAccessApp/remote/blockingUDPTransport.cpp +++ b/pvAccessApp/remote/blockingUDPTransport.cpp @@ -57,10 +57,11 @@ namespace epics { delete _receiveBuffer; delete _sendBuffer; + delete _responseHandler; } void BlockingUDPTransport::start() { - String threadName = "UDP-receive "+inetAddressToString(&_bindAddress); + String threadName = "UDP-receive "+inetAddressToString(_bindAddress); errlogSevPrintf(errlogInfo, "Starting thread: %s",threadName.c_str()); @@ -82,7 +83,7 @@ namespace epics { errlogSevPrintf(errlogInfo, "UDP socket %s closed.", - inetAddressToString(&_bindAddress).c_str()); + inetAddressToString(_bindAddress).c_str()); epicsSocketDestroy(_channel); } @@ -160,7 +161,7 @@ namespace epics { if(_ignoredAddresses!=0) { for(size_t i = 0; i <_ignoredAddresses->size(); i++) - if(_ignoredAddresses->at(i)->ia.sin_addr.s_addr + if(_ignoredAddresses->at(i).ia.sin_addr.s_addr ==fromAddress.ia.sin_addr.s_addr) { ignore = true; break; @@ -264,7 +265,7 @@ namespace epics { for(size_t i = 0; i<_sendAddresses->size(); i++) { buffer->flip(); int retval = sendto(_channel, buffer->getArray(), - buffer->getLimit(), 0, &(_sendAddresses->at(i)->sa), + buffer->getLimit(), 0, &(_sendAddresses->at(i).sa), sizeof(sockaddr)); { if(retval<0) errlogSevPrintf(errlogMajor, diff --git a/pvAccessApp/remote/remote.h b/pvAccessApp/remote/remote.h index a341de6..2e6a7f3 100644 --- a/pvAccessApp/remote/remote.h +++ b/pvAccessApp/remote/remote.h @@ -289,6 +289,8 @@ namespace epics { */ class ResponseHandler { public: + virtual ~ResponseHandler() {} + /** * Handle response. * @param[in] responseFrom remote address of the responder, 0 if unknown. @@ -504,6 +506,7 @@ namespace epics { */ class ResponseRequest { public: + virtual ~ResponseRequest() {} /** * Get I/O ID. @@ -540,6 +543,8 @@ namespace epics { */ class DataResponse : public ResponseRequest { public: + virtual ~DataResponse() {} + /** * Notification response. * @param transport @@ -559,6 +564,8 @@ namespace epics { */ class SubscriptionRequest /*: public ResponseRequest*/ { public: + virtual ~SubscriptionRequest() {} + /** * Update (e.g. after some time of unresponsiveness) - report current value. */ diff --git a/pvAccessApp/utils/inetAddressUtil.cpp b/pvAccessApp/utils/inetAddressUtil.cpp index 6ee7ab7..17f43b2 100644 --- a/pvAccessApp/utils/inetAddressUtil.cpp +++ b/pvAccessApp/utils/inetAddressUtil.cpp @@ -66,10 +66,10 @@ namespace epics { namespace pvAccess { void addDefaultBroadcastAddress(InetAddrVector* v, in_port_t p) { - osiSockAddr* pNewNode = new osiSockAddr; - pNewNode->ia.sin_family = AF_INET; - pNewNode->ia.sin_addr.s_addr = htonl(INADDR_BROADCAST); - pNewNode->ia.sin_port = htons(p); + osiSockAddr pNewNode; + pNewNode.ia.sin_family = AF_INET; + pNewNode.ia.sin_addr.s_addr = htonl(INADDR_BROADCAST); + pNewNode.ia.sin_port = htons(p); v->push_back(pNewNode); } @@ -84,7 +84,7 @@ namespace epics { struct ifreq* pIfreqList; struct ifreq* pifreq; struct ifreq ifrBuff; - osiSockAddr* pNewNode; + osiSockAddr pNewNode; InetAddrVector* retVector = new InetAddrVector(); @@ -157,16 +157,6 @@ namespace epics { */ if(ifrBuff.ifr_flags&IFF_LOOPBACK) continue; - pNewNode = new osiSockAddr; - if(pNewNode==NULL) { - errlogSevPrintf(errlogMajor, - "getBroadcastAddresses(): no memory available for configuration"); - delete[] pIfreqList; - if(retVector->size()==0) addDefaultBroadcastAddress( - retVector, defaultPort); - return retVector; - } - /* * If this is an interface that supports * broadcast fetch the broadcast address. @@ -186,10 +176,9 @@ namespace epics { errlogMinor, "getBroadcastAddresses(): net intf \"%s\": bcast addr fetch fail", pifreq->ifr_name); - delete pNewNode; continue; } - pNewNode->sa = ifrBuff.ifr_broadaddr; + pNewNode.sa = ifrBuff.ifr_broadaddr; } #ifdef IFF_POINTOPOINT else if(ifrBuff.ifr_flags&IFF_POINTOPOINT) { @@ -201,10 +190,9 @@ namespace epics { errlogMinor, "getBroadcastAddresses(): net intf \"%s\": pt to pt addr fetch fail", pifreq->ifr_name); - delete pNewNode; continue; } - pNewNode->sa = ifrBuff.ifr_dstaddr; + pNewNode.sa = ifrBuff.ifr_dstaddr; } #endif else { @@ -212,10 +200,9 @@ namespace epics { errlogMinor, "getBroadcastAddresses(): net intf \"%s\": not point to point or bcast?", pifreq->ifr_name); - delete pNewNode; continue; } - pNewNode->ia.sin_port = htons(defaultPort); + pNewNode.ia.sin_port = htons(defaultPort); retVector->push_back(pNewNode); } @@ -296,15 +283,15 @@ namespace epics { size_t subEnd; while((subEnd = list.find(' ', subStart))!=String::npos) { String address = list.substr(subStart, (subEnd-subStart)); - osiSockAddr* addr = new osiSockAddr; - aToIPAddr(address.c_str(), defaultPort, &addr->ia); + osiSockAddr addr; + aToIPAddr(address.c_str(), defaultPort, &addr.ia); iav->push_back(addr); subStart = list.find_first_not_of(" \t\r\n\v", subEnd); } if(subStart!=String::npos&&list.length()>0) { - osiSockAddr* addr = new osiSockAddr; - aToIPAddr(list.substr(subStart).c_str(), defaultPort, &addr->ia); + osiSockAddr addr; + aToIPAddr(list.substr(subStart).c_str(), defaultPort, &addr.ia); iav->push_back(addr); } @@ -315,18 +302,18 @@ namespace epics { return iav; } - const String inetAddressToString(const osiSockAddr *addr, + const String inetAddressToString(const osiSockAddr &addr, bool displayPort, bool displayHex) { stringstream saddr; - int ipa = ntohl(addr->ia.sin_addr.s_addr); + int ipa = ntohl(addr.ia.sin_addr.s_addr); saddr<<((int)(ipa>>24)&0xFF)<<'.'; saddr<<((int)(ipa>>16)&0xFF)<<'.'; saddr<<((int)(ipa>>8)&0xFF)<<'.'; saddr<<((int)ipa&0xFF); - if(displayPort) saddr<<":"<ia.sin_port); - if(displayHex) saddr<<" ("<ia.sin_addr.s_addr) + if(displayPort) saddr<<":"< InetAddrVector; + typedef std::vector InetAddrVector; /** * returns a vector containing all the IPv4 broadcast addresses @@ -72,7 +72,7 @@ namespace epics { InetAddrVector* getSocketAddressList(epics::pvData::String list, int defaultPort, const InetAddrVector* appendList = NULL); - const epics::pvData::String inetAddressToString(const osiSockAddr *addr, + const epics::pvData::String inetAddressToString(const osiSockAddr &addr, bool displayPort = true, bool displayHex = false); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ diff --git a/testApp/remote/testBlockingUDPClnt.cpp b/testApp/remote/testBlockingUDPClnt.cpp index d34ae35..c74b6ad 100644 --- a/testApp/remote/testBlockingUDPClnt.cpp +++ b/testApp/remote/testBlockingUDPClnt.cpp @@ -57,6 +57,8 @@ public: DummyResponseHandler(Context* ctx) { } + virtual ~DummyResponseHandler() {} + virtual void handleResponse(osiSockAddr* responseFrom, Transport* transport, int8 version, int8 command, int payloadSize, ByteBuffer* payloadBuffer) { diff --git a/testApp/remote/testBlockingUDPSrv.cpp b/testApp/remote/testBlockingUDPSrv.cpp index a8c3aa4..7bbed6a 100644 --- a/testApp/remote/testBlockingUDPSrv.cpp +++ b/testApp/remote/testBlockingUDPSrv.cpp @@ -49,6 +49,8 @@ public: DummyResponseHandler(Context* context) : packets(0) { } + + virtual ~DummyResponseHandler() {} int getPackets() { return packets; diff --git a/testApp/remote/testRemoteClientImpl.cpp b/testApp/remote/testRemoteClientImpl.cpp index 2e00223..272fb11 100644 --- a/testApp/remote/testRemoteClientImpl.cpp +++ b/testApp/remote/testRemoteClientImpl.cpp @@ -655,6 +655,7 @@ class ChannelPutImpl : public BaseRequestImpl, public ChannelPut PVDATA_REFCOUNT_MONITOR_DEFINE(channelGetField); +// NOTE: this instance is not returned as Request, so it must self-destruct class ChannelGetFieldRequestImpl : public DataResponse, public TransportSender { private: @@ -775,6 +776,8 @@ class ChannelGetFieldRequestImpl : public DataResponse, public TransportSender // always cancel request // cancel(); // } + + cancel(); } @@ -1251,7 +1254,19 @@ class ClientResponseHandler : public ResponseHandler, private epics::pvData::NoD public: - ~ClientResponseHandler() { + virtual ~ClientResponseHandler() { + delete m_handlerTable[ 0]; + delete m_handlerTable[ 1]; + delete m_handlerTable[ 2]; + delete m_handlerTable[ 3]; + delete m_handlerTable[ 4]; + delete m_handlerTable[ 5]; + delete m_handlerTable[ 6]; + delete m_handlerTable[ 7]; + delete m_handlerTable[ 8]; + delete m_handlerTable[ 9]; + delete m_handlerTable[18]; + delete[] m_handlerTable; } @@ -1315,27 +1330,6 @@ class ClientResponseHandler : public ResponseHandler, private epics::pvData::NoD } }; - class TCI : public TransportSendControl { - public: - virtual void flushSerializeBuffer() { - } - - virtual void ensureBuffer(int size) { - } - - virtual void startMessage(int8 command, int ensureCapacity){} - virtual void endMessage() {} - - virtual void flush(bool lastMessageCompleted) {} - - virtual void setRecipient(const osiSockAddr& sendTo) {} - }; - - - - - - @@ -1534,7 +1528,7 @@ class TestChannelImpl : public ChannelImpl { } else { - return inetAddressToString(m_transport->getRemoteAddress()); + return inetAddressToString(*m_transport->getRemoteAddress()); } } @@ -1840,7 +1834,7 @@ class TestChannelImpl : public ChannelImpl { if (sockAddrAreIdentical(transport->getRemoteAddress(), serverAddress)) { m_requester->message("More than one channel with name '" + m_name + - "' detected, additional response from: " + inetAddressToString(serverAddress), warningMessage); + "' detected, additional response from: " + inetAddressToString(*serverAddress), warningMessage); return; } } @@ -2184,6 +2178,14 @@ class TestChannelImpl : public ChannelImpl { } virtual Configuration* getConfiguration() { +/* +TODO + final ConfigurationProvider configurationProvider = ConfigurationFactory.getProvider(); + Configuration config = configurationProvider.getConfiguration("pvAccess-client"); + if (config == null) + config = configurationProvider.getConfiguration("system"); + return config; +*/ return m_configuration; } @@ -2289,15 +2291,12 @@ class TestChannelImpl : public ChannelImpl { ~TestClientContextImpl() {}; void loadConfiguration() { - // TODO - /* - m_addressList = config->getPropertyAsString("EPICS4_CA_ADDR_LIST", m_addressList); - m_autoAddressList = config->getPropertyAsBoolean("EPICS4_CA_AUTO_ADDR_LIST", m_autoAddressList); - m_connectionTimeout = config->getPropertyAsFloat("EPICS4_CA_CONN_TMO", m_connectionTimeout); - m_beaconPeriod = config->getPropertyAsFloat("EPICS4_CA_BEACON_PERIOD", m_beaconPeriod); - m_broadcastPort = config->getPropertyAsInteger("EPICS4_CA_BROADCAST_PORT", m_broadcastPort); - m_receiveBufferSize = config->getPropertyAsInteger("EPICS4_CA_MAX_ARRAY_BYTES", m_receiveBufferSize); - */ + m_addressList = m_configuration->getPropertyAsString("EPICS4_CA_ADDR_LIST", m_addressList); + m_autoAddressList = m_configuration->getPropertyAsBoolean("EPICS4_CA_AUTO_ADDR_LIST", m_autoAddressList); + m_connectionTimeout = m_configuration->getPropertyAsFloat("EPICS4_CA_CONN_TMO", m_connectionTimeout); + m_beaconPeriod = m_configuration->getPropertyAsFloat("EPICS4_CA_BEACON_PERIOD", m_beaconPeriod); + m_broadcastPort = m_configuration->getPropertyAsInteger("EPICS4_CA_BROADCAST_PORT", m_broadcastPort); + m_receiveBufferSize = m_configuration->getPropertyAsInteger("EPICS4_CA_MAX_ARRAY_BYTES", m_receiveBufferSize); } void internalInitialize() { @@ -2322,6 +2321,7 @@ class TestChannelImpl : public ChannelImpl { // quary broadcast addresses of all IFs SOCKET socket = epicsSocketCreate(AF_INET, SOCK_DGRAM, 0); + if (socket == INVALID_SOCKET) return false; auto_ptr broadcastAddresses(getBroadcastAddresses(socket, m_broadcastPort)); epicsSocketDestroy (socket); @@ -2346,7 +2346,7 @@ class TestChannelImpl : public ChannelImpl { listenLocalAddress.ia.sin_port = htons(m_broadcastPort); listenLocalAddress.ia.sin_addr.s_addr = htonl(INADDR_ANY); - BlockingUDPConnector* broadcastConnector = new BlockingUDPConnector(true, true); + auto_ptr broadcastConnector(new BlockingUDPConnector(true, true)); m_broadcastTransport = (BlockingUDPTransport*)broadcastConnector->connect( 0, new ClientResponseHandler(this), listenLocalAddress, CA_MINOR_PROTOCOL_REVISION, @@ -2361,7 +2361,7 @@ class TestChannelImpl : public ChannelImpl { undefinedAddress.ia.sin_port = htons(0); undefinedAddress.ia.sin_addr.s_addr = htonl(INADDR_ANY); - BlockingUDPConnector* searchConnector = new BlockingUDPConnector(false, true); + auto_ptr searchConnector(new BlockingUDPConnector(false, true)); m_searchTransport = (BlockingUDPTransport*)searchConnector->connect( 0, new ClientResponseHandler(this), undefinedAddress, CA_MINOR_PROTOCOL_REVISION, @@ -3072,11 +3072,11 @@ int main(int argc,char *argv[]) epicsThreadSleep ( 1.0 ); channel->printInfo(); -/* + GetFieldRequesterImpl getFieldRequesterImpl; channel->getField(&getFieldRequesterImpl, ""); epicsThreadSleep ( 1.0 ); - +/* ChannelProcessRequesterImpl channelProcessRequester; ChannelProcess* channelProcess = channel->createChannelProcess(&channelProcessRequester, 0); epicsThreadSleep ( 1.0 ); diff --git a/testApp/utils/inetAddressUtilsTest.cpp b/testApp/utils/inetAddressUtilsTest.cpp index bffa82f..eb7c33b 100644 --- a/testApp/utils/inetAddressUtilsTest.cpp +++ b/testApp/utils/inetAddressUtilsTest.cpp @@ -32,25 +32,25 @@ int main(int argc, char *argv[]) { assert(vec->size()==3); - osiSockAddr* addr; + osiSockAddr addr; addr = vec->at(0); - assert(addr->ia.sin_family==AF_INET); - assert(addr->ia.sin_port==htons(555)); - assert(addr->ia.sin_addr.s_addr==htonl(0x7F000001)); + assert(addr.ia.sin_family==AF_INET); + assert(addr.ia.sin_port==htons(555)); + assert(addr.ia.sin_addr.s_addr==htonl(0x7F000001)); assert(inetAddressToString(addr)=="127.0.0.1:555"); cout<<'\t'<at(1); - assert(addr->ia.sin_family==AF_INET); - assert(addr->ia.sin_port==htons(1234)); - assert(addr->ia.sin_addr.s_addr==htonl(0x0A0A0C0B)); + assert(addr.ia.sin_family==AF_INET); + assert(addr.ia.sin_port==htons(1234)); + assert(addr.ia.sin_addr.s_addr==htonl(0x0A0A0C0B)); assert(inetAddressToString(addr)=="10.10.12.11:1234"); cout<<'\t'<at(2); - assert(addr->ia.sin_family==AF_INET); - assert(addr->ia.sin_port==htons(555)); - assert(addr->ia.sin_addr.s_addr==htonl(0xC0A80304)); + assert(addr.ia.sin_family==AF_INET); + assert(addr.ia.sin_port==htons(555)); + assert(addr.ia.sin_addr.s_addr==htonl(0xC0A80304)); assert(inetAddressToString(addr)=="192.168.3.4:555"); cout<<'\t'<size()==4); addr = vec1->at(0); - assert(addr->ia.sin_family==AF_INET); - assert(addr->ia.sin_port==htons(6789)); - assert(addr->ia.sin_addr.s_addr==htonl(0xAC1037A0)); + assert(addr.ia.sin_family==AF_INET); + assert(addr.ia.sin_port==htons(6789)); + assert(addr.ia.sin_addr.s_addr==htonl(0xAC1037A0)); assert(inetAddressToString(addr)=="172.16.55.160:6789"); cout<<'\t'<at(1); - assert(addr->ia.sin_family==AF_INET); - assert(addr->ia.sin_port==htons(555)); - assert(addr->ia.sin_addr.s_addr==htonl(0x7F000001)); + assert(addr.ia.sin_family==AF_INET); + assert(addr.ia.sin_port==htons(555)); + assert(addr.ia.sin_addr.s_addr==htonl(0x7F000001)); assert(inetAddressToString(addr)=="127.0.0.1:555"); cout<<'\t'<at(2); - assert(addr->ia.sin_family==AF_INET); - assert(addr->ia.sin_port==htons(1234)); - assert(addr->ia.sin_addr.s_addr==htonl(0x0A0A0C0B)); + assert(addr.ia.sin_family==AF_INET); + assert(addr.ia.sin_port==htons(1234)); + assert(addr.ia.sin_addr.s_addr==htonl(0x0A0A0C0B)); assert(inetAddressToString(addr)=="10.10.12.11:1234"); cout<<'\t'<at(3); - assert(addr->ia.sin_family==AF_INET); - assert(addr->ia.sin_port==htons(555)); - assert(addr->ia.sin_addr.s_addr==htonl(0xC0A80304)); + assert(addr.ia.sin_family==AF_INET); + assert(addr.ia.sin_port==htons(555)); + assert(addr.ia.sin_addr.s_addr==htonl(0xC0A80304)); assert(inetAddressToString(addr)=="192.168.3.4:555"); cout<<'\t'<at(0)))==(int32)0x7F000001); - assert(ipv4AddressToInt(*(vec->at(1)))==(int32)0x0A0A0C0B); - assert(ipv4AddressToInt(*(vec->at(2)))==(int32)0xC0A80304); + assert(ipv4AddressToInt((vec->at(0)))==(int32)0x7F000001); + assert(ipv4AddressToInt((vec->at(1)))==(int32)0x0A0A0C0B); + assert(ipv4AddressToInt((vec->at(2)))==(int32)0xC0A80304); cout<<"\nPASSED!\n"; delete vec; delete vec1; + osiSockAddr* paddr; cout<<"Testing \"intToIPv4Address\""<ia.sin_family==AF_INET); - assert(inetAddressToString(addr)=="127.0.0.1:0"); - cout<<'\t'<ia.sin_family==AF_INET); + assert(inetAddressToString(*paddr)=="127.0.0.1:0"); + cout<<'\t'<ia.sin_family==AF_INET); - assert(inetAddressToString(addr)=="10.10.12.11:0"); - cout<<'\t'<ia.sin_family==AF_INET); + assert(inetAddressToString(*paddr)=="10.10.12.11:0"); + cout<<'\t'<getArray(), src, 16)==0); cout<<"\nPASSED!\n"; @@ -135,7 +138,6 @@ int main(int argc, char *argv[]) { } delete broadcasts; - delete addr; return 0; }