This commit is contained in:
Matej Sekoranja
2011-09-17 22:02:53 +02:00
20 changed files with 79 additions and 214 deletions

View File

@@ -32,6 +32,14 @@ ifeq ($(EPICS_HOST_ARCH),linux-x86)
USR_LDFLAGS += -lpthread
endif
ifeq ($(EPICS_HOST_ARCH),win32-x86)
USR_SYS_LIBS += ws2_32
endif
ifeq ($(EPICS_HOST_ARCH),win32-x86-debug)
USR_SYS_LIBS += ws2_32
endif
INSTALL_INCLUDE = $(INSTALL_LOCATION)/include/pv
USR_INCLUDES += -I $(INSTALL_LOCATION)/include

View File

@@ -26,7 +26,7 @@ TEMPLATE_TOP=$(EPICS_BASE)/templates/makeBaseApp/top
# EPICS_BASE usually appears last so other apps can override stuff:
PVDATA=/Users/msekoranja/tmp/pvDataCPP
PVDATA=/opt/epics/pvDataCPP
EPICS_BASE=/opt/epics/base
#PVDATA=/home/mrk/hg/pvDataCPP

View File

@@ -207,7 +207,7 @@ namespace epics {
static const int MAX_ENSURE_DATA_BUFFER_SIZE = 1024;
static const double _delay = 0.01;
static const double _delay;
/****** finally initialized at construction time and after start (called by the same thread) ********/
@@ -864,7 +864,7 @@ namespace epics {
* Initialize connection acception.
* @return port where server is listening
*/
int initialize(in_port_t port);
int initialize(unsigned short port);
/**
* Validate connection by sending a validation message request.

View File

@@ -43,7 +43,7 @@ namespace epics {
destroy();
}
int BlockingTCPAcceptor::initialize(in_port_t port) {
int BlockingTCPAcceptor::initialize(unsigned short port) {
// specified bind address
_bindAddress.ia.sin_family = AF_INET;
_bindAddress.ia.sin_port = htons(port);
@@ -85,7 +85,7 @@ namespace epics {
_bindAddress.ia.sin_port = htons(0);
}
else {
::close(_serverSocketChannel);
epicsSocketDestroy(_serverSocketChannel);
break; // exit while loop
}
}
@@ -94,7 +94,7 @@ namespace epics {
// update bind address, if dynamically port selection was used
if(ntohs(_bindAddress.ia.sin_port)==0) {
socklen_t sockLen = sizeof(sockaddr);
osiSocklen_t sockLen = sizeof(sockaddr);
// read the actual socket info
retval = ::getsockname(_serverSocketChannel, &_bindAddress.sa, &sockLen);
if(retval<0) {
@@ -168,14 +168,14 @@ namespace epics {
// enable TCP_NODELAY (disable Nagle's algorithm)
int optval = 1; // true
int retval = ::setsockopt(newClient, IPPROTO_TCP, TCP_NODELAY, &optval, sizeof(int));
int retval = ::setsockopt(newClient, IPPROTO_TCP, TCP_NODELAY, (char *)&optval, sizeof(int));
if(retval<0) {
epicsSocketConvertErrnoToString(strBuffer, sizeof(strBuffer));
LOG(logLevelDebug, "Error setting TCP_NODELAY: %s", strBuffer);
}
// enable TCP_KEEPALIVE
retval = ::setsockopt(newClient, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(int));
retval = ::setsockopt(newClient, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(int));
if(retval<0) {
epicsSocketConvertErrnoToString(strBuffer, sizeof(strBuffer));
LOG(logLevelDebug, "Error setting SO_KEEPALIVE: %s", strBuffer);

View File

@@ -14,7 +14,6 @@
#include <logger.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sstream>
namespace epics {
@@ -120,7 +119,7 @@ namespace epics {
// enable TCP_NODELAY (disable Nagle's algorithm)
int optval = 1; // true
int retval = ::setsockopt(socket, IPPROTO_TCP, TCP_NODELAY,
&optval, sizeof(int));
(char *)&optval, sizeof(int));
if(retval<0) {
char errStr[64];
epicsSocketConvertErrnoToString(errStr, sizeof(errStr));
@@ -129,7 +128,7 @@ namespace epics {
// enable TCP_KEEPALIVE
retval = ::setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE,
&optval, sizeof(int));
(char *)&optval, sizeof(int));
if(retval<0)
{
char errStr[64];

View File

@@ -5,6 +5,7 @@
* Author: Miha Vitorovic
*/
#define __STDC_LIMIT_MACROS 1
#include <pv/blockingTCP.h>
#include <pv/inetAddressUtil.h>
#include <pv/caConstants.h>
@@ -24,10 +25,14 @@
/* standard */
#include <sys/types.h>
#include <sys/socket.h>
#include <algorithm>
#include <sstream>
#ifdef _WIN32
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#endif
using namespace epics::pvData;
using std::max;
@@ -72,6 +77,8 @@ namespace epics {
PVDATA_REFCOUNT_MONITOR_DEFINE(blockingTCPTransport);
const double BlockingTCPTransport::_delay = 0.01;
BlockingTCPTransport::BlockingTCPTransport(Context::shared_pointer const & context,
SOCKET channel, std::auto_ptr<ResponseHandler>& responseHandler,
int receiveBufferSize, int16 priority) :
@@ -111,7 +118,7 @@ namespace epics {
_verified(false),
_markerToSend(0),
_totalBytesSent(0),
_remoteBufferFreeSpace(LONG_LONG_MAX)
_remoteBufferFreeSpace(INT64_MAX)
{
PVDATA_REFCOUNT_MONITOR_CONSTRUCT(blockingTCPTransport);
@@ -126,9 +133,9 @@ namespace epics {
_maxPayloadSize = _sendBuffer->getSize() - 2*CA_MESSAGE_HEADER_SIZE; // one for header, one for flow control
// get send buffer size
socklen_t intLen = sizeof(int);
osiSocklen_t intLen = sizeof(int);
int retval = getsockopt(_channel, SOL_SOCKET, SO_SNDBUF, &_socketSendBufferSize, &intLen);
int retval = getsockopt(_channel, SOL_SOCKET, SO_SNDBUF, (char *)&_socketSendBufferSize, &intLen);
if(retval<0) {
_socketSendBufferSize = MAX_TCP_RECV;
char errStr[64];
@@ -138,7 +145,7 @@ namespace epics {
errStr);
}
socklen_t saSize = sizeof(sockaddr);
osiSocklen_t saSize = sizeof(sockaddr);
retval = getpeername(_channel, &(_socketAddress.sa), &saSize);
if(retval<0) {
char errStr[64];
@@ -150,7 +157,7 @@ namespace epics {
// set receive timeout so that we do not have problems at shutdown (recvfrom would block)
struct timeval timeout;
bzero(&timeout, sizeof(struct timeval));
memset(&timeout, 0, sizeof(struct timeval));
timeout.tv_sec = 1;
timeout.tv_usec = 0;
@@ -274,9 +281,9 @@ namespace epics {
// this DatagramSocket.
int sockBufSize;
socklen_t intLen = sizeof(int);
osiSocklen_t intLen = sizeof(int);
int retval = getsockopt(_channel, SOL_SOCKET, SO_RCVBUF,&sockBufSize, &intLen);
int retval = getsockopt(_channel, SOL_SOCKET, SO_RCVBUF, (char *)&sockBufSize, &intLen);
if(retval<0)
{
char errStr[64];
@@ -497,7 +504,7 @@ namespace epics {
while(_socketBuffer->getPosition()<requiredPosition) {
// read
int pos = _socketBuffer->getPosition();
ssize_t bytesRead = recv(_channel, (void*)(_socketBuffer->getArray()+pos),
ssize_t bytesRead = recv(_channel, (char*)(_socketBuffer->getArray()+pos),
_socketBuffer->getRemaining(), 0);
_socketBuffer->setPosition(pos+bytesRead);

View File

@@ -15,7 +15,6 @@
/* standard */
#include <sys/types.h>
#include <sys/socket.h>
using namespace std;
@@ -38,7 +37,7 @@ namespace epics {
}
int optval = _broadcast ? 1 : 0;
int retval = ::setsockopt(socket, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval));
int retval = ::setsockopt(socket, SOL_SOCKET, SO_BROADCAST, (char *)&optval, sizeof(optval));
if(retval<0)
{
char errStr[64];

View File

@@ -24,7 +24,6 @@
/* standard */
#include <cstdio>
#include <sys/types.h>
#include <sys/socket.h>
using namespace epics::pvData;
using namespace std;
@@ -54,7 +53,7 @@ namespace epics {
// set receive timeout so that we do not have problems at shutdown (recvfrom would block)
struct timeval timeout;
bzero(&timeout, sizeof(struct timeval));
memset(&timeout, 0, sizeof(struct timeval));
timeout.tv_sec = 1;
timeout.tv_usec = 0;
@@ -181,9 +180,9 @@ namespace epics {
// data ready to be read
_receiveBuffer->clear();
socklen_t addrStructSize = sizeof(sockaddr);
osiSocklen_t addrStructSize = sizeof(sockaddr);
int bytesRead = recvfrom(_channel, (void*)_receiveBuffer->getArray(),
int bytesRead = recvfrom(_channel, (char*)_receiveBuffer->getArray(),
_receiveBuffer->getRemaining(), 0, (sockaddr*)&fromAddress,
&addrStructSize);
@@ -217,6 +216,8 @@ namespace epics {
// interrupted or timeout
if (socketError == EINTR ||
socketError == EAGAIN ||
// windows times out with this
socketError == SOCK_ETIMEDOUT ||
socketError == EWOULDBLOCK)
continue;
@@ -331,9 +332,9 @@ namespace epics {
// this DatagramSocket.
int sockBufSize = -1;
socklen_t intLen = sizeof(int);
osiSocklen_t intLen = sizeof(int);
int retval = getsockopt(_channel, SOL_SOCKET, SO_RCVBUF, &sockBufSize, &intLen);
int retval = getsockopt(_channel, SOL_SOCKET, SO_RCVBUF, (char *)&sockBufSize, &intLen);
if(retval<0)
{
char errStr[64];

View File

@@ -497,12 +497,12 @@ ChannelSearchManager::ChannelSearchManager(Context* context):
maxPeriod = min(maxPeriod, MAX_SEARCH_PERIOD_LOWER_LIMIT);
// calculate number of timers to reach maxPeriod (each timer period is doubled)
double powerOfTwo = log(maxPeriod / (double)MIN_RTT) / log(2);
double powerOfTwo = log(maxPeriod / (double)MIN_RTT) / log(2.0);
int32 numberOfTimers = (int32)(powerOfTwo + 1);
numberOfTimers = min(numberOfTimers, MAX_TIMERS);
// calculate beacon anomaly timer index
powerOfTwo = log(BEACON_ANOMALY_SEARCH_PERIOD / (double)MIN_RTT) / log(2);
powerOfTwo = log(BEACON_ANOMALY_SEARCH_PERIOD / (double)MIN_RTT) / log(2.0);
_beaconAnomalyTimerIndex = (int32)(powerOfTwo + 1);
_beaconAnomalyTimerIndex = min(_beaconAnomalyTimerIndex, numberOfTimers - 1);

View File

@@ -3414,7 +3414,7 @@ namespace epics {
m_needSubscriptionUpdate = true;
int count = 0;
ResponseRequest::weak_pointer rrs[m_responseRequests.size()];
std::vector<ResponseRequest::weak_pointer> rrs(m_responseRequests.size());
for (IOIDResponseRequestMap::iterator iter = m_responseRequests.begin();
iter != m_responseRequests.end();
iter++)
@@ -3829,7 +3829,7 @@ TODO
Lock guard(m_cidMapMutex);
int count = 0;
ChannelImpl::weak_pointer channels[m_channelsByCID.size()];
std::vector<ChannelImpl::weak_pointer> channels(m_channelsByCID.size());
for (CIDChannelMap::iterator iter = m_channelsByCID.begin();
iter != m_channelsByCID.end();
iter++)

View File

@@ -32,7 +32,7 @@ BaseChannelRequester::BaseChannelRequester(
}
boolean BaseChannelRequester::startRequest(int32 qos)
bool BaseChannelRequester::startRequest(int32 qos)
{
Lock guard(_mutex);
if (_pendingRequest != NULL_REQUEST)

View File

@@ -2,6 +2,10 @@
* beaconEmitter.cpp
*/
#ifdef _WIN32
#define NOMINMAX
#endif
#include <pv/beaconEmitter.h>
#include <pv/introspectionRegistry.h>

View File

@@ -22,42 +22,6 @@
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
// since we do not have autoconf
#ifdef darwin
#define HAVE_SOCKADDR_SA_LEN
#endif
/*
* In newer BSD systems, the socket address is variable-length, and
* there's an "sa_len" field giving the length of the structure;
* this allows socket addresses to be longer than 2 bytes of family
* and 14 bytes of data.
*
* Some commercial UNIXes use the old BSD scheme, some use the RFC 2553
* variant of the old BSD scheme (with "struct sockaddr_storage" rather
* than "struct sockaddr"), and some use the new BSD scheme.
*
* Some versions of GNU libc use neither scheme, but has an "SA_LEN()"
* macro that determines the size based on the address family. Other
* versions don't have "SA_LEN()" (as it was in drafts of RFC 2553
* but not in the final version).
*
* We assume that a UNIX that doesn't have "getifaddrs()" and doesn't have
* SIOCGLIFCONF, but has SIOCGIFCONF, uses "struct sockaddr" for the
* address in an entry returned by SIOCGIFCONF.
*/
#ifndef SA_LEN
#ifdef HAVE_SOCKADDR_SA_LEN
#define SA_LEN(addr) ((addr).sa_len)
#else /* HAVE_SOCKADDR_SA_LEN */
#define SA_LEN(addr) (sizeof (struct sockaddr))
#endif /* HAVE_SOCKADDR_SA_LEN */
#endif /* SA_LEN */
using namespace std;
using namespace epics::pvData;
@@ -65,7 +29,7 @@ using namespace epics::pvData;
namespace epics {
namespace pvAccess {
void addDefaultBroadcastAddress(InetAddrVector* v, in_port_t p) {
void addDefaultBroadcastAddress(InetAddrVector* v, unsigned short p) {
osiSockAddr pNewNode;
pNewNode.ia.sin_family = AF_INET;
pNewNode.ia.sin_addr.s_addr = htonl(INADDR_BROADCAST);
@@ -73,141 +37,22 @@ namespace epics {
v->push_back(pNewNode);
}
// TODO use osiSockDiscoverBroadcastAddresses() from epics/base/src/libCom/osi/os/default/osdNetIntf.c
InetAddrVector* getBroadcastAddresses(SOCKET sock,
in_port_t defaultPort) {
static const unsigned nelem = 100;
int status;
struct ifconf ifconf;
struct ifreq* pIfreqList;
struct ifreq* pifreq;
struct ifreq ifrBuff;
osiSockAddr pNewNode;
InetAddrVector* retVector = new InetAddrVector();
/*
* use pool so that we avoid using too much stack space
*
* nelem is set to the maximum interfaces
* on one machine here
*/
pIfreqList = new ifreq[nelem];
if(!pIfreqList) {
LOG(logLevelError,
"getBroadcastAddresses(): no memory to complete request");
addDefaultBroadcastAddress(retVector, defaultPort);
return retVector;
InetAddrVector* getBroadcastAddresses(SOCKET sock,
unsigned short defaultPort) {
ELLLIST as;
ellInit(&as);
osiSockAddr serverAddr;
memset(&serverAddr, 0, sizeof(osiSockAddr));
InetAddrVector * v = new InetAddrVector;
osiSockDiscoverBroadcastAddresses(&as, sock, &serverAddr);
for(ELLNODE * n = ellFirst(&as); n != NULL; n = ellNext(n))
{
osiSockAddrNode * sn = (osiSockAddrNode *)n;
sn->addr.ia.sin_port = htons(defaultPort);
v->push_back(sn->addr);
}
// get number of interfaces
ifconf.ifc_len = nelem*sizeof(ifreq);
ifconf.ifc_req = pIfreqList;
memset(ifconf.ifc_req, 0, ifconf.ifc_len);
status = ioctl(sock, SIOCGIFCONF, &ifconf);
if(status<0||ifconf.ifc_len==0) {
LOG(logLevelDebug,
"getBroadcastAddresses(): unable to fetch network interface configuration");
delete[] pIfreqList;
addDefaultBroadcastAddress(retVector, defaultPort);
return retVector;
}
int maxNodes = ifconf.ifc_len/sizeof(ifreq);
//errlogPrintf("Found %d interfaces\n", maxNodes);
pifreq = pIfreqList;
for(int i = 0; i<maxNodes; i++) {
if(!(*pifreq->ifr_name)) break;
if(i>0) {
size_t n = SA_LEN(pifreq->ifr_addr)+sizeof(pifreq->ifr_name);
if(n<sizeof(ifreq))
pifreq++;
else
pifreq = (struct ifreq *)((char *)pifreq+n);
}
/*
* If its not an internet interface then dont use it
*/
if(pifreq->ifr_addr.sa_family!=AF_INET) continue;
strncpy(ifrBuff.ifr_name, pifreq->ifr_name,
sizeof(ifrBuff.ifr_name));
status = ioctl(sock, SIOCGIFFLAGS, &ifrBuff);
if(status) {
LOG(
logLevelDebug,
"getBroadcastAddresses(): net intf flags fetch for \"%s\" failed",
pifreq->ifr_name);
continue;
}
/*
* dont bother with interfaces that have been disabled
*/
if(!(ifrBuff.ifr_flags&IFF_UP)) continue;
/*
* dont use the loop back interface
*/
if(ifrBuff.ifr_flags&IFF_LOOPBACK) continue;
/*
* If this is an interface that supports
* broadcast fetch the broadcast address.
*
* Otherwise if this is a point to point
* interface then use the destination address.
*
* Otherwise CA will not query through the
* interface.
*/
if(ifrBuff.ifr_flags&IFF_BROADCAST) {
strncpy(ifrBuff.ifr_name, pifreq->ifr_name,
sizeof(ifrBuff.ifr_name));
status = ioctl(sock, SIOCGIFBRDADDR, &ifrBuff);
if(status) {
LOG(
logLevelDebug,
"getBroadcastAddresses(): net intf \"%s\": bcast addr fetch fail",
pifreq->ifr_name);
continue;
}
pNewNode.sa = ifrBuff.ifr_broadaddr;
}
#ifdef IFF_POINTOPOINT
else if(ifrBuff.ifr_flags&IFF_POINTOPOINT) {
strncpy(ifrBuff.ifr_name, pifreq->ifr_name,
sizeof(ifrBuff.ifr_name));
status = ioctl(sock, SIOCGIFDSTADDR, &ifrBuff);
if(status) {
LOG(
logLevelDebug,
"getBroadcastAddresses(): net intf \"%s\": pt to pt addr fetch fail",
pifreq->ifr_name);
continue;
}
pNewNode.sa = ifrBuff.ifr_dstaddr;
}
#endif
else {
LOG(
logLevelDebug,
"getBroadcastAddresses(): net intf \"%s\": not point to point or bcast?",
pifreq->ifr_name);
continue;
}
pNewNode.ia.sin_port = htons(defaultPort);
retVector->push_back(pNewNode);
}
delete[] pIfreqList;
return retVector;
ellFree(&as);
return v;
}
void encodeAsIPv6Address(ByteBuffer* buffer, const osiSockAddr* address) {
@@ -218,7 +63,7 @@ namespace epics {
// next 16-bits are 1
buffer->putShort(0xFFFF);
// following IPv4 address in big-endian (network) byte order
in_addr_t ipv4Addr = ntohl(address->ia.sin_addr.s_addr);
uint32_t ipv4Addr = ntohl(address->ia.sin_addr.s_addr);
buffer->putByte((int8)((ipv4Addr>>24)&0xFF));
buffer->putByte((int8)((ipv4Addr>>16)&0xFF));
buffer->putByte((int8)((ipv4Addr>>8)&0xFF));

View File

@@ -35,10 +35,9 @@ namespace epics {
* on this machine. IPv6 doesn't have a local broadcast address.
* Conversion of the defaultPort to network byte order performed by
* the function.
* TODO: Windows implementation of the function.
*/
InetAddrVector* getBroadcastAddresses(SOCKET sock,
in_port_t defaultPort);
unsigned short defaultPort);
/**
* Encode IPv4 address as IPv6 address.

View File

@@ -26,7 +26,7 @@ testBeaconEmitter_LIBS += pvData pvAccess Com
testBeaconHandler_SRCS += testBeaconHandler.cpp
testBeaconHandler_LIBS += pvData pvAccess Com
PROD_HOST += testChannelSearchManager
PROD_HOST_Linux += testChannelSearchManager
testChannelSearchManager_SRCS += testChannelSearchManager.cpp
testChannelSearchManager_LIBS += pvData pvAccess Com

View File

@@ -16,6 +16,7 @@
#include <pv/pvType.h>
#include <osiSock.h>
#include <epicsThread.h>
#include <logger.h>
#include <iostream>
@@ -160,7 +161,7 @@ void testBlockingTCPSender() {
transport->enqueueSendRequest(dts);
else
break;
sleep(1);
epicsThreadSleep(1.0);
}
} catch(std::exception& e) {
cout<<e.what()<<endl;

View File

@@ -13,6 +13,7 @@
//#include <pv/CDRMonitor.h>
#include <osiSock.h>
#include <epicsThread.h>
#include <iostream>
#include <cstdio>
@@ -128,7 +129,7 @@ void testBlockingUDPSender() {
for(int i = 0; i<10; i++) {
cout<<" Packet: "<<i+1<<endl;
transport->enqueueSendRequest(dts);
sleep(1);
epicsThreadSleep(1.0);
}
}

View File

@@ -11,6 +11,7 @@
#include <pv/hexDump.h>
#include <osiSock.h>
#include <epicsThread.h>
#include <iostream>
#include <sstream>
@@ -118,7 +119,7 @@ void testBlockingUDPConnector() {
//TODO drh can be deleted in connector!
while(drh->getPackets()<10) {
sleep(1);
epicsThreadSleep(1.0);
}
}

View File

@@ -596,7 +596,7 @@ class MockChannel : public Channel {
PVDoubleArray *pvField = static_cast<PVDoubleArray*>(m_pvStructure->getScalarArrayField(String("value"), pvDouble));
int v = 0;
int ix = 0;
int COUNT = 1000;
const int COUNT = 1000;
pvField->setCapacity(1000*COUNT);
for (int n = 0; n < 1000; n++)

View File

@@ -26,11 +26,11 @@ PROD_HOST += transportRegisterTest
transportRegisterTest_SRCS += transportRegistryTest.cpp
transportRegisterTest_LIBS += pvAccess Com pvData
PROD_HOST += namedLockPatternTest
PROD_HOST_Linux += namedLockPatternTest
namedLockPatternTest_SRCS += namedLockPatternTest.cpp
namedLockPatternTest_LIBS += pvAccess Com pvData
PROD_HOST += configurationTest
PROD_HOST_Linux += configurationTest
configurationTest_SRCS += configurationTest.cpp
configurationTest_LIBS += pvAccess Com pvData