Exemple #1
0
int hb_sockexSelect( PHB_ITEM pArrayRD, HB_BOOL fSetRD,
                     PHB_ITEM pArrayWR, HB_BOOL fSetWR,
                     PHB_ITEM pArrayEX, HB_BOOL fSetEX,
                     HB_MAXINT timeout, HB_SOCKET_FUNC pFunc )
{
   int iResult;
   HB_SIZE nRead = 0, nWrite = 0, nLen, nPos;
   PHB_SOCKEX pSock;

   if( pArrayRD )
   {
      nLen = hb_arrayLen( pArrayRD );
      for( nPos = 1; nPos <= nLen; ++nPos )
      {
         pSock = hb_sockexItemGet( hb_arrayGetItemPtr( pArrayRD, nPos ) );
         if( pSock && pSock->pFilter->CanRead( pSock, HB_TRUE, 0 ) > 0 )
         {
            ++nRead;
            if( fSetRD && nRead != nPos )
               hb_itemMove( hb_arrayGetItemPtr( pArrayRD, nRead ),
                            hb_arrayGetItemPtr( pArrayRD, nPos ) );
         }
      }
   }
   if( pArrayWR )
   {
      nLen = hb_arrayLen( pArrayWR );
      for( nPos = 1; nPos <= nLen; ++nPos )
      {
         pSock = hb_sockexItemGet( hb_arrayGetItemPtr( pArrayWR, nPos ) );
         if( pSock && pSock->pFilter->CanWrite( pSock, HB_TRUE, 0 ) > 0 )
         {
            ++nWrite;
            if( fSetWR && nWrite != nPos )
               hb_itemMove( hb_arrayGetItemPtr( pArrayWR, nWrite ),
                            hb_arrayGetItemPtr( pArrayWR, nPos ) );
         }
      }
   }

   if( nRead > 0 || nWrite > 0 )
   {
      if( fSetRD && pArrayRD )
         hb_arraySize( pArrayRD, nRead );
      if( fSetWR && pArrayWR )
         hb_arraySize( pArrayWR, nWrite );
      if( fSetEX && pArrayEX )
         hb_arraySize( pArrayEX, 0 );
      iResult = ( int ) ( nRead + nWrite );
   }
   else
   {
      if( pFunc == NULL )
         pFunc = s_socketSelectCallback;
      iResult = hb_socketSelect( pArrayRD, fSetRD, pArrayWR, fSetWR, pArrayEX, fSetEX,
                                 timeout, pFunc );
   }

   return iResult;
}
Exemple #2
0
static HB_ERRCODE s_waList( AREAP pArea, void * Cargo )
{
   PHB_ITEM pArray = ( PHB_ITEM ) Cargo;
   HB_SIZE  nLen   = hb_arrayLen( pArray ) + 1;

   hb_arraySize( pArray, nLen );
   hb_arraySetC( pArray, nLen, hb_dynsymName( ( PHB_DYNS ) pArea->atomAlias ) );

   return HB_SUCCESS;
}
Exemple #3
0
void hb_tblStructure( AREAP pArea, PHB_ITEM pStruct, HB_USHORT uiSize )
{
   HB_USHORT uiFields, uiCount;

   if( SELF_FIELDCOUNT( pArea, &uiFields ) == HB_SUCCESS )
   {
      if( hb_arraySize( pStruct, uiFields ) )
      {
         for( uiCount = 1; uiCount <= uiFields; ++uiCount )
            hb_fldStructure( pArea, uiCount, uiSize,
                             hb_arrayGetItemPtr( pStruct, uiCount ) );
      }
   }
}
Exemple #4
0
HB_ERRCODE hb_dbTransStruct( AREAP lpaSource, AREAP lpaDest,
                             LPDBTRANSINFO lpdbTransInfo,
                             PHB_ITEM * pStruct, PHB_ITEM pFields )
{
   HB_USHORT uiFields, uiSize, uiCount, uiPosSrc, uiPosDst, uiSizeSrc, uiSizeDst;
   HB_ERRCODE errCode;
   const char * szField;
   HB_BOOL fAll;

   errCode = SELF_FIELDCOUNT( lpaSource, &uiSizeSrc );
   if( errCode != HB_SUCCESS )
      return errCode;

   if( lpaDest )
   {
      errCode = SELF_FIELDCOUNT( lpaDest, &uiSizeDst );
      if( errCode != HB_SUCCESS )
         return errCode;
      uiSize = HB_MIN( uiSizeDst, uiSizeSrc );
   }
   else
   {
      uiSize = uiSizeDst = uiSizeSrc;
   }

   if( ! uiSize )
      return HB_FAILURE;
   if( hb_itemType( pFields ) & HB_IT_ARRAY )
   {
      uiFields = ( HB_USHORT ) hb_arrayLen( pFields );
      if( uiFields )
         uiSize = uiFields;
   }
   else
      uiFields = 0;

   fAll = ( uiSizeDst == uiSizeSrc );

   lpdbTransInfo->lpaSource    = lpaSource;
   lpdbTransInfo->lpaDest      = lpaDest;
   lpdbTransInfo->lpTransItems = ( LPDBTRANSITEM )
                                    hb_xgrab( uiSize * sizeof( DBTRANSITEM ) );

   if( ! lpaDest )
   {
      *pStruct = hb_itemNew( NULL );
      hb_arrayNew( *pStruct, 0 );
   }

   if( uiFields == 0 )
   {
      if( lpaDest )
      {
         PHB_ITEM pItem = hb_itemNew( NULL );
         uiSize = 0;
         for( uiCount = 1; uiCount <= uiSizeSrc; ++uiCount )
         {
            if( SELF_FIELDINFO( lpaSource, uiCount, DBS_NAME, pItem ) != HB_SUCCESS )
            {
               uiSize = 0;
               break;
            }
            szField = hb_itemGetCPtr( pItem );
            uiPosDst = hb_rddFieldExpIndex( lpaDest, szField );
            if( uiPosDst != uiCount )
               fAll = HB_FALSE;
            if( uiPosDst )
            {
               HB_USHORT ui;

               /* check for replicated field names in source area */
               for( ui = 0; ui < uiSize; ++ui )
               {
                  if( lpdbTransInfo->lpTransItems[ ui ].uiDest == uiPosDst )
                     break;
               }
               if( ui == uiSize )
               {
                  lpdbTransInfo->lpTransItems[ uiSize ].uiSource = uiCount;
                  lpdbTransInfo->lpTransItems[ uiSize++ ].uiDest = uiPosDst;
               }
            }
         }
         hb_itemRelease( pItem );
      }
      else
      {
         hb_tblStructure( lpaSource, *pStruct, 0 );
         uiSize = ( HB_USHORT ) hb_arrayLen( *pStruct );
         for( uiCount = 0; uiCount < uiSize; ++uiCount )
         {
            lpdbTransInfo->lpTransItems[ uiCount ].uiSource =
            lpdbTransInfo->lpTransItems[ uiCount ].uiDest = uiCount + 1;
         }
      }
   }
   else
   {
      uiSize = 0;
      for( uiCount = 1; uiCount <= uiFields; ++uiCount )
      {
         szField = hb_dbTransFieldPos( pFields, uiCount );
         if( szField )
         {
            uiPosSrc = hb_rddFieldExpIndex( lpaSource, szField );
            if( ! uiPosSrc )
               continue;
            if( lpaDest )
               uiPosDst = hb_rddFieldExpIndex( lpaDest, szField );
            else
               uiPosDst = uiSize + 1;
            if( uiPosDst )
            {
               if( uiPosSrc != uiPosDst )
                  fAll = HB_FALSE;
               lpdbTransInfo->lpTransItems[ uiSize ].uiSource = uiPosSrc;
               lpdbTransInfo->lpTransItems[ uiSize++ ].uiDest = uiPosDst;
               if( ! lpaDest )
               {
                  hb_arraySize( *pStruct, uiSize );
                  hb_fldStructure( lpaSource, uiPosSrc, 0,
                                   hb_arrayGetItemPtr( *pStruct, uiSize ) );
               }
            }
         }
      }
   }

   if( uiSize != uiSizeSrc )
      fAll = HB_FALSE;

   if( fAll && lpaDest )
   {
      PHB_ITEM pSrcItm = hb_itemNew( NULL ),
               pDstItm = hb_itemNew( NULL );
      /*
       * if fAll is HB_TRUE here then it means that all fields are included
       * and they are on the same positions in both tables, so now check
       * if their types and sizes are also equal
       */
      for( uiCount = 1; uiCount <= uiSize; ++uiCount )
      {
         if( SELF_FIELDINFO( lpaSource, uiCount, DBS_TYPE, pSrcItm ) != HB_SUCCESS ||
             SELF_FIELDINFO( lpaDest,   uiCount, DBS_TYPE, pDstItm ) != HB_SUCCESS )
         {
            uiSize = 0;
            break;
         }
         if( hb_stricmp( hb_itemGetCPtr( pSrcItm ),
                         hb_itemGetCPtr( pDstItm ) ) != 0 )
         {
            fAll = HB_FALSE;
            break;
         }
         if( SELF_FIELDINFO( lpaSource, uiCount, DBS_LEN, pSrcItm ) != HB_SUCCESS ||
             SELF_FIELDINFO( lpaDest,   uiCount, DBS_LEN, pDstItm ) != HB_SUCCESS )
         {
            uiSize = 0;
            break;
         }
         if( hb_itemGetNL( pSrcItm ) != hb_itemGetNL( pDstItm ) )
         {
            fAll = HB_FALSE;
            break;
         }
         if( SELF_FIELDINFO( lpaSource, uiCount, DBS_DEC, pSrcItm ) != HB_SUCCESS ||
             SELF_FIELDINFO( lpaDest,   uiCount, DBS_DEC, pDstItm ) != HB_SUCCESS )
         {
            uiSize = 0;
            break;
         }
         if( hb_itemGetNL( pSrcItm ) != hb_itemGetNL( pDstItm ) )
         {
            fAll = HB_FALSE;
            break;
         }
#ifdef DBS_FLAG
         if( SELF_FIELDINFO( lpaSource, uiCount, DBS_FLAG, pSrcItm ) != HB_SUCCESS ||
             SELF_FIELDINFO( lpaDest,   uiCount, DBS_FLAG, pDstItm ) != HB_SUCCESS )
         {
            uiSize = 0;
            break;
         }
         if( hb_itemGetNL( pSrcItm ) != hb_itemGetNL( pDstItm ) )
         {
            fAll = HB_FALSE;
            break;
         }
#endif
      }
      hb_itemRelease( pSrcItm );
      hb_itemRelease( pDstItm );
   }

   lpdbTransInfo->uiFlags = fAll ? DBTF_MATCH : 0;
   lpdbTransInfo->uiItemCount = uiSize;

   return uiSize ? HB_SUCCESS : HB_FAILURE;
}