use new data conversion interface
This commit is contained in:
@@ -289,7 +289,7 @@ caStatus casDGClient::searchResponse ( const caHdrLargeArray & msg,
|
||||
// server's port when it is a redirect).
|
||||
//
|
||||
if (ina.sin_port==0u) {
|
||||
ina.sin_port = epicsHTON16 (static_cast <unsigned short> (CA_SERVER_PORT));
|
||||
ina.sin_port = htons ( CA_SERVER_PORT );
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -307,17 +307,17 @@ caStatus casDGClient::searchResponse ( const caHdrLargeArray & msg,
|
||||
// o disconnect UDP socket from the destination IP
|
||||
//
|
||||
if ( ina.sin_addr.s_addr == INADDR_ANY ) {
|
||||
ina.sin_addr.s_addr = epicsNTOH32 (~0U);
|
||||
ina.sin_addr.s_addr = htonl ( ~0U );
|
||||
}
|
||||
}
|
||||
serverAddr = epicsNTOH32 (ina.sin_addr.s_addr);
|
||||
serverPort = epicsNTOH16 (ina.sin_port);
|
||||
serverAddr = ntohl ( ina.sin_addr.s_addr );
|
||||
serverPort = ntohs ( ina.sin_port );
|
||||
}
|
||||
else {
|
||||
caNetAddr addr = this->serverAddress ();
|
||||
struct sockaddr_in inetAddr = addr.getSockIP();
|
||||
serverAddr = ~0U;
|
||||
serverPort = epicsNTOH16 ( inetAddr.sin_port );
|
||||
serverPort = ntohs ( inetAddr.sin_port );
|
||||
}
|
||||
|
||||
ca_uint16_t * pMinorVersion;
|
||||
@@ -332,7 +332,8 @@ caStatus casDGClient::searchResponse ( const caHdrLargeArray & msg,
|
||||
// This value is ignored by earlier clients.
|
||||
//
|
||||
if ( status == S_cas_success ) {
|
||||
*pMinorVersion = epicsHTON16 ( CA_MINOR_PROTOCOL_REVISION );
|
||||
AlignedWireRef < epicsUInt16 > tmp ( *pMinorVersion );
|
||||
tmp = CA_MINOR_PROTOCOL_REVISION;
|
||||
this->out.commitMsg ();
|
||||
}
|
||||
|
||||
@@ -391,9 +392,9 @@ void casDGClient::sendBeacon ( ca_uint32_t beaconNumber )
|
||||
// create the message
|
||||
//
|
||||
memset ( & buf, 0, sizeof ( msg ) );
|
||||
msg.m_cmmd = epicsHTON16 ( CA_PROTO_RSRV_IS_UP );
|
||||
msg.m_dataType = epicsHTON16 ( CA_MINOR_PROTOCOL_REVISION );
|
||||
msg.m_cid = epicsHTON32 ( beaconNumber );
|
||||
AlignedWireRef < epicsUInt16 > ( msg.m_cmmd ) = CA_PROTO_RSRV_IS_UP;
|
||||
AlignedWireRef < epicsUInt16 > ( msg.m_dataType ) = CA_MINOR_PROTOCOL_REVISION;
|
||||
AlignedWireRef < epicsUInt32 > ( msg.m_cid ) = beaconNumber;
|
||||
|
||||
//
|
||||
// send it to all addresses on the beacon list,
|
||||
@@ -754,8 +755,8 @@ caStatus casDGClient::processMsg ()
|
||||
rawMP = this->in.msgPtr ();
|
||||
memcpy ( & smallHdr, rawMP, sizeof ( smallHdr ) );
|
||||
|
||||
ca_uint32_t payloadSize = epicsNTOH16 ( smallHdr.m_postsize );
|
||||
ca_uint32_t nElem = epicsNTOH16 ( smallHdr.m_count );
|
||||
ca_uint32_t payloadSize = AlignedWireRef < epicsUInt16 > ( smallHdr.m_postsize );
|
||||
ca_uint32_t nElem = AlignedWireRef < epicsUInt16 > ( smallHdr.m_count );
|
||||
if ( payloadSize != 0xffff && nElem != 0xffff ) {
|
||||
hdrSize = sizeof ( smallHdr );
|
||||
}
|
||||
@@ -770,16 +771,16 @@ caStatus casDGClient::processMsg ()
|
||||
// alignment problems
|
||||
//
|
||||
memcpy ( LWA, rawMP + sizeof ( caHdr ), sizeof( LWA ) );
|
||||
payloadSize = epicsNTOH32 ( LWA[0] );
|
||||
nElem = epicsNTOH32 ( LWA[1] );
|
||||
payloadSize = AlignedWireRef < epicsUInt32 > ( LWA[0] );
|
||||
nElem = AlignedWireRef < epicsUInt32 > ( LWA[1] );
|
||||
}
|
||||
|
||||
msgTmp.m_cmmd = epicsNTOH16 ( smallHdr.m_cmmd );
|
||||
msgTmp.m_cmmd = AlignedWireRef < epicsUInt16 > ( smallHdr.m_cmmd );
|
||||
msgTmp.m_postsize = payloadSize;
|
||||
msgTmp.m_dataType = epicsNTOH16 ( smallHdr.m_dataType );
|
||||
msgTmp.m_dataType = AlignedWireRef < epicsUInt16 > ( smallHdr.m_dataType );
|
||||
msgTmp.m_count = nElem;
|
||||
msgTmp.m_cid = epicsNTOH32 ( smallHdr.m_cid );
|
||||
msgTmp.m_available = epicsNTOH32 ( smallHdr.m_available );
|
||||
msgTmp.m_cid = AlignedWireRef < epicsUInt32 > ( smallHdr.m_cid );
|
||||
msgTmp.m_available = AlignedWireRef < epicsUInt32 > ( smallHdr.m_available );
|
||||
|
||||
if ( payloadSize & 0x7 ) {
|
||||
status = this->sendErr (
|
||||
|
||||
@@ -154,8 +154,8 @@ caStatus casStrmClient::processMsg ()
|
||||
rawMP = this->in.msgPtr ();
|
||||
memcpy ( & smallHdr, rawMP, sizeof ( smallHdr ) );
|
||||
|
||||
ca_uint32_t payloadSize = epicsNTOH16 ( smallHdr.m_postsize );
|
||||
ca_uint32_t nElem = epicsNTOH16 ( smallHdr.m_count );
|
||||
ca_uint32_t payloadSize = AlignedWireRef < epicsUInt16 > ( smallHdr.m_postsize );
|
||||
ca_uint32_t nElem = AlignedWireRef < epicsUInt16 > ( smallHdr.m_count );
|
||||
if ( payloadSize != 0xffff && nElem != 0xffff ) {
|
||||
hdrSize = sizeof ( smallHdr );
|
||||
}
|
||||
@@ -170,16 +170,16 @@ caStatus casStrmClient::processMsg ()
|
||||
// alignment problems
|
||||
//
|
||||
memcpy ( LWA, rawMP + sizeof ( caHdr ), sizeof( LWA ) );
|
||||
payloadSize = epicsNTOH32 ( LWA[0] );
|
||||
nElem = epicsNTOH32 ( LWA[1] );
|
||||
payloadSize = AlignedWireRef < epicsUInt32 > ( LWA[0] );
|
||||
nElem = AlignedWireRef < epicsUInt32 > ( LWA[1] );
|
||||
}
|
||||
|
||||
msgTmp.m_cmmd = epicsNTOH16 ( smallHdr.m_cmmd );
|
||||
msgTmp.m_cmmd = AlignedWireRef < epicsUInt16 > ( smallHdr.m_cmmd );
|
||||
msgTmp.m_postsize = payloadSize;
|
||||
msgTmp.m_dataType = epicsNTOH16 ( smallHdr.m_dataType );
|
||||
msgTmp.m_dataType = AlignedWireRef < epicsUInt16 > ( smallHdr.m_dataType );
|
||||
msgTmp.m_count = nElem;
|
||||
msgTmp.m_cid = epicsNTOH32 ( smallHdr.m_cid );
|
||||
msgTmp.m_available = epicsNTOH32 ( smallHdr.m_available );
|
||||
msgTmp.m_cid = AlignedWireRef < epicsUInt32 > ( smallHdr.m_cid );
|
||||
msgTmp.m_available = AlignedWireRef < epicsUInt32 > ( smallHdr.m_available );
|
||||
|
||||
// disconnect clients that dont send 8 byte aligned payloads
|
||||
if ( payloadSize & 0x7 ) {
|
||||
@@ -520,10 +520,12 @@ caStatus casStrmClient::readResponse ( epicsGuard < casClientMutex > & guard,
|
||||
return this->sendErrWithEpicsStatus (
|
||||
guard, & msg, pChan->getCID(), S_cas_badBounds, ECA_GETFAIL );
|
||||
}
|
||||
#ifdef CONVERSION_REQUIRED
|
||||
( * cac_dbr_cvrt[msg.m_dataType] )
|
||||
( pPayload, pPayload, true, msg.m_count );
|
||||
#endif
|
||||
int cacStatus = caNetConvert (
|
||||
msg.m_dataType, pPayload, pPayload, true, msg.m_count );
|
||||
if ( cacStatus != ECA_NORMAL ) {
|
||||
return this->sendErrWithEpicsStatus (
|
||||
guard, & msg, pChan->getCID(), S_cas_internal, cacStatus );
|
||||
}
|
||||
if ( msg.m_dataType == DBR_STRING && msg.m_count == 1u ) {
|
||||
unsigned reducedPayloadSize = strlen ( static_cast < char * > ( pPayload ) ) + 1u;
|
||||
this->out.commitMsg ( reducedPayloadSize );
|
||||
@@ -621,10 +623,12 @@ caStatus casStrmClient::readNotifyResponse ( epicsGuard < casClientMutex > & gua
|
||||
return this->readNotifyFailureResponse ( guard, msg, ECA_NOCONVERT );
|
||||
}
|
||||
|
||||
#ifdef CONVERSION_REQUIRED
|
||||
( * cac_dbr_cvrt[ msg.m_dataType ] )
|
||||
( pPayload, pPayload, true, msg.m_count );
|
||||
#endif
|
||||
int cacStatus = caNetConvert (
|
||||
msg.m_dataType, pPayload, pPayload, true, msg.m_count );
|
||||
if ( cacStatus != ECA_NORMAL ) {
|
||||
return this->sendErrWithEpicsStatus (
|
||||
guard, & msg, pChan->getCID(), S_cas_internal, cacStatus );
|
||||
}
|
||||
|
||||
if ( msg.m_dataType == DBR_STRING && msg.m_count == 1u ) {
|
||||
unsigned reducedPayloadSize = strlen ( static_cast < char * > ( pPayload ) ) + 1u;
|
||||
@@ -854,11 +858,12 @@ caStatus casStrmClient::monitorResponse (
|
||||
return monitorFailureResponse ( guard, msg, ECA_NOCONVERT );
|
||||
}
|
||||
|
||||
#ifdef CONVERSION_REQUIRED
|
||||
/* use type as index into conversion jumptable */
|
||||
(* cac_dbr_cvrt[msg.m_dataType])
|
||||
( pPayload, pPayload, true, msg.m_count );
|
||||
#endif
|
||||
int cacStatus = caNetConvert (
|
||||
msg.m_dataType, pPayload, pPayload, true, msg.m_count );
|
||||
if ( cacStatus != ECA_NORMAL ) {
|
||||
return this->sendErrWithEpicsStatus (
|
||||
guard, & msg, chan.getCID(), S_cas_internal, cacStatus );
|
||||
}
|
||||
|
||||
//
|
||||
// force string message size to be the true size
|
||||
@@ -1602,7 +1607,7 @@ caStatus casStrmClient::eventAddAction (
|
||||
// place monitor mask in correct byte order
|
||||
//
|
||||
casEventMask mask;
|
||||
ca_uint16_t caProtoMask = epicsNTOH16 (pMonInfo->m_mask);
|
||||
ca_uint16_t caProtoMask = AlignedWireRef < epicsUInt16 > ( pMonInfo->m_mask );
|
||||
if (caProtoMask&DBE_VALUE) {
|
||||
mask |= this->getCAS().valueEventMask();
|
||||
}
|
||||
@@ -1966,25 +1971,21 @@ caStatus casStrmClient::write()
|
||||
const caHdrLargeArray *pHdr = this->ctx.getMsg();
|
||||
caStatus status;
|
||||
|
||||
//
|
||||
// no puts via compound types (for now)
|
||||
//
|
||||
if (dbr_value_offset[pHdr->m_dataType]) {
|
||||
return S_cas_badType;
|
||||
}
|
||||
|
||||
#ifdef CONVERSION_REQUIRED
|
||||
// dont byte swap twice
|
||||
if ( this->payloadNeedsByteSwap ) {
|
||||
/* use type as index into conversion jumptable */
|
||||
(* cac_dbr_cvrt[pHdr->m_dataType])
|
||||
( this->ctx.getData(),
|
||||
this->ctx.getData(),
|
||||
false, /* net -> host format */
|
||||
pHdr->m_count);
|
||||
int cacStatus = caNetConvert (
|
||||
pHdr->m_dataType, this->ctx.getData(), this->ctx.getData(),
|
||||
false, pHdr->m_count );
|
||||
if ( cacStatus != ECA_NORMAL ) {
|
||||
return S_cas_badType;
|
||||
}
|
||||
this->payloadNeedsByteSwap = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
// clear async IO flag
|
||||
|
||||
@@ -104,12 +104,14 @@ caStatus outBuf::copyInHeader ( ca_uint16_t response, ca_uint32_t payloadSize,
|
||||
return status;
|
||||
}
|
||||
|
||||
pHdr->m_cmmd = epicsHTON16 ( response );
|
||||
pHdr->m_dataType = epicsHTON16 ( dataType );
|
||||
pHdr->m_cid = epicsHTON32 ( cid );
|
||||
pHdr->m_available = epicsHTON32 ( responseSpecific );
|
||||
pHdr->m_postsize = epicsHTON16 ( static_cast < epicsUInt16 > ( alignedPayloadSize ) );
|
||||
pHdr->m_count = epicsHTON16 ( static_cast < epicsUInt16 > ( nElem ) );
|
||||
AlignedWireRef < epicsUInt16 > ( pHdr->m_cmmd ) = response;
|
||||
AlignedWireRef < epicsUInt16 > ( pHdr->m_dataType ) = dataType;
|
||||
AlignedWireRef < epicsUInt32 > ( pHdr->m_cid ) = cid;
|
||||
AlignedWireRef < epicsUInt32 > ( pHdr->m_available ) = responseSpecific;
|
||||
AlignedWireRef < epicsUInt16 > ( pHdr->m_postsize ) =
|
||||
static_cast < epicsUInt16 > ( alignedPayloadSize );
|
||||
AlignedWireRef < epicsUInt16 > ( pHdr->m_count ) =
|
||||
static_cast < epicsUInt16 > ( nElem );
|
||||
pPayload = reinterpret_cast < char * > ( pHdr + 1 );
|
||||
}
|
||||
else {
|
||||
@@ -122,15 +124,17 @@ caStatus outBuf::copyInHeader ( ca_uint16_t response, ca_uint32_t payloadSize,
|
||||
return status;
|
||||
}
|
||||
|
||||
pHdr->m_cmmd = epicsHTON16 ( response );
|
||||
pHdr->m_dataType = epicsHTON16 ( dataType );
|
||||
pHdr->m_cid = epicsHTON32 ( cid );
|
||||
pHdr->m_available = epicsHTON32 ( responseSpecific );
|
||||
pHdr->m_postsize = epicsHTON16 ( 0xffff );
|
||||
pHdr->m_count = epicsHTON16 ( 0 );
|
||||
AlignedWireRef < epicsUInt16 > ( pHdr->m_cmmd ) = response;
|
||||
AlignedWireRef < epicsUInt16 > ( pHdr->m_dataType ) = dataType;
|
||||
AlignedWireRef < epicsUInt32 > ( pHdr->m_cid ) = cid;
|
||||
AlignedWireRef < epicsUInt32 > ( pHdr->m_available ) = responseSpecific;
|
||||
AlignedWireRef < epicsUInt16 > ( pHdr->m_postsize ) = 0xffff;
|
||||
AlignedWireRef < epicsUInt16 > ( pHdr->m_count ) = 0;
|
||||
ca_uint32_t * pLW = reinterpret_cast < ca_uint32_t * > ( pHdr + 1 );
|
||||
pLW[0] = epicsHTON32 ( alignedPayloadSize );
|
||||
pLW[1] = epicsHTON32 ( nElem );
|
||||
AlignedWireRef < epicsUInt32 > sizeWireRef ( pLW[0] );
|
||||
sizeWireRef = alignedPayloadSize;
|
||||
AlignedWireRef < epicsUInt32 > nElemWireRef ( pLW[1] );
|
||||
nElemWireRef= nElem;
|
||||
pPayload = reinterpret_cast < char * > ( pLW + 2 );
|
||||
}
|
||||
|
||||
@@ -159,13 +163,13 @@ void outBuf::commitMsg ()
|
||||
const caHdr * mp = ( caHdr * ) & this->pBuf[ this->stack ];
|
||||
if ( mp->m_postsize == 0xffff || mp->m_count == 0xffff ) {
|
||||
const ca_uint32_t *pLW = reinterpret_cast <const ca_uint32_t *> ( mp + 1 );
|
||||
payloadSize = epicsNTOH32 ( pLW[0] );
|
||||
elementCount = epicsNTOH32 ( pLW[1] );
|
||||
payloadSize = AlignedWireRef < const epicsUInt32 > ( pLW[0] );
|
||||
elementCount = AlignedWireRef < const epicsUInt32 > ( pLW[1] );
|
||||
hdrSize = sizeof ( caHdr ) + 2 * sizeof ( ca_uint32_t );
|
||||
}
|
||||
else {
|
||||
payloadSize = epicsNTOH16 ( mp->m_postsize );
|
||||
elementCount = epicsNTOH16 ( mp->m_count );
|
||||
payloadSize = AlignedWireRef < const epicsUInt16 > ( mp->m_postsize );
|
||||
elementCount = AlignedWireRef < const epicsUInt16 > ( mp->m_count );
|
||||
hdrSize = sizeof ( caHdr );
|
||||
}
|
||||
|
||||
@@ -173,12 +177,15 @@ void outBuf::commitMsg ()
|
||||
|
||||
unsigned debugLevel = this->client.getDebugLevel();
|
||||
if ( debugLevel ) {
|
||||
if ( mp->m_cmmd != CA_PROTO_VERSION || debugLevel > 2 ) {
|
||||
epicsUInt16 cmmd = AlignedWireRef < const epicsUInt16 > ( mp->m_cmmd );
|
||||
if ( cmmd != CA_PROTO_VERSION || debugLevel > 2 ) {
|
||||
epicsUInt16 type = AlignedWireRef < const epicsUInt16 > ( mp->m_dataType );
|
||||
epicsUInt32 cid = AlignedWireRef < const epicsUInt32 > ( mp->m_cid );
|
||||
epicsUInt32 avail = AlignedWireRef < const epicsUInt32 > ( mp->m_available );
|
||||
fprintf ( stderr,
|
||||
"CAS Response: cmd=%d id=%x typ=%d cnt=%d psz=%d avail=%x outBuf ptr=%p \n",
|
||||
epicsNTOH16 ( mp->m_cmmd ), epicsNTOH32 ( mp->m_cid ),
|
||||
epicsNTOH16 ( mp->m_dataType ), elementCount, payloadSize,
|
||||
epicsNTOH32 ( mp->m_available ), static_cast <const void *> ( mp ) );
|
||||
cmmd, cid, type, elementCount, payloadSize, avail,
|
||||
static_cast < const void * > ( mp ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,12 +199,14 @@ void outBuf::commitMsg ( ca_uint32_t reducedPayloadSize )
|
||||
reducedPayloadSize = CA_MESSAGE_ALIGN ( reducedPayloadSize );
|
||||
if ( mp->m_postsize == 0xffff || mp->m_count == 0xffff ) {
|
||||
ca_uint32_t *pLW = reinterpret_cast <ca_uint32_t *> ( mp + 1 );
|
||||
assert ( reducedPayloadSize <= epicsNTOH32 ( pLW[0] ) );
|
||||
pLW[0] = epicsHTON32 ( reducedPayloadSize );
|
||||
AlignedWireRef < epicsUInt32 > payloadSizeExtended ( pLW[0] );
|
||||
assert ( reducedPayloadSize <= payloadSizeExtended );
|
||||
payloadSizeExtended = reducedPayloadSize;
|
||||
}
|
||||
else {
|
||||
assert ( reducedPayloadSize <= epicsNTOH16 ( mp->m_postsize ) );
|
||||
mp->m_postsize = epicsHTON16 ( static_cast <ca_uint16_t> ( reducedPayloadSize ) );
|
||||
AlignedWireRef < epicsUInt16 > payloadSize ( mp->m_postsize );
|
||||
assert ( reducedPayloadSize <= payloadSize );
|
||||
payloadSize = static_cast < ca_uint16_t > ( reducedPayloadSize );
|
||||
}
|
||||
this->commitMsg ();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user