Starting work on blocking tranport.

This commit is contained in:
miha_vitorovic
2010-12-21 10:06:42 +01:00
parent d0b5e2ad66
commit 20cf4fed8b
3 changed files with 158 additions and 0 deletions

View File

@@ -31,6 +31,9 @@ SRC_DIRS += $(PVACCESS)/factory
LIBSRCS += ChannelAccessFactory.cpp
SRC_DIRS += $(PVACCESS)/remote
INC += blockingUDPTransport.h
LIBSRCS += blockingUDPTransport.cpp
LIBRARY = pvAccess

View File

@@ -0,0 +1,70 @@
/*
* blockingUDPTransport.cpp
*
* Created on: Dec 20, 2010
* Author: Miha Vitorovic
*/
/* pvAccess */
#include "blockingUDPTransport.h"
#include "caConstants.h"
/* pvData */
#include <byteBuffer.h>
/* EPICSv3 */
#include <osdSock.h>
#include <osiSock.h>
#include <errlog.h>
#include <cstdio>
namespace epics {
namespace pvAccess {
using namespace epics::pvData;
BlockingUDPTransport::BlockingUDPTransport(SOCKET channel,
osiSockAddr* bindAddress, osiSockAddr* sendAddresses,
short remoteTransportRevision) {
this->channel = channel;
this->bindAddress = bindAddress;
this->sendAddresses = sendAddresses;
socketAddress = bindAddress;
// allocate receive buffer
receiveBuffer = new ByteBuffer(MAX_UDP_RECV);
// allocate send buffer and non-reentrant lock
sendBuffer = new ByteBuffer(MAX_UDP_SEND);
ignoredAddresses = NULL;
closed = false;
lastMessageStartPosition = 0;
}
BlockingUDPTransport::~BlockingUDPTransport() {
delete receiveBuffer;
delete sendBuffer;
}
void BlockingUDPTransport::start() {
// TODO implement
}
void BlockingUDPTransport::close(bool forced) {
if (closed)
return;
closed = true;
if (bindAddress != NULL)
errlogSevPrintf( errlogInfo, "UDP connection to %d closed.", *bindAddress);
//std::fclose(channel);
}
}
}

View File

@@ -0,0 +1,85 @@
/*
* blockingUDPTransport.h
*
* Created on: Dec 20, 2010
* Author: Miha Vitorovic
*/
#ifndef BLOCKINGUDPTRANSPORT_H_
#define BLOCKINGUDPTRANSPORT_H_
#include <noDefaultMethods.h>
#include <byteBuffer.h>
#include <osdSock.h>
#include <osiSock.h>
namespace epics {
namespace pvAccess {
class BlockingUDPTransport : public epics::pvData::NoDefaultMethods {
public:
BlockingUDPTransport(SOCKET channel, osiSockAddr* bindAddress,
osiSockAddr* sendAddresses, short remoteTransportRevision);
~BlockingUDPTransport();
bool isClosed() {
return closed;
}
void start();
void close(bool forced);
protected:
bool closed;
private:
// Context only used for logging in this class
/**
* Corresponding channel.
*/
SOCKET channel;
/**
* Cached socket address.
*/
osiSockAddr* socketAddress;
/**
* Bind address.
*/
osiSockAddr* bindAddress;
/**
* Send addresses.
*/
osiSockAddr* sendAddresses;
/**
* Ignore addresses.
*/
osiSockAddr* ignoredAddresses;
/**
* Receive buffer.
*/
epics::pvData::ByteBuffer* receiveBuffer;
/**
* Send buffer.
*/
epics::pvData::ByteBuffer* sendBuffer;
/**
* Last message start position.
*/
int lastMessageStartPosition;
};
}
}
#endif /* BLOCKINGUDPTRANSPORT_H_ */