Exemplo n.º 1
0
//---------------------------------------------------------------------------
void Control::TimeOut_Init()
{
    DateTime=QDateTime::currentMSecsSinceEpoch();
    if (!Timer)
    {
        Timer=new QTimer(this);
        connect(Timer, SIGNAL(timeout()), this, SLOT(TimeOut()));
    }
    TimeOut();
}
Exemplo n.º 2
0
/* Test for a  simultaneous property
If the property isn't independently cached, return false (1)
If the simultaneous conversion is more recent, return false (1)
Else return the cached value and true (0)
*/
GOOD_OR_BAD Cache_Get_Simul_Time(enum simul_type type, time_t * dwell_time, const struct parsedname * pn)
{
	// valid cached primary data -- see if a simultaneous conversion should be used instead
	struct tree_node tn;
	time_t duration ;
	time_t time_left ;
	size_t dsize_simul = 0 ;
	struct parsedname pn_directory ;

	duration = TimeOut(ipSimul[type].change); // time allocated this conversion
	if ( duration <= 0) {
		// uncachable
		return gbBAD;
	}

	LEVEL_DEBUG("Looking for conversion time "SNformat, SNvar(pn->sn));
	
	FS_LoadDirectoryOnly(&pn_directory, pn);
	LoadTK(pn_directory.sn, Simul_Marker[type], pn->selected_connection->index, &tn ) ;
	if ( Get_Stat(&cache_int, Cache_Get_Common(NULL, &dsize_simul, &time_left, &tn)) ) {
		return gbBAD ;
	}
	// duration_simul is time left
	// duration is time allocated
	// back-compute dwell time
	dwell_time[0] = duration - time_left ;
	return gbGOOD ;
}
Exemplo n.º 3
0
///////////////////////////////////////////////////////////////////////////////////////
// OutCmd1: Write command and wait for acknowledge of IK 220 with user defined time out
///////////////////////////////////////////////////////////////////////////////////////
BOOL OutCmd1 (USHORT Axis, USHORT IK220Cmd)
{
USHORT	RegW;					// Register value word

	DLLInfo = DLLInfo & 0x00FFFFFF;
	DLLInfo=DLLInfo+0x01000000;											// -- 1 --
	if (!OutputW (Axis, CmdPort, IK220Cmd))				return FALSE;	// Write command to IK 220


	DLLInfo=DLLInfo+0x01000000;											// -- 2 --
	InitTimeOut (TimOutCmd1);											// Init timer for time out
	do 
	{
		if (!InputW (Axis, Flag1Reg, &RegW))			return FALSE;	// Wait until finished
	}																	// or time out
	while ( !(RegW & G28Sem0) && !TimeOut (TimOutCmd1, UserTimeOut1) );

	DLLInfo=DLLInfo+0x01000000;											// -- 3 --
	if (!InputW (Axis, Flag1Reg, &RegW))				return FALSE;	// Finished ?
	if ( !(RegW & G28Sem0) )
	{
		DLLStatus = DLLStatus | DLLStatus_TimeOut;		return FALSE;	// No, time out
	}

	DLLInfo=DLLInfo+0x01000000;											// -- 4 --
	if (!InputW (Axis, DatPort0, &RegW))				return FALSE;	// Verify acknowledge
	if (RegW!=IK220Cmd)
	{
		DLLStatus = DLLStatus | DLLStatus_WrongAck;		return FALSE;	// Wrong command acknowledge
	}
	
	return TRUE;
}
Exemplo n.º 4
0
static void Cache_Del(const struct parsedname *pn)
{
	struct tree_node tn;
	time_t duration;

	//printf("Cache_Del\n") ;
	//printf("Cache_Del\n") ;
	if (!pn) {
		return;	// do check here to avoid needless processing
	}
	
	duration = TimeOut(pn->selected_filetype->change);
	if (duration <= 0) {
		return;				/* in case timeout set to 0 */
	}
	
	LoadTK( pn->sn, pn->selected_filetype, pn->extension, &tn ) ;
	switch (pn->selected_filetype->change) {
		case fc_persistent:
			Del_Stat(&cache_pst, Cache_Del_Persistent(&tn));
			break ;
		default:
			Del_Stat(&cache_ext, Cache_Del_Common(&tn));
			break ;
	}
}
Exemplo n.º 5
0
/* return 0 if good, 1 if not */
GOOD_OR_BAD Cache_Add_SlaveSpecific(const void *data, const size_t datasize, const struct internal_prop *ip, const struct parsedname *pn)
{
	struct tree_node *tn;
	time_t duration;
	//printf("Cache_Add_SlaveSpecific\n");
	if (!pn) {
		return gbGOOD;				// do check here to avoid needless processing
	}

	duration = TimeOut(ip->change);
	if (duration <= 0) {
		return gbGOOD;				/* in case timeout set to 0 */
	}

	tn = (struct tree_node *) owmalloc(sizeof(struct tree_node) + datasize);
	if (!tn) {
		return gbBAD;
	}

	LEVEL_DEBUG("Adding internal data for "SNformat " size=%d", SNvar(pn->sn), (int) datasize);
	LoadTK( pn->sn, ip->name, EXTENSION_INTERNAL, tn );
	tn->expires = duration + NOW_TIME;
	tn->dsize = datasize;
	if (datasize) {
		memcpy(TREE_DATA(tn), data, datasize);
	}
	//printf("ADD INTERNAL name= %s size=%d \n",tn->tk.p.nm,tn->dsize);
	//printf("  ADD INTERNAL data[0]=%d size=%d \n",((BYTE *)data)[0],datasize);
	switch (ip->change) {
	case fc_persistent:
		return Add_Stat(&cache_pst, Cache_Add_Persistent(tn));
	default:
		return Add_Stat(&cache_int, Cache_Add_Common(tn));
	}
}
Exemplo n.º 6
0
	int Socket::Receive(void *pBuffer, int nBufLen, bool bCheckData, long lSecond, long lMinSecond)
	{
		if (TimeOut(lSecond, lMinSecond))
			return SOCKET_ERROR;

		int nRet = 0, nFlags = 0;
		if (bCheckData)
			nFlags = MSG_PEEK;

		nRet = ::recv(m_hSocket, (char*)pBuffer, nBufLen, nFlags);
		if (nRet == 0)
			return SOCKET_ERROR;

		if (nRet != SOCKET_ERROR)
			return nRet;

#ifdef WIN32
		int nErrCode = ::GetLastError();
		if (nErrCode == WSAEWOULDBLOCK)
			return 0;
#else
		if (errno == EAGAIN)
			return 0;
#endif
		return SOCKET_ERROR;
	}
Exemplo n.º 7
0
/* return 0 if good, 1 if not */
GOOD_OR_BAD Cache_Add_Device(const int bus_nr, const BYTE * sn)
{
	time_t duration = TimeOut(fc_presence);
	struct tree_node *tn;

	if (duration <= 0) {
		return gbGOOD;				/* in case timeout set to 0 */
	}

	if ( sn[0] == 0 ) { //bad serial number
		return gbGOOD ;
	}

	tn = (struct tree_node *) owmalloc(sizeof(struct tree_node) + sizeof(int));
	if (!tn) {
		return gbBAD;
	}

	LEVEL_DEBUG("Adding device location " SNformat " bus=%d", SNvar(sn), (int) bus_nr);
	LoadTK(sn, Device_Marker, 0, tn );
	tn->expires = duration + NOW_TIME;
	tn->dsize = sizeof(int);
	memcpy(TREE_DATA(tn), &bus_nr, sizeof(int));
	return Add_Stat(&cache_dev, Cache_Add_Common(tn));
}
Exemplo n.º 8
0
	list <int> Poller::WaitForData (int timeOut) const
	{
		vector <pollfd> pfd (FileDescriptors.size());
		for (size_t i = 0; i < FileDescriptors.size(); i++)
		{
			pfd[i].fd = FileDescriptors[i];
			pfd[i].events = POLLIN;
		}

		list <int> descList;

		int pollRes = poll (&pfd[0], pfd.size(), timeOut);

		if (pollRes == 0 && timeOut != -1)
			throw TimeOut (SRC_POS);

		if (pollRes > 0)
		{
			for (size_t i = 0; i < pfd.size(); i++)
			{
				if (pfd[i].revents & POLLIN)
					descList.push_back (pfd[i].fd);
			}
		}

		return descList;
	}
Exemplo n.º 9
0
void Cache_Del_Mixed_Aggregate(const struct parsedname *pn)
{
	struct tree_node tn;
	time_t duration;
	//printf("Cache_Del\n") ;
	if (!pn) {
		return;				// do check here to avoid needless processing
	}
	if (pn->selected_filetype->ag==NON_AGGREGATE || pn->selected_filetype->ag->combined!=ag_mixed) {
		return ;
	}
	duration = TimeOut(pn->selected_filetype->change);
	if (duration <= 0) {
		return;				/* in case timeout set to 0 */
	}
	
	LoadTK( pn->sn, pn->selected_filetype, EXTENSION_ALL, &tn) ;
	switch (pn->selected_filetype->change) {
		case fc_persistent:
			Del_Stat(&cache_pst, Cache_Del_Persistent(&tn));
			break ;
		default:
			Del_Stat(&cache_ext, Cache_Del_Common(&tn));
			break ;
	}
}
Exemplo n.º 10
0
EFI_STATUS TestTimer()
{
    EFI_STATUS  Status;
    EFI_EVENT myEvent;
    UINTN       index=0;
    UINTN       repeats=0;

    Print(L"Test EVT_TIMER  ");
    Status = gBS->CreateEvent(EVT_TIMER  , TPL_CALLBACK, (EFI_EVENT_NOTIFY)NULL, (VOID*)NULL, &myEvent);
    if(EFI_ERROR(Status)){
        Print(L"Fail EVT_TIMER | EVT_RUNTIME %r", Status);
        return Status;
    }
    Status = gBS->SetTimer(myEvent,TimerPeriodic , 15 * 1000 * 1000);
    while(1)
    {
        Status = gBS->WaitForEvent(1, &myEvent, &index);
        // do something
        TimeOut();
        Print(L"Time out!");
        if(repeats ++ == 10){
            break;
        }
    }
    Status = gBS->CloseEvent(myEvent);
    return EFI_SUCCESS;
}
Exemplo n.º 11
0
/* Look in caches, 0=found and valid, 1=not or uncachable in the first place */
GOOD_OR_BAD Cache_Get(void *data, size_t * dsize, const struct parsedname *pn)
{
	time_t duration;
	struct tree_node tn;
	int persistent ;

	// do check here to avoid needless processing
	if (IsUncachedDir(pn) || IsAlarmDir(pn)) {
		return gbBAD;
	}

	// Special handling of Mock
	persistent = IsThisPersistent(pn) ;
	if ( persistent ) {
		duration = 1 ;
	} else {
		duration = TimeOut(pn->selected_filetype->change);
		if (duration <= 0) {
			return gbBAD;				/* in case timeout set to 0 */
		}
	}


	LEVEL_DEBUG(SNformat " size=%d IsUncachedDir=%d", SNvar(pn->sn), (int) dsize[0], IsUncachedDir(pn));
	LoadTK( pn->sn, pn->selected_filetype, pn->extension, &tn );
	return persistent ?
		Get_Stat(&cache_pst, Cache_Get_Persistent(data, dsize, &duration, &tn)) :
		Get_Stat(&cache_ext, Cache_Get_Common(data, dsize, &duration, &tn));
}
Exemplo n.º 12
0
//---------------------------------------------------------------------------
void MainWindow::processFile(const QString &FileName)
{
    if (FileName.isEmpty())
        return;

    // Files (must be deleted first in order to stop ffmpeg processes)
    for (size_t Pos=0; Pos<Files.size(); Pos++)
        delete Files[Pos];    
    Files.clear();
    ui->fileNamesBox->clear();

    // Layout
    QLayout* Layout=layout();
    if (FilesListArea)
    {
        ui->verticalLayout->removeWidget(FilesListArea);
        delete FilesListArea; FilesListArea=NULL;
    }
    if (PlotsArea)
    {
        ui->verticalLayout->removeWidget(PlotsArea);
        delete PlotsArea; PlotsArea=NULL;
    }
    if (TinyDisplayArea)
    {
        ui->verticalLayout->removeWidget(TinyDisplayArea);
        delete TinyDisplayArea; TinyDisplayArea=NULL;
    }
    if (ControlArea)
    {
        ui->verticalLayout->removeWidget(ControlArea);
        delete ControlArea; ControlArea=NULL;
    }
    if (InfoArea)
    {
        ui->verticalLayout->removeWidget(InfoArea);
        delete InfoArea; InfoArea=NULL;
    }

    // Status
    statusBar()->showMessage("Scanning "+QFileInfo(FileName).fileName()+"...");

    // Launch analysis
    Files.push_back(new FileInformation(this, FileName));
    Files_CurrentPos=0;
    ui->fileNamesBox->addItem(FileName);

    // Coherency
    if (Files[Files_CurrentPos]->Glue->VideoFrameCount==0)
    {
        statusBar()->showMessage("Unsupported format", 10000);
        return;
    }

    TimeOut();
}
Exemplo n.º 13
0
void Cache_Del_Device(const struct parsedname *pn)
{
	struct tree_node tn;
	time_t duration = TimeOut(fc_presence);
	if (duration <= 0) {
		return;
	}

	LoadTK(pn->sn, Device_Marker, 0, &tn) ;
	Del_Stat(&cache_dev, Cache_Del_Common(&tn));
}
Exemplo n.º 14
0
/* return 0 if good, 1 if not */
GOOD_OR_BAD Cache_Add_Dir(const struct dirblob *db, const struct parsedname *pn)
{
	time_t duration = TimeOut(fc_directory);
	struct tree_node *tn;
	size_t size = DirblobElements(db) * SERIAL_NUMBER_SIZE;
	struct parsedname pn_directory;

	if (pn==NO_PARSEDNAME || pn->selected_connection==NO_CONNECTION) {
		return gbGOOD;				// do check here to avoid needless processing
	}
	
	switch ( get_busmode(pn->selected_connection) ) {
		case bus_fake:
		case bus_tester:
		case bus_mock:
		case bus_w1:
		case bus_bad:
		case bus_unknown:
			return gbGOOD ;
		default:
			break ;
	}
	
	if (duration <= 0) {
		return 0;				/* in case timeout set to 0 */
	}

	if ( DirblobElements(db) < 1 ) {
		// only cache long directories.
		// zero (or one?) entry is possibly an error and needs to be repeated more quickly
		LEVEL_DEBUG("Won\'t cache empty directory");
		Cache_Del_Dir( pn ) ;
		return gbGOOD ;
	}
	
	// allocate space for the node and data
	tn = (struct tree_node *) owmalloc(sizeof(struct tree_node) + size);
	if (!tn) {
		return gbBAD;
	}
	
	LEVEL_DEBUG("Adding directory for " SNformat " elements=%d", SNvar(pn->sn), DirblobElements(db));
	
	// populate node with directory name and dirblob
	FS_LoadDirectoryOnly(&pn_directory, pn);
	LoadTK( pn_directory.sn, Directory_Marker, pn->selected_connection->index, tn );
	tn->expires = duration + NOW_TIME;
	tn->dsize = size;
	if (size) {
		memcpy(TREE_DATA(tn), db->snlist, size);
	}
	return Add_Stat(&cache_dir, Cache_Add_Common(tn));
}
Exemplo n.º 15
0
/* Note: done in single-threaded mode so locking not yet needed */
void Cache_Open(void)
{
	memset(&cache, 0, sizeof(struct cache_data));

	cache.retired_lifespan = TimeOut(fc_stable);
	if (cache.retired_lifespan > 3600) {
		cache.retired_lifespan = 3600;	/* 1 hour tops */
	}

	// Flip once (at start) to set up old tree.
	FlipTree() ;
}
bool PushButton::StateChanged() {
	bool changed = false;
	if (m_debounce.hasTimedOut()) {
		m_current = Raw();
		if (m_current != m_last) {
			changed = true;
			m_last = m_current;
			m_debounce = TimeOut(50);
		}
	}
	return changed;
}
Exemplo n.º 17
0
/* Look in caches, 0=found and valid, 1=not or uncachable in the first place */
GOOD_OR_BAD Cache_Get_Device(void *bus_nr, const struct parsedname *pn)
{
	time_t duration = TimeOut(fc_presence);
	size_t size = sizeof(int);
	struct tree_node tn;
	if (duration <= 0) {
		return gbBAD;
	}

	LEVEL_DEBUG("Looking for device "SNformat, SNvar(pn->sn));
	LoadTK( pn->sn, Device_Marker, 0, &tn ) ;
	return Get_Stat(&cache_dev, Cache_Get_Common(bus_nr, &size, &duration, &tn));
}
Exemplo n.º 18
0
//---------------------------------------------------------------------------
void MainWindow::addFile_finish()
{
    if (FilesListArea)
    {
        FilesListArea->UpdateAll();
        FilesListArea->show();
    }
    if (Files.size()>1)
        ui->actionFilesList->trigger();
    else
        ui->actionGraphsLayout->trigger();

    TimeOut();
}
Exemplo n.º 19
0
/* Look in caches, 0=found and valid, 1=not or uncachable in the first place */
GOOD_OR_BAD Cache_Get_Dir(struct dirblob *db, const struct parsedname *pn)
{
	time_t duration = TimeOut(fc_directory);
	struct tree_node tn;
	struct parsedname pn_directory;
	DirblobInit(db);
	if (duration <= 0) {
		return gbBAD;
	}

	LEVEL_DEBUG("Looking for directory "SNformat, SNvar(pn->sn));
	FS_LoadDirectoryOnly(&pn_directory, pn);
	LoadTK( pn_directory.sn, Directory_Marker, pn->selected_connection->index, &tn) ;
	return Get_Stat(&cache_dir, Cache_Get_Common_Dir(db, &duration, &tn));
}
Exemplo n.º 20
0
//---------------------------------------------------------------------------
void MainWindow::processFile(const QString &FileName)
{
    if (FileName.isEmpty())
        return;

    // Files (must be deleted first in order to stop ffmpeg processes)
    for (size_t Pos=0; Pos<Files.size(); Pos++)
        delete Files[Pos];
    Files.clear();
    ui->fileNamesBox->clear();

    // Layout
    if (FilesListArea)
    {
        ui->verticalLayout->removeWidget(FilesListArea);
        delete FilesListArea; FilesListArea=NULL;
    }
    if (PlotsArea)
    {
        ui->verticalLayout->removeWidget(PlotsArea);
        delete PlotsArea; PlotsArea=NULL;
    }
    if (TinyDisplayArea)
    {
        ui->verticalLayout->removeWidget(TinyDisplayArea);
        delete TinyDisplayArea; TinyDisplayArea=NULL;
    }
    if (ControlArea)
    {
        ui->verticalLayout->removeWidget(ControlArea);
        delete ControlArea; ControlArea=NULL;
    }
    if (InfoArea)
    {
        ui->verticalLayout->removeWidget(InfoArea);
        delete InfoArea; InfoArea=NULL;
    }

    // Status
    statusBar()->showMessage("Scanning "+QFileInfo(FileName).fileName()+"...");

    // Launch analysis
    Files.push_back(new FileInformation(this, FileName, Prefs->ActiveFilters, Prefs->ActiveAllTracks));
    Files_CurrentPos=0;
    ui->fileNamesBox->addItem(FileName);

    TimeOut();
}
Exemplo n.º 21
0
struct RxReturn RxPacket(void)
{
	struct RxReturn respuesta;
	byte bCount, bLength, bChecksum;
	byte Rx_time_out = 0;
	Sentit_Dades_Rx();
	init_A1_timer();
	for(bCount = 0; bCount < 4; bCount++)
	{
		Reset_Timeout();
		Byte_Recibido=false; //No_se_ha_recibido_Byte();
		while (!Byte_Recibido)
		{
			Rx_time_out=TimeOut(5000); // tiempo en decenas de microsegundos
			if (Rx_time_out)break;
		}
		if (Rx_time_out)break; //sale del for si ha habido Timeout
		respuesta.StatusPacket[bCount] = DatoLeido_UART;
	}
	bLength = bCount;
	bChecksum=0;
	if (!Rx_time_out)
	{
		if(bLength>3)			//podem fer checking
		{
			if(respuesta.StatusPacket[0]!=0xff || respuesta.StatusPacket[0]!=0xff)
			{
				//WRONG HEADER
				//netejar buffer
			}
			if(respuesta.StatusPacket[3]!=bLength-4)
			{
				//WRONG LENGTH
				//NETEJAR BUFFER
			}
			for(bCount = 2; bCount<bLength; bCount++) bChecksum += respuesta.StatusPacket[bCount];
			if(bChecksum!=0xff)
			{
				//WRONG CHECKSUM
				//NETEJAR BUFFER
			}
		}
	}
	return respuesta;


}
Exemplo n.º 22
0
/* Test for a simultaneous property
 * return true if simultaneous is the prefered method
 * bad if no simultaneous, or it's not the best
*/
static GOOD_OR_BAD Cache_Get_Simultaneous(enum simul_type type, struct one_wire_query *owq)
{
	struct tree_node tn;
	time_t duration ;
	time_t time_left ;
	time_t dwell_time_simul ;
	struct parsedname * pn = PN(owq) ;
	size_t dsize = sizeof(union value_object) ;
	
	duration = TimeOut(pn->selected_filetype->change);
	if (duration <= 0) {
		// probably "uncached" requested
		return gbBAD;
	}
	
	LoadTK( pn->sn, pn->selected_filetype, pn->extension, &tn ) ;
	
	if ( Get_Stat(&cache_ext, Cache_Get_Common( &OWQ_val(owq), &dsize, &time_left, &tn)) == 0 ) {
		// valid cached primary data -- see if a simultaneous conversion should be used instead
		time_t dwell_time_data = duration - time_left ;
		
		if ( BAD( Cache_Get_Simul_Time( type, &dwell_time_simul, pn)) ) {
			// Simul not found or timed out
			LEVEL_DEBUG("Simultaneous conversion not found.") ;
			OWQ_SIMUL_CLR(owq) ;
			return gbGOOD ;
		}
		if ( dwell_time_simul < dwell_time_data ) {
			LEVEL_DEBUG("Simultaneous conversion is newer than previous reading.") ;
			OWQ_SIMUL_SET(owq) ;
			return gbBAD ; // Simul is newer
		}
		// Cached data is newer, so use it
		OWQ_SIMUL_CLR(owq) ;
		return gbGOOD ;
	}
	// fall through -- no cached primary data
	if ( BAD( Cache_Get_Simul_Time( type, &dwell_time_simul, pn)) ) {
		// no simultaneous either
		OWQ_SIMUL_CLR(owq) ;
		return gbBAD ;
	}
	OWQ_SIMUL_SET(owq) ;
	return gbBAD ; // Simul is newer
}
Exemplo n.º 23
0
//---------------------------------------------------------------------------
void Control::TimeOut_Init()
{
    stop();

    Time = QTime();

    startFrame = FileInfoData->Frames_Pos_Get();
    startFrameTimeStamp = QTime::currentTime();
    lastRenderedFrame = -1;

    auto averageFrameRate = FileInfoData->averageFrameRate();
    averageFrameDuration = averageFrameRate != 0.0 ? 1000.0 / averageFrameRate : 0.0;

    if (!Timer)
    {
        Thread = new QThread(this);
        connect(Thread, SIGNAL(finished()), Thread, SLOT(deleteLater()));

        Timer = new QTimer();
        connect(Thread, SIGNAL(started()), Timer, SLOT(start()));
        connect(Thread, SIGNAL(finished()), Timer, SLOT(stop()));
        connect(Thread, SIGNAL(finished()), Timer, SLOT(deleteLater()));

        connect(Timer, SIGNAL(timeout()), this, SLOT(TimeOut()), Qt::DirectConnection);

        if (playAllFrames)
        {
            if(SelectedSpeed == Speed_P0 || SelectedSpeed == Speed_M0)
                Timer_Duration = ceil(averageFrameRate * 2);
            else if(SelectedSpeed == Speed_P1 || SelectedSpeed == Speed_M1)
                Timer_Duration = ceil(averageFrameRate);
            else if(SelectedSpeed == Speed_P2 || SelectedSpeed == Speed_M2)
                Timer_Duration = ceil(averageFrameRate / 2);

            Timer->setInterval(Timer_Duration);
        } else
        {
            Timer->setInterval(averageFrameDuration / 3);
        }

        Timer->moveToThread(Thread);
        Thread->start();
    }
}
Exemplo n.º 24
0
/*
	功能:接收数据
	参数:
		lpBuf		void*		[Out]	保存接收的数据
		nBufLen		__int32		[Out]	收到数据的长度
		lSecond		long		[In]	超时时间秒
		lMinSecond	long		[In]	超时时间毫秒
	返回值:实际接收到的字节数,超时返回-2,断开连接返回-1,其它错误返回-3
*/
int Socket::Receive( void* lpBuf, int nBufLen, bool bCheckDataLength, long lSecond, long lMinSecond )
{
	if ( TimeOut( lSecond, lMinSecond ) ) return seTimeOut;//超时
	int nResult;
	int nFlag = 0;
	if ( bCheckDataLength ) nFlag = MSG_PEEK;
	nResult = recv(m_hSocket, (char*)lpBuf, nBufLen, nFlag);
	if ( 0 == nResult ) return seSocketClose;//断开连接
	if ( SOCKET_ERROR != nResult ) return nResult;//无异常发生
	
	//socket发生异常
#ifdef WIN32
		int nError = GetLastError();
		if ( WSAEWOULDBLOCK == nError ) return 0;//非阻塞recv返回,无数据可接收
		return seError;
#else
		if ( EAGAIN == errno ) return 0;//非阻塞recv返回,无数据可接收
		return seError;
#endif
}
Exemplo n.º 25
0
//---------------------------------------------------------------------------
void MainWindow::closeFile()
{
    if (Files_CurrentPos==(size_t)-1)
        return;
    if (Files.size()==1)
    {
        closeAllFiles();
        return;
    }

    // Launch analysis
    Files.erase(Files.begin()+Files_CurrentPos);
    ui->fileNamesBox->removeItem(Files_CurrentPos);
    if (ui->fileNamesBox->isVisible())
        ui->fileNamesBox->setCurrentIndex(Files_CurrentPos<Files.size()?Files_CurrentPos:Files_CurrentPos-1);
    else
        Files_CurrentPos=Files_CurrentPos<Files.size()?Files_CurrentPos:Files_CurrentPos-1;

    TimeOut();
}
Exemplo n.º 26
0
/* return 0 if good, 1 if not */
GOOD_OR_BAD Cache_Add_Simul(const enum simul_type type, const struct parsedname *pn)
{
	// Note: pn already points to directory
	time_t duration = TimeOut(fc_volatile);
	struct tree_node *tn;

	if (pn==NO_PARSEDNAME || pn->selected_connection==NO_CONNECTION) {
		return gbGOOD;				// do check here to avoid needless processing
	}
	
	switch ( get_busmode(pn->selected_connection) ) {
		case bus_fake:
		case bus_tester:
		case bus_mock:
		case bus_bad:
		case bus_unknown:
			return gbGOOD ;
		default:
			break ;
	}
	
	if (duration <= 0) {
		return gbGOOD;				/* in case timeout set to 0 */
	}
	
	// allocate space for the node and data
	LEVEL_DEBUG("Adding for conversion time for "SNformat, SNvar(pn->sn));
	tn = (struct tree_node *) owmalloc(sizeof(struct tree_node));
	if (!tn) {
		return gbBAD;
	}
	
	LEVEL_DEBUG(SNformat, SNvar(pn->sn));
	
	// populate node with directory name and dirblob
	LoadTK( pn->sn, Simul_Marker[type], pn->selected_connection->index, tn) ;
	LEVEL_DEBUG("Simultaneous add type=%d",type);
	tn->expires = duration + NOW_TIME;
	tn->dsize = 0;
	return Add_Stat(&cache_dir, Cache_Add_Common(tn));
}
Exemplo n.º 27
0
bool FMessageRpcClient::HandleTicker(float DeltaTime)
{
	const FDateTime UtcNow = FDateTime::UtcNow();

	for (TMap<FGuid, TSharedPtr<IMessageRpcCall>>::TIterator It(Calls); It; ++It)
	{
		auto Call = It.Value();
		
		if (UtcNow - Call->GetTimeCreated() > FTimespan::FromSeconds(MESSAGE_RPC_RETRY_TIMEOUT))
		{
			It.RemoveCurrent();
			Call->TimeOut();
		}
		else if (UtcNow - Call->GetLastUpdated() > FTimespan::FromSeconds(MESSAGE_RPC_RETRY_INTERVAL))
		{
			SendCall(Call);
		}
	}

	return true;
}
Exemplo n.º 28
0
/* return 0 if good, 1 if not */
static GOOD_OR_BAD Cache_Add(const void *data, const size_t datasize, const struct parsedname *pn)
{
	struct tree_node *tn;
	time_t duration;
	int persistent ;

	if (!pn || IsAlarmDir(pn)) {
		return gbGOOD;				// do check here to avoid needless processing
	}

	// Special handling of Mock
	persistent = IsThisPersistent(pn) ;
	if ( persistent ) {
		duration = 1 ;
	} else {
		duration = TimeOut(pn->selected_filetype->change);
		if (duration <= 0) {
			return gbGOOD;				/* in case timeout set to 0 */
		}
	}

	// allocate space for the node and data
	tn = (struct tree_node *) owmalloc(sizeof(struct tree_node) + datasize);
	if (!tn) {
		return gbBAD;
	}

	LEVEL_DEBUG(SNformat " size=%d", SNvar(pn->sn), (int) datasize);

	// populate the node structure with data
	LoadTK( pn->sn, pn->selected_filetype, pn->extension, tn );
	tn->expires = duration + NOW_TIME;
	tn->dsize = datasize;
	if (datasize) {
		memcpy(TREE_DATA(tn), data, datasize);
	}
	return persistent ?
		Add_Stat(&cache_pst, Cache_Add_Persistent(tn)) :
		Add_Stat(&cache_ext, Cache_Add_Common(tn)) ;
}
Exemplo n.º 29
0
//---------------------------------------------------------------------------
void MainWindow::on_actionGraphsLayout_triggered()
{
    if (ui->actionGoTo)
        ui->actionGoTo->setVisible(true);
    if (ui->actionExport_XmlGz_Prompt)
        ui->actionExport_XmlGz_Prompt->setVisible(true);
    if (ui->actionExport_XmlGz_Sidecar)
        ui->actionExport_XmlGz_Sidecar->setVisible(true);
    //if (ui->actionExport_XmlGz_Custom) // Not implemented action
    //    ui->actionExport_XmlGz_Custom->setVisible(true);
    if (ui->actionCSV)
        ui->actionCSV->setVisible(true);
    //if (ui->actionPrint)
    //    ui->actionPrint->setVisible(true);
    if (ui->actionZoomIn)
        ui->actionZoomIn->setVisible(true);
    if (ui->actionZoomOut)
        ui->actionZoomOut->setVisible(true);
    if (ui->actionWindowOut)
        ui->actionWindowOut->setVisible(false);
    for (size_t Pos=0; Pos<PlotType_Max; Pos++)
        if (CheckBoxes[Pos])
            CheckBoxes[Pos]->show();
    if (ui->fileNamesBox)
        ui->fileNamesBox->show();
    if (PlotsArea)
        PlotsArea->show();
    if (TinyDisplayArea)
        TinyDisplayArea->show();
    if (ControlArea)
        ControlArea->show();
    if (FilesListArea)
        FilesListArea->hide();

    if (ui->fileNamesBox)
        ui->fileNamesBox->setCurrentIndex(Files_CurrentPos);

    TimeOut();
}
Exemplo n.º 30
0
/*
	功能:调用库函数recvFrom接收UDP数据
	参数:
		lpBuf		void*		[Out]	保存接收的数据
		nBufLen		int			[Out]	收到数据的长度
		strFromIP	string&		[Out]	发送方IP
		nFromPort	int&		[Out]	发送方端口
		lSecond		long		[In]	超时时间秒
		lMinSecond	long		[In]	超时时间毫秒
		返回值:实际接收到的字节数,超时返回0
*/
int Socket::ReceiveFrom( char* lpBuf, int nBufLen, string &strFromIP, int &nFromPort, bool bCheckDataLength, long lSecond, long lMinSecond )
{
	strFromIP = "";
	nFromPort = -1;
	if ( 0 >= nBufLen ) return 0;
	sockaddr_in sockAddr;
	socklen_t nAddrLen = sizeof(sockaddr);
	/* waiting for receive data */
	int nResult;
	int nFlag = 0;
	while ( true )
	{
		if ( TimeOut( lSecond, lMinSecond ) ) return seTimeOut;
		if ( bCheckDataLength )nFlag = MSG_PEEK;
		nResult = recvfrom(m_hSocket, lpBuf, nBufLen, nFlag, (sockaddr*)&sockAddr, &nAddrLen);
		if ( nAddrLen > 0 ) GetAddress(sockAddr, strFromIP, nFromPort);
		if ( SOCKET_ERROR == nResult ) //socket发生异常
		{
#ifndef WIN32
			if ( EAGAIN == errno ) return 0;//非阻塞recv返回,无数据可接收
			return seError;
#else
			int nError = GetLastError();
			if ( 0 == nError )//之前存在失败的udp发送
			{
				if ( MSG_PEEK == nFlag )//没有删除接收缓冲,从接收缓冲将消息删除
				{
					recvfrom(m_hSocket, lpBuf, nBufLen, 0, (sockaddr*)&sockAddr, &nAddrLen);
				}
				continue;
			}
			if ( WSAEWOULDBLOCK == nError ) return 0;//非阻塞recv返回,无数据可接收
			return seError;
#endif
		}		
		break;
	}
	return nResult;
}