Files
pvAccess/pvAccessApp/remote/blockingUDPConnector.cpp
miha_vitorovic bd1a4e2634 Makefile: included all the new sources
blockingClientTCPTransport.cpp: implementation

blockingTCP.h:
* class BlockingTCPTransport:
  - added Context to ctor
  - added 'virtual' declaration to overrides
  - 'priority' is now 'int16'
* added class 'BlockingClientTCPTransport'

blockingTCPConnector.cpp: implementation

blockingTCPTransport.cpp:
* removed 'transportRegistry' added 'context'

blockingUDP.h:
* added missing override 'getIntrospectionRegistry'
* 'BlockingUDPConnector::_priority' is now 'int16' instead of 'short'

blockingUDPConnector.cpp:
* 'connect' parameter priority is now 'int16' instead of 'short'
* fixed and added error logging

remote.h:
* added 'TransportRegistry' forward declaration
* added 'Transport::getIntrospectionRegistry' prototype
* changed 'Connector::connect' prototype parameter 'priority': 'short'->'int16'
* added 'Context' interface
* added 'ReferenceCountingTransport' interface

transportRegistry.h:
* added 'Transport' forward declaration

testRemoteClientImpl.cpp:
* added '#include <transportRegistry.h>' to fix compile error
* lots of auto-format changes

transportRegistryTest.cpp:
*
2011-01-04 11:58:00 +01:00

78 lines
2.5 KiB
C++

/*
* blockingUDPConnector.cpp
*
* Created on: Dec 27, 2010
* Author: Miha Vitorovic
*/
/* pvAccess */
#include "blockingUDP.h"
#include "remote.h"
/* pvData */
#include <epicsException.h>
/* EPICSv3 */
#include <errlog.h>
#include <osiSock.h>
/* standard */
#include <sys/types.h>
#include <sys/socket.h>
namespace epics {
namespace pvAccess {
Transport* BlockingUDPConnector::connect(TransportClient* client,
ResponseHandler* responseHandler, osiSockAddr* bindAddress,
short transportRevision, int16 priority) {
errlogSevPrintf(errlogInfo, "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);
}
/* from MSDN:
* Note: If the setsockopt function is called before the bind
* function, TCP/IP options will not be checked by using TCP/IP
* until the bind occurs. In this case, the setsockopt function
* call will always succeed, but the bind function call can fail
* because of an early setsockopt call failing.
*/
int retval = ::bind(socket, (sockaddr*)&(bindAddress->sa),
sizeof(sockaddr));
if(retval<0) {
errlogSevPrintf(errlogMajor, "Error binding socket: %s",
strerror(errno));
THROW_BASE_EXCEPTION(strerror(errno));
}
// set the socket options
int optval = _reuseSocket ? 1 : 0;
retval = ::setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, &optval,
sizeof(optval));
if(retval<0) errlogSevPrintf(errlogMajor,
"Error setting SO_REUSEADDR: %s", strerror(errno));
optval = _broadcast ? 1 : 0;
retval = ::setsockopt(socket, SOL_SOCKET, SO_BROADCAST, &optval,
sizeof(optval));
if(retval<0) errlogSevPrintf(errlogMajor,
"Error setting SO_BROADCAST: %s", strerror(errno));
// sockets are blocking by default
return new BlockingUDPTransport(responseHandler, socket,
bindAddress, _sendAddresses, transportRevision);
}
}
}