BlockingUDPConnector cleanup

remove unused options and arguments.  Avoid alloc.
This commit is contained in:
Michael Davidsaver
2018-11-02 09:58:50 -07:00
parent 5e79342219
commit d48971dbb9
3 changed files with 21 additions and 48 deletions

View File

@@ -35,10 +35,10 @@ struct closer {
namespace epics {
namespace pvAccess {
BlockingUDPTransport::shared_pointer BlockingUDPConnector::connect(std::tr1::shared_ptr<ClientChannelImpl> const & /*client*/,
ResponseHandler::shared_pointer const & responseHandler, osiSockAddr& bindAddress,
int8 transportRevision, int16 /*priority*/) {
BlockingUDPTransport::shared_pointer BlockingUDPConnector::connect(ResponseHandler::shared_pointer const & responseHandler,
osiSockAddr& bindAddress,
int8 transportRevision)
{
SOCKET socket = epicsSocketCreate(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(socket==INVALID_SOCKET) {
char errStr[64];
@@ -47,7 +47,7 @@ BlockingUDPTransport::shared_pointer BlockingUDPConnector::connect(std::tr1::sha
return BlockingUDPTransport::shared_pointer();
}
int optval = _broadcast ? 1 : 0;
int optval = 1;
int retval = ::setsockopt(socket, SOL_SOCKET, SO_BROADCAST, (char *)&optval, sizeof(optval));
if(retval<0)
{
@@ -69,8 +69,7 @@ BlockingUDPTransport::shared_pointer BlockingUDPConnector::connect(std::tr1::sha
// set SO_REUSEADDR or SO_REUSEPORT, OS dependant
if (_reuseSocket)
epicsSocketEnableAddressUseForDatagramFanout(socket);
epicsSocketEnableAddressUseForDatagramFanout(socket);
retval = ::bind(socket, (sockaddr*)&(bindAddress.sa), sizeof(sockaddr));
if(retval<0) {

View File

@@ -575,8 +575,7 @@ void initializeUDPTransports(bool serverFlag,
const std::string& addressList,
const std::string& ignoreAddressList)
{
std::tr1::shared_ptr<ClientChannelImpl> nullTransportClient;
epics::auto_ptr<BlockingUDPConnector> connector(new BlockingUDPConnector(serverFlag, true, true));
BlockingUDPConnector connector(serverFlag);
//
// Create UDP transport for sending (to all network interfaces)
@@ -588,10 +587,7 @@ void initializeUDPTransports(bool serverFlag,
anyAddress.ia.sin_port = htons(0);
anyAddress.ia.sin_addr.s_addr = htonl(INADDR_ANY);
sendTransport = connector->connect(
nullTransportClient, responseHandler,
anyAddress, PVA_PROTOCOL_REVISION,
PVA_DEFAULT_PRIORITY);
sendTransport = connector.connect(responseHandler, anyAddress, PVA_PROTOCOL_REVISION);
if (!sendTransport)
{
THROW_BASE_EXCEPTION("Failed to initialize UDP transport.");
@@ -727,10 +723,8 @@ void initializeUDPTransports(bool serverFlag,
listenLocalAddress.ia.sin_port = htons(listenPort);
listenLocalAddress.ia.sin_addr.s_addr = node.addr.ia.sin_addr.s_addr;
BlockingUDPTransport::shared_pointer transport = connector->connect(
nullTransportClient, responseHandler,
listenLocalAddress, PVA_PROTOCOL_REVISION,
PVA_DEFAULT_PRIORITY);
BlockingUDPTransport::shared_pointer transport = connector.connect(
responseHandler, listenLocalAddress, PVA_PROTOCOL_REVISION);
if (!transport)
continue;
listenLocalAddress = transport->getRemoteAddress();
@@ -764,10 +758,7 @@ void initializeUDPTransports(bool serverFlag,
bcastAddress.ia.sin_port = htons(listenPort);
bcastAddress.ia.sin_addr.s_addr = node.bcast.ia.sin_addr.s_addr;
transport2 = connector->connect(
nullTransportClient, responseHandler,
bcastAddress, PVA_PROTOCOL_REVISION,
PVA_DEFAULT_PRIORITY);
transport2 = connector.connect(responseHandler, bcastAddress, PVA_PROTOCOL_REVISION);
if (transport2)
{
/* The other wrinkle is that nothing should be sent from this second
@@ -820,15 +811,14 @@ void initializeUDPTransports(bool serverFlag,
try
{
// NOTE: multicast receiver socket must be "bound" to INADDR_ANY or multicast address
localMulticastTransport = connector->connect(
nullTransportClient, responseHandler,
localMulticastTransport = connector.connect(
responseHandler,
#if !defined(_WIN32)
group,
#else
anyAddress,
#endif
PVA_PROTOCOL_REVISION,
PVA_DEFAULT_PRIORITY);
PVA_PROTOCOL_REVISION);
if (!localMulticastTransport)
throw std::runtime_error("Failed to bind UDP socket.");

View File

@@ -400,26 +400,19 @@ private:
};
class BlockingUDPConnector :
private epics::pvData::NoDefaultMethods {
class BlockingUDPConnector{
public:
POINTER_DEFINITIONS(BlockingUDPConnector);
BlockingUDPConnector(
bool serverFlag,
bool reuseSocket,
bool broadcast) :
_serverFlag(serverFlag),
_reuseSocket(reuseSocket),
_broadcast(broadcast) {
}
BlockingUDPConnector(bool serverFlag) :_serverFlag(serverFlag) {}
/**
* NOTE: transport client is ignored for broadcast (UDP).
*/
BlockingUDPTransport::shared_pointer connect(std::tr1::shared_ptr<ClientChannelImpl> const & client,
ResponseHandler::shared_pointer const & responseHandler, osiSockAddr& bindAddress,
epics::pvData::int8 transportRevision, epics::pvData::int16 priority);
BlockingUDPTransport::shared_pointer connect(
ResponseHandler::shared_pointer const & responseHandler,
osiSockAddr& bindAddress,
epics::pvData::int8 transportRevision);
private:
@@ -428,16 +421,7 @@ private:
*/
bool _serverFlag;
/**
* Reuse socket flag.
*/
bool _reuseSocket;
/**
* Broadcast flag.
*/
bool _broadcast;
EPICS_NOT_COPYABLE(BlockingUDPConnector)
};
typedef std::vector<BlockingUDPTransport::shared_pointer> BlockingUDPTransportVector;