byte order independent code, transportRevision is int8
This commit is contained in:
@@ -31,13 +31,8 @@ namespace epics {
|
||||
/** Unknown CA protocol minor revision. */
|
||||
const int8 CA_UNKNOWN_MINOR_PROTOCOL_REVISION = 0;
|
||||
|
||||
/** CA magic/major version signature (e.g. 0xCA50). */
|
||||
const int16 CA_MAGIC_AND_MAJOR_VERSION = CA_MAGIC<<8
|
||||
|CA_MAJOR_PROTOCOL_REVISION<<4;
|
||||
|
||||
/** CA magic/version signature (e.g. 0xCA51). */
|
||||
const int16 CA_MAGIC_AND_VERSION = CA_MAGIC<<8
|
||||
|CA_MAJOR_PROTOCOL_REVISION<<4|CA_MINOR_PROTOCOL_REVISION;
|
||||
/** CA version signature (e.g. 0x50). */
|
||||
const int8 CA_VERSION = ((unsigned int8)CA_MAJOR_PROTOCOL_REVISION<<4)|CA_MINOR_PROTOCOL_REVISION;
|
||||
|
||||
/** CA protocol port base. */
|
||||
const int32 CA_PORT_BASE = 5056;
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace epics {
|
||||
BlockingClientTCPTransport::BlockingClientTCPTransport(
|
||||
Context::shared_pointer const & context, SOCKET channel,
|
||||
auto_ptr<ResponseHandler>& responseHandler, int receiveBufferSize,
|
||||
TransportClient::shared_pointer client, short remoteTransportRevision,
|
||||
TransportClient::shared_pointer client, int8 remoteTransportRevision,
|
||||
float beaconInterval, int16 priority) :
|
||||
BlockingTCPTransport(context, channel, responseHandler, receiveBufferSize, priority),
|
||||
_introspectionRegistry(false),
|
||||
|
||||
@@ -343,7 +343,7 @@ namespace epics {
|
||||
int _storedPosition;
|
||||
int _storedLimit;
|
||||
|
||||
short _magicAndVersion;
|
||||
int8 _version;
|
||||
int8 _packetType;
|
||||
int8 _command;
|
||||
int _payloadSize;
|
||||
@@ -447,13 +447,13 @@ namespace epics {
|
||||
private:
|
||||
BlockingClientTCPTransport(Context::shared_pointer const & context, SOCKET channel,
|
||||
std::auto_ptr<ResponseHandler>& responseHandler, int receiveBufferSize,
|
||||
TransportClient::shared_pointer client, short remoteTransportRevision,
|
||||
TransportClient::shared_pointer client, int8 remoteTransportRevision,
|
||||
float beaconInterval, int16 priority);
|
||||
|
||||
public:
|
||||
static BlockingClientTCPTransport::shared_pointer create(Context::shared_pointer const & context, SOCKET channel,
|
||||
std::auto_ptr<ResponseHandler>& responseHandler, int receiveBufferSize,
|
||||
TransportClient::shared_pointer client, short remoteTransportRevision,
|
||||
TransportClient::shared_pointer client, int8 remoteTransportRevision,
|
||||
float beaconInterval, int16 priority)
|
||||
{
|
||||
BlockingClientTCPTransport::shared_pointer thisPointer(
|
||||
@@ -592,7 +592,7 @@ namespace epics {
|
||||
|
||||
virtual Transport::shared_pointer connect(TransportClient::shared_pointer const & client,
|
||||
std::auto_ptr<ResponseHandler>& responseHandler, osiSockAddr& address,
|
||||
short transportRevision, int16 priority);
|
||||
int8 transportRevision, int16 priority);
|
||||
private:
|
||||
/**
|
||||
* Lock timeout
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace epics {
|
||||
|
||||
Transport::shared_pointer BlockingTCPConnector::connect(TransportClient::shared_pointer const & client,
|
||||
std::auto_ptr<ResponseHandler>& responseHandler, osiSockAddr& address,
|
||||
short transportRevision, int16 priority) {
|
||||
int8 transportRevision, int16 priority) {
|
||||
|
||||
SOCKET socket = INVALID_SOCKET;
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace epics {
|
||||
_storedPayloadSize(0),
|
||||
_storedPosition(0),
|
||||
_storedLimit(0),
|
||||
_magicAndVersion(0),
|
||||
_version(0),
|
||||
_packetType(0),
|
||||
_command(0),
|
||||
_payloadSize(0),
|
||||
@@ -234,7 +234,8 @@ namespace epics {
|
||||
_sendPending = false;
|
||||
|
||||
// prepare ACK marker
|
||||
_sendBuffer->putShort(CA_MAGIC_AND_VERSION);
|
||||
_sendBuffer->putByte(CA_MAGIC);
|
||||
_sendBuffer->putByte(CA_VERSION);
|
||||
_sendBuffer->putByte(1); // control data
|
||||
_sendBuffer->putByte(1); // marker ACK
|
||||
_sendBuffer->putInt(0);
|
||||
@@ -327,7 +328,8 @@ namespace epics {
|
||||
_lastMessageStartPosition = -1;
|
||||
ensureBuffer(CA_MESSAGE_HEADER_SIZE+ensureCapacity);
|
||||
_lastMessageStartPosition = _sendBuffer->getPosition();
|
||||
_sendBuffer->putShort(CA_MAGIC_AND_VERSION);
|
||||
_sendBuffer->putByte(CA_MAGIC);
|
||||
_sendBuffer->putByte(CA_VERSION);
|
||||
_sendBuffer->putByte(_lastSegmentedMessageType); // data
|
||||
_sendBuffer->putByte(command); // command
|
||||
_sendBuffer->putInt(0); // temporary zero payload
|
||||
@@ -396,9 +398,10 @@ namespace epics {
|
||||
int position = _sendBuffer->getPosition();
|
||||
int bytesLeft = _sendBuffer->getRemaining();
|
||||
|
||||
if(position>=_nextMarkerPosition&&bytesLeft
|
||||
>=CA_MESSAGE_HEADER_SIZE) {
|
||||
_sendBuffer->putShort(CA_MAGIC_AND_VERSION);
|
||||
if(position>=_nextMarkerPosition &&
|
||||
bytesLeft>=CA_MESSAGE_HEADER_SIZE) {
|
||||
_sendBuffer->putByte(CA_MAGIC);
|
||||
_sendBuffer->putByte(CA_VERSION);
|
||||
_sendBuffer->putByte(1); // control data
|
||||
_sendBuffer->putByte(0); // marker
|
||||
_sendBuffer->putInt((int)(_totalBytesSent+position
|
||||
@@ -549,9 +552,10 @@ namespace epics {
|
||||
|
||||
// first byte is CA_MAGIC
|
||||
// second byte version - major/minor nibble
|
||||
// check magic and version at once
|
||||
_magicAndVersion = _socketBuffer->getShort();
|
||||
if((short)(_magicAndVersion&0xFFF0)!=CA_MAGIC_AND_MAJOR_VERSION) {
|
||||
int8 magic = _socketBuffer->getByte();
|
||||
_version = _socketBuffer->getByte();
|
||||
if((magic != CA_MAGIC) || (((unsigned int8)_version) >> 4)!=CA_MAJOR_PROTOCOL_REVISION)
|
||||
{
|
||||
// error... disconnect
|
||||
LOG(
|
||||
logLevelError,
|
||||
@@ -614,7 +618,7 @@ namespace epics {
|
||||
|
||||
if(_stage==PROCESS_PAYLOAD) {
|
||||
// read header
|
||||
int8 version = (int8)(_magicAndVersion&0xFF);
|
||||
|
||||
// last segment bit set (means in-between segment or last segment)
|
||||
bool notFirstSegment = (_packetType&0x20)!=0;
|
||||
|
||||
@@ -631,7 +635,7 @@ namespace epics {
|
||||
// handle response
|
||||
Transport::shared_pointer thisPointer = shared_from_this();
|
||||
_responseHandler->handleResponse(&_socketAddress,
|
||||
thisPointer, version, _command, _payloadSize,
|
||||
thisPointer, _version, _command, _payloadSize,
|
||||
_socketBuffer);
|
||||
} catch(...) {
|
||||
//noop // TODO print?
|
||||
|
||||
@@ -295,7 +295,7 @@ namespace epics {
|
||||
*/
|
||||
virtual Transport::shared_pointer connect(TransportClient::shared_pointer const & client,
|
||||
std::auto_ptr<ResponseHandler>& responseHandler, osiSockAddr& bindAddress,
|
||||
short transportRevision, int16 priority);
|
||||
int8 transportRevision, int16 priority);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace epics {
|
||||
|
||||
Transport::shared_pointer BlockingUDPConnector::connect(TransportClient::shared_pointer const & client,
|
||||
auto_ptr<ResponseHandler>& responseHandler, osiSockAddr& bindAddress,
|
||||
short transportRevision, int16 priority) {
|
||||
int8 transportRevision, int16 priority) {
|
||||
|
||||
LOG(logLevelDebug, "Creating datagram socket to: %s",
|
||||
inetAddressToString(bindAddress).c_str());
|
||||
|
||||
@@ -144,7 +144,8 @@ namespace epics {
|
||||
|
||||
void BlockingUDPTransport::startMessage(int8 command, int ensureCapacity) {
|
||||
_lastMessageStartPosition = _sendBuffer->getPosition();
|
||||
_sendBuffer->putShort(CA_MAGIC_AND_VERSION);
|
||||
_sendBuffer->putByte(CA_MAGIC);
|
||||
_sendBuffer->putByte(CA_VERSION);
|
||||
_sendBuffer->putByte(0); // data
|
||||
_sendBuffer->putByte(command); // command
|
||||
_sendBuffer->putInt(0); // temporary zero payload
|
||||
@@ -260,9 +261,10 @@ namespace epics {
|
||||
|
||||
// first byte is CA_MAGIC
|
||||
// second byte version - major/minor nibble
|
||||
// check magic and version at once
|
||||
short magicAndVersion = receiveBuffer->getShort();
|
||||
if((short)(magicAndVersion&0xFFF0)!=CA_MAGIC_AND_MAJOR_VERSION) return false;
|
||||
int8 magic = receiveBuffer->getByte();
|
||||
int8 version = receiveBuffer->getByte();
|
||||
if((magic != CA_MAGIC) || (((unsigned int8)version) >> 4)!=CA_MAJOR_PROTOCOL_REVISION)
|
||||
return false;
|
||||
|
||||
// only data for UDP
|
||||
receiveBuffer->getByte();
|
||||
@@ -277,7 +279,7 @@ namespace epics {
|
||||
|
||||
// handle
|
||||
_responseHandler->handleResponse(&fromAddress, thisTransport,
|
||||
(int8)(magicAndVersion&0xFF), command, payloadSize,
|
||||
version, command, payloadSize,
|
||||
_receiveBuffer);
|
||||
|
||||
// set position (e.g. in case handler did not read all)
|
||||
|
||||
@@ -637,7 +637,8 @@ void ChannelSearchManager::initializeSendBuffer()
|
||||
|
||||
// new buffer
|
||||
_sendBuffer->clear();
|
||||
_sendBuffer->putShort(CA_MAGIC_AND_VERSION);
|
||||
_sendBuffer->putByte(CA_MAGIC);
|
||||
_sendBuffer->putByte(CA_VERSION);
|
||||
_sendBuffer->putByte((int8)0); // data
|
||||
_sendBuffer->putByte((int8)3); // search
|
||||
_sendBuffer->putInt(sizeof(int32)/sizeof(int8) + 1); // "zero" payload
|
||||
|
||||
@@ -403,7 +403,7 @@ namespace epics {
|
||||
*/
|
||||
virtual Transport::shared_pointer connect(TransportClient::shared_pointer const & client,
|
||||
std::auto_ptr<ResponseHandler>& responseHandler, osiSockAddr& address,
|
||||
short transportRevision, int16 priority) = 0;
|
||||
int8 transportRevision, int16 priority) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -4028,7 +4028,7 @@ TODO
|
||||
* @param priority process priority.
|
||||
* @return transport for given address
|
||||
*/
|
||||
Transport::shared_pointer getTransport(TransportClient::shared_pointer const & client, osiSockAddr* serverAddress, int16 minorRevision, int16 priority)
|
||||
Transport::shared_pointer getTransport(TransportClient::shared_pointer const & client, osiSockAddr* serverAddress, int8 minorRevision, int16 priority)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace epics {
|
||||
virtual ResponseRequest::shared_pointer unregisterResponseRequest(pvAccessID ioid) = 0;
|
||||
|
||||
|
||||
virtual Transport::shared_pointer getTransport(TransportClient::shared_pointer const & client, osiSockAddr* serverAddress, int16 minorRevision, int16 priority) = 0;
|
||||
virtual Transport::shared_pointer getTransport(TransportClient::shared_pointer const & client, osiSockAddr* serverAddress, int8 minorRevision, int16 priority) = 0;
|
||||
|
||||
virtual void beaconAnomalyNotify() = 0;
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ void testBlockingTCPSender() {
|
||||
|
||||
try {
|
||||
Transport::shared_pointer transport(connector.connect(dtc, drh, srvAddr,
|
||||
CA_MAGIC_AND_VERSION, CA_DEFAULT_PRIORITY));
|
||||
CA_VERSION, CA_DEFAULT_PRIORITY));
|
||||
|
||||
cout<<"Sending 10 messages..."<<endl;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user