getName() and getHostName return string size

This commit is contained in:
Jeff Hill
2004-10-19 20:46:55 +00:00
parent 004db1aea7
commit c3f277dbc6
6 changed files with 56 additions and 32 deletions

View File

@@ -236,12 +236,31 @@ bool nciu::searchMsg ( epicsGuard < epicsMutex > & guard )
}
const char *nciu::pName (
epicsGuard < epicsMutex > & guard ) const
epicsGuard < epicsMutex > & guard ) const throw ()
{
guard.assertIdenticalMutex ( this->cacCtx.mutexRef () );
return this->pNameStr;
}
unsigned nciu::getName (
epicsGuard < epicsMutex > &,
char * pBuf, unsigned bufLen ) const throw ()
{
if ( bufLen == 0u ) {
return 0u;
}
if ( this->nameLength < bufLen ) {
strcpy ( pBuf, this->pNameStr );
return this->nameLength;
}
else {
unsigned reducedSize = bufLen - 1u;
strncpy ( pBuf, this->pNameStr, bufLen );
pBuf[reducedSize] = '\0';
return reducedSize;
}
}
unsigned nciu::nameLen (
epicsGuard < epicsMutex > & guard ) const
{
@@ -386,21 +405,14 @@ void nciu::ioShow (
this->cacCtx.ioShow ( guard, idIn, level );
}
void nciu::hostName (
unsigned nciu::getHostName (
epicsGuard < epicsMutex > & guard,
char *pBuf, unsigned bufLength ) const
char *pBuf, unsigned bufLength ) const throw ()
{
this->piiu->hostName (
return this->piiu->getHostName (
guard, pBuf, bufLength );
}
// deprecated - please do not use, this is _not_ thread safe
const char * nciu::pHostName (
epicsGuard < epicsMutex > & guard ) const
{
return this->piiu->pHostName ( guard );
}
bool nciu::ca_v42_ok (
epicsGuard < epicsMutex > & guard ) const
{
@@ -477,7 +489,7 @@ void nciu::show (
{
if ( this->connected ( guard ) ) {
char hostNameTmp [256];
this->hostName ( guard, hostNameTmp, sizeof ( hostNameTmp ) );
this->getHostName ( guard, hostNameTmp, sizeof ( hostNameTmp ) );
::printf ( "Channel \"%s\", connected to server %s",
this->pNameStr, hostNameTmp );
if ( level > 1u ) {

View File

@@ -178,12 +178,16 @@ public:
void show (
epicsGuard < epicsMutex > &,
unsigned level ) const;
unsigned getName (
epicsGuard < epicsMutex > &,
char * pBuf, unsigned bufLen ) const throw ();
const char * pName (
epicsGuard < epicsMutex > & ) const;
epicsGuard < epicsMutex > & ) const throw ();
unsigned nameLen (
epicsGuard < epicsMutex > & ) const;
const char * pHostName (
epicsGuard < epicsMutex > & ) const; // deprecated - please do not use
unsigned getHostName (
epicsGuard < epicsMutex > &,
char * pBuf, unsigned bufLen ) const throw ();
void writeException (
epicsGuard < epicsMutex > &, epicsGuard < epicsMutex > &,
int status, const char *pContext, unsigned type, arrayElementCount count );
@@ -255,9 +259,6 @@ private:
epicsGuard < epicsMutex > & ) const;
bool ca_v42_ok (
epicsGuard < epicsMutex > & ) const;
void hostName (
epicsGuard < epicsMutex > &,
char *pBuf, unsigned bufLength ) const;
arrayElementCount nativeElementCount (
epicsGuard < epicsMutex > & ) const;
static void stringVerify ( const char *pStr, const unsigned count );

View File

@@ -88,20 +88,31 @@ void netiiu::subscriptionUpdateRequest (
{
}
void netiiu::hostName (
static const char * const pHostNameNetIIU = "<disconnected>";
unsigned netiiu::getHostName (
epicsGuard < epicsMutex > & guard,
char *pBuf, unsigned bufLength ) const
char * pBuf, unsigned bufLen ) const throw ()
{
if ( bufLength ) {
strncpy ( pBuf, this->pHostName ( guard ), bufLength );
pBuf[bufLength - 1u] = '\0';
if ( bufLen ) {
unsigned len = strlen ( pHostNameNetIIU );
strncpy ( pBuf, pHostNameNetIIU, bufLen );
if ( len < bufLen ) {
return len;
}
else {
unsigned reducedSize = bufLen - 1u;
pBuf[reducedSize] = '\0';
return reducedSize;
}
}
return 0u;
}
const char * netiiu::pHostName (
epicsGuard < epicsMutex > & ) const
{
return "<disconnected>";
return pHostNameNetIIU;
}
osiSockAddr netiiu::getNetworkAddress (

View File

@@ -38,11 +38,11 @@ class nciu;
class netiiu {
public:
virtual ~netiiu () = 0;
virtual void hostName (
virtual unsigned getHostName (
epicsGuard < epicsMutex > &, char * pBuf,
unsigned bufLength ) const = 0;
unsigned bufLength ) const throw () = 0;
virtual const char * pHostName (
epicsGuard < epicsMutex > & ) const = 0;
epicsGuard < epicsMutex > & ) const = 0;
virtual bool ca_v41_ok (
epicsGuard < epicsMutex > & ) const = 0;
virtual bool ca_v42_ok (

View File

@@ -33,11 +33,11 @@ noopiiu::~noopiiu ()
{
}
void noopiiu::hostName (
unsigned noopiiu::getHostName (
epicsGuard < epicsMutex > & cacGuard,
char *pBuf, unsigned bufLength ) const
char * pBuf, unsigned bufLength ) const throw ()
{
netiiu::hostName ( cacGuard, pBuf, bufLength );
return netiiu::getHostName ( cacGuard, pBuf, bufLength );
}
const char * noopiiu::pHostName (

View File

@@ -30,9 +30,9 @@
class noopiiu : public netiiu {
public:
~noopiiu ();
void hostName (
unsigned getHostName (
epicsGuard < epicsMutex > &, char * pBuf,
unsigned bufLength ) const;
unsigned bufLength ) const throw ();
const char * pHostName (
epicsGuard < epicsMutex > & ) const;
bool ca_v41_ok (