Ejemplo n.º 1
0
	StatsFile::StatsFile(QString filename)
	:m_filename(filename)
	{
		m_file.setName(filename);
		readSync();
	}
Ejemplo n.º 2
0
bool Connection::recvSync( BufferPtr& outBuffer, const bool block )
{
    LBASSERTINFO( _impl->buffer,
                  "No pending receive on " << getDescription()->toString( ));

    // reset async IO data
    outBuffer = _impl->buffer;
    const uint64_t bytes = _impl->bytes;
    _impl->buffer = 0;
    _impl->bytes = 0;

    if( _impl->state != STATE_CONNECTED || !outBuffer || bytes == 0 )
        return false;
    LBASSERTINFO( bytes < LB_BIT48,
                  "Out-of-sync network stream: read size " << bytes << "?" );
#ifdef STATISTICS
    _impl->inBytes += bytes;
#endif

    // 'Iterators' for receive loop
    uint8_t* ptr = outBuffer->getData() + outBuffer->getSize();
    uint64_t bytesLeft = bytes;
    int64_t got = readSync( ptr, bytesLeft, block );

    // WAR: fluke notification: On Win32, we get occasionally a data
    // notification and then deadlock when reading from the connection. The
    // callee (Node::handleData) will flag the first read, the underlying
    // SocketConnection will not block and we will restore the AIO operation if
    // no data was present.
    if( got == READ_TIMEOUT )
    {
        _impl->buffer = outBuffer;
        _impl->bytes = bytes;
        outBuffer = 0;
        return true;
    }

    // From here on, receive loop until all data read or error
    while( true )
    {
        if( got < 0 ) // error
        {
            const uint64_t read = bytes - bytesLeft;
            outBuffer->resize( outBuffer->getSize() + read );
            if( bytes == bytesLeft )
                LBDEBUG << "Read on dead connection" << std::endl;
            else
                LBERROR << "Error during read after " << read << " bytes on "
                        << _impl->description << std::endl;
            return false;
        }
        else if( got == 0 )
        {
            // ConnectionSet::select may report data on an 'empty' connection.
            // If we have nothing read so far, we have hit this case.
            if( bytes == bytesLeft )
                return false;
            LBVERB << "Zero bytes read" << std::endl;
        }
        if( bytesLeft > static_cast< uint64_t >( got )) // partial read
        {
            ptr += got;
            bytesLeft -= got;

            readNB( ptr, bytesLeft );
            got = readSync( ptr, bytesLeft, true );
            continue;
        }

        // read done
        LBASSERTINFO( static_cast< uint64_t >( got ) == bytesLeft,
                      got << " != " << bytesLeft );

        outBuffer->resize( outBuffer->getSize() + bytes );
#ifndef NDEBUG
        if( bytes <= 1024 && ( lunchbox::Log::topics & LOG_PACKETS ))
        {
            ptr -= (bytes - bytesLeft); // rewind
            LBINFO << "recv:" << lunchbox::format( ptr, bytes ) << std::endl;
        }
#endif
        return true;
    }

    LBUNREACHABLE;
    return true;
}
Ejemplo n.º 3
0
bool Connection::recvSync( void** outBuffer, uint64_t* outBytes,
                           const bool block )
{
    // set up async IO data
    EQASSERT( _aioBuffer );
    EQASSERT( _aioBytes );

    if( outBuffer )
        *outBuffer = _aioBuffer;
    if( outBytes )
        *outBytes = _aioBytes;

    void* buffer( _aioBuffer );
    const uint64_t bytes( _aioBytes );
    _aioBuffer = 0;
    _aioBytes  = 0;

    if( _state != STATE_CONNECTED || !buffer || !bytes )
        return false;

    // 'Iterator' data for receive loop
    uint8_t* ptr = static_cast< uint8_t* >( buffer );
    uint64_t bytesLeft = bytes;

    // WAR: On Win32, we get occasionally a data notification and then deadlock
    // when reading from the connection. The callee (Node::handleData) will flag
    // the first read, the underlying SocketConnection will not block and we
    // will restore the AIO operation if no data was present.
    int64_t got = readSync( ptr, bytesLeft, block );
    if( got == READ_TIMEOUT ) // fluke notification
    {
        EQASSERTINFO( bytesLeft == bytes, bytesLeft << " != " << bytes );
        if( outBytes )
            *outBytes = 0;

        _aioBuffer = buffer;
        _aioBytes  = bytes;
        return true;
    }

    // From here on, blocking receive loop until all data read or error
    while( true )
    {
        if( got < 0 ) // error
        {
            if( outBytes )
                *outBytes -= bytesLeft;
            if( bytes == bytesLeft )
                EQINFO << "Read on dead connection" << std::endl;
            else
                EQERROR << "Error during read after " << bytes - bytesLeft
                        << " bytes on " << _description << std::endl;
            return false;
        }
        else if( got == 0 )
        {
            // ConnectionSet::select may report data on an 'empty' connection.
            // If we have nothing read so far, we have hit this case.
            if( bytes == bytesLeft )
            {
                if( outBytes )
                    *outBytes = 0;
                return false;
            }
            EQVERB << "Zero bytes read" << std::endl;
        }

        if( bytesLeft > static_cast< uint64_t >( got )) // partial read
        {
            ptr += got;
            bytesLeft -= got;

            readNB( ptr, bytesLeft );
            got = readSync( ptr, bytesLeft, true );
        }
        else
        {
            EQASSERTINFO( static_cast< uint64_t >( got ) == bytesLeft,
                          got << " != " << bytesLeft );

#ifndef NDEBUG
            if( bytes <= 1024 && ( base::Log::topics & LOG_PACKETS ))
            {
                ptr = static_cast< uint8_t* >( buffer );
                EQINFO << "recv:" << std::hex << base::disableFlush
                       << base::disableHeader;
                for( size_t i = 0; i < bytes; ++i )
                {
                    if( (i % 16) == 0 )
                        EQINFO << std::endl;
                    if( (i % 4) == 0 )
                        EQINFO << " 0x";
                    EQINFO << std::setfill( '0' ) << std::setw(2)
                           << static_cast< unsigned >( ptr[ i ] );
                }
                EQINFO << std::dec << base::enableFlush
                       << std::endl << base::enableHeader;
            }
#endif
            return true;
        }
    }

    EQUNREACHABLE;
    return true;
}
Ejemplo n.º 4
0
int main(int argc, char **argv) {
  eb_t eb;
  ep_t ep;
  uint64_t networkpid;
  int myproc;
  int numprocs;
  int k;
  int iters = 0;
  int errs = 0;

  TEST_STARTUP(argc, argv, networkpid, eb, ep, 1, 1, "iters");

  /* setup handlers */
  setupUtilHandlers(ep, eb);

  /* get SPMD info */
  myproc = AMX_SPMDMyProc();
  numprocs = AMX_SPMDNumProcs();

  if (argc > 1) iters = atoi(argv[1]);
  if (!iters) iters = 1;
  if (myproc == 0) {
    printf("Running %i iterations of read/write test...\n", iters);
    fflush(stdout);
  }

  /* gather pointers to static data, to handle non-uniform address spaces */
  AM_Safe(AMX_SPMDAllGather(&myvals, pvals, sizeof(myvals))); 

  for (k=0;k < iters; k++) {
    /* set left neighbor's array */
    int i;
    int leftP = myproc-1;
    if (leftP == -1) leftP = numprocs-1;
    for (i=0;i<MAX_PROCS;i++) writeWord(leftP, pvals[leftP]+i, k);
    writeSync();

    AM_Safe(AMX_SPMDBarrier()); /* barrier */

    { /* read right neighbor's array  */
      int i;
      int rightP = myproc+1;
      if (rightP == numprocs) rightP = 0;

      for (i=0;i<MAX_PROCS;i++) readWord(&readarray[i], rightP, pvals[rightP]+i);
      readSync();

      /* verify */
      for (i=0;i<MAX_PROCS;i++) {
        if (((int)readarray[i]) != k) {
          printf("ERROR: Proc %i READ/WRITE TEST FAILED : readarray[%i] = %i   k = %i\n", myproc, i, (int)readarray[i], k);
          fflush(stdout);
          errs++;
          break;
        }
      }
    }

    AM_Safe(AMX_SPMDBarrier()); /* barrier */

  }

  if (!errs) {
    printf("Proc %i verified.\n", myproc);
    fflush(stdout);
  }

  /* dump stats */
  AM_Safe(AMX_SPMDBarrier());
  printGlobalStats();
  AM_Safe(AMX_SPMDBarrier());

  /* exit */
  AM_Safe(AMX_SPMDExit(0));

  return 0;
}
Ejemplo n.º 5
0
MessageList History::readSync(const ChatUnit *unit, int max_num)
{
    return readSync(unit, QDateTime::currentDateTime(), max_num);
}