Пример #1
0
void SslTcpClient::OnTimeout()
{
	OSMutexLocker locker(&fMutexList);
	SetTimeout(kTimeKeepAlive*1000);
	SetConnectStatus(kOffline);
	if(fTcpSocket != NULL)
	{
		delete fTcpSocket;
	}
	fTcpSocket = new SslTcpClientSocket(Socket::kNonBlockingSocketType);
	SetClientSocket(fTcpSocket);
}
Пример #2
0
WaitForEvent::WaitForEvent(int Timeout)
	: mKQueue(::kqueue()),
	  mpTimeout(0)
{
	if(mKQueue == -1)
	{
		THROW_EXCEPTION(CommonException, CouldNotCreateKQueue)
	}

	// Set the choosen timeout
	SetTimeout(Timeout);
}
Пример #3
0
void CGenomicCollectionsService::x_Connect()
{
#ifdef _DEBUG
    LOG_POST(Info << "Connecting to url:" << x_GetURL().c_str());
#endif
    STimeout to5Min;
    to5Min.sec=600;
    to5Min.usec=0;
    SetTimeout(&to5Min);

    x_ConnectURL(x_GetURL());
}
Пример #4
0
void C4StartupNetListEntry::SetError(const char *szErrorText, TimeoutType eTimeout)
{
	// set error message
	fError = true;
	sInfoText[1].Copy(szErrorText);
	for (int i=2; i<InfoLabelCount; ++i) sInfoText[i].Clear();
	InvalidateStatusIcons();
	UpdateSmallState(); UpdateText();
	pIcon->SetIcon(C4GUI::Ico_Close);
	pIcon->SetAnimated(false, 0);
	pIcon->SetBounds(rctIconSmall);
	SetTimeout(eTimeout);
}
Пример #5
0
/*----------------------------------------------------------------------
|   PLT_EventSubscriber::PLT_EventSubscriber
+---------------------------------------------------------------------*/
PLT_EventSubscriber::PLT_EventSubscriber(PLT_TaskManager* task_manager, 
                                         PLT_Service*     service,
                                         const char*      sid,
                                         NPT_Timeout      timeout_secs /* = -1 */) : 
    m_TaskManager(task_manager), 
    m_Service(service), 
    m_EventKey(0),
    m_SubscriberTask(NULL),
    m_SID(sid)
{
    NPT_LOG_FINE_1("Creating new subscriber (%s)", m_SID.GetChars());
    SetTimeout(timeout_secs);
}
Пример #6
0
	inline
	void DtlsTransport::onTimer(Timer* timer)
	{
		MS_TRACE();

		DTLSv1_handle_timeout(this->ssl);

		// If required, send DTLS data.
		SendPendingOutgoingDtlsData();

		// Set the DTLS timer again.
		SetTimeout();
	}
// -----------------------------------------------------------------------------
// CTFTestCaseRepeater::CTFTestCaseRepeater
// -----------------------------------------------------------------------------
EXPORT_C CTFTestCaseRepeater::CTFTestCaseRepeater( TInt aId, const TDesC& aName, CTFATestSuite* aSuite, TInt aRepeatCount, TBool aRandomRepeat )
: CTFATestCase( aId, aName )
, iSuite( aSuite )
, iRepeatCount( aRepeatCount )
, iRandomRepeat( aRandomRepeat )
    {
    if ( aSuite != NULL )
        {
        if ( iRandomRepeat )
            {
            SetTimeout( aRepeatCount * aSuite->Count() * KTFDefaultTimeout );
            }
        else
            {
            SetTimeout( aRepeatCount * aSuite->Count() * KTFLoopCount * KTFDefaultTimeout );
            }
        }
    else
        {
        TRACE_ASSERT_ALWAYS;
        }
    }
//错误0:检查不到wifi芯片  错误1:建立服务器失败
u8 esp8266::ConnectNetwork_server(short port)//作为服务器
{
	if(!kick() )
		return 0; //检查不到wifi芯片
	SetMode(2);
	restart();
	tskmgr.DelayS(3);
	SetMUX(false);
	if(!CreateServerMode(port))
		return 1;
	SetTimeout(0);
	return 0xff;
}
AutonomousMove::AutonomousMove(float velocity, float time) {
	// Use requires() here to declare subsystem dependencies
	// eg. requires(chassis);
	// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
	Requires(Robot::driveTrain);

    // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
	m_velocity = velocity;
	m_time = time;
	m_distance = 0;
	SetTimeout(time);
	isDistanceMove = false;
}
Пример #10
0
	void DtlsTransport::Run(Role localRole)
	{
		MS_TRACE();

		MS_ASSERT(localRole == Role::CLIENT || localRole == Role::SERVER, "local DTLS role must be 'client' or 'server'");

		Role previousLocalRole = this->localRole;

		if (localRole == previousLocalRole)
		{
			MS_ERROR("same local DTLS role provided, doing nothing");

			return;
		}

		// If the previous local DTLS role was 'client' or 'server' do reset.
		if (previousLocalRole == Role::CLIENT || previousLocalRole == Role::SERVER)
		{
			MS_DEBUG("resetting DTLS due to local role change");

			Reset();
		}

		// Update local role.
		this->localRole = localRole;

		// Set state and notify the listener.
		this->state = DtlsState::CONNECTING;
		this->listener->onDtlsConnecting(this);

		switch (this->localRole)
		{
			case Role::CLIENT:
				MS_DEBUG("running [role:client]");

				SSL_set_connect_state(this->ssl);
				SSL_do_handshake(this->ssl);
				SendPendingOutgoingDtlsData();
				SetTimeout();
				break;
			case Role::SERVER:
				MS_DEBUG("running [role:server]");

				SSL_set_accept_state(this->ssl);
				SSL_do_handshake(this->ssl);
				break;
			default:
				MS_ABORT("invalid local DTLS role");
				break;
		}
	}
Пример #11
0
 void CTcpHandler::TcpAdd(CCommand *pCmd)
 {
     CTcpAddCommand *pConnectCmd = dynamic_cast<CTcpAddCommand *>(pCmd);
     CEventThread *pThread = dynamic_cast<CEventThread *>(GetThread()); 
     m_pBufevt = bufferevent_socket_new(pThread->GetEventBase(), 
             pConnectCmd->m_iFd, BEV_OPT_THREADSAFE);
     bufferevent_setcb(m_pBufevt, CNetThread::OnStaticRead, CNetThread::OnStaticWrite, CNetThread::OnStaticError, this);
     bufferevent_enable(m_pBufevt, EV_READ|EV_PERSIST|EV_ET);		
     bufferevent_setwatermark(m_pBufevt, EV_READ, 
                               OnRead(NULL, 0), 0);
     OnConnect();
     //告诉listen线程
     SetTimeout();
 }
Пример #12
0
/*!	A menu item that draws an icon alongside the label.

	It's currently used in the mount and new file template menus.
*/
IconMenuItem::IconMenuItem(const char* label, BMessage* message, BBitmap* icon,
                           icon_size which)
    :
    PositionPassingMenuItem(label, message),
    fDeviceIcon(NULL),
    fHeightDelta(0),
    fWhich(which)
{
    SetIcon(icon);

    // IconMenuItem is used in synchronously invoked menus, make sure
    // we invoke with a timeout
    SetTimeout(kSynchMenuInvokeTimeout);
}
Пример #13
0
CIncomingConnection::CIncomingConnection(const CString& sHostname,
                                         unsigned short uPort,
                                         CListener::EAcceptType eAcceptType,
                                         const CString& sURIPrefix)
    : CZNCSock(sHostname, uPort),
      m_eAcceptType(eAcceptType),
      m_sURIPrefix(sURIPrefix) {
    // The socket will time out in 120 secs, no matter what.
    // This has to be fixed up later, if desired.
    SetTimeout(120, 0);

    SetEncoding("UTF-8");
    EnableReadLine();
}
Пример #14
0
 void OnTimeout() {
   SetTimeout(5);
   if (!m_state)
   {
     m_state = 1;
   }
   else
   {
     ConnectorSocket *s = new ConnectorSocket(Handler());
     s -> Open(gHost, gPort);
     s -> SetDeleteByHandler();
     Handler().Add(s);
   }
 }
Пример #15
0
// Called just before this Command runs the first time
void Autonomous_Simple::Initialize() {
	printf("Autonomous_Simple Initialize Start\n");
	Robot::driveTrain->Set_VoltageMode();
	Robot::driveTrain->Zero_DriveEncoders();
	first = false;
	hasMoved = false;
	SetTimeout(TimeOut);
	targetpulses = dist * Robot::driveTrain->Get_PulsesPerInch();
	startingPoint = Robot::driveTrain->Get_CurrentPosition();

	printf("Autonomous_Simple TimeOut = %f MaxThrottle = %f Throttle_Ramp = %f dist = %f\n",TimeOut,MaxThrottle, Throttle_Ramp,dist);
	printf("Autonomous_Simple targetpulses = %f startingPoint = %f\n",targetpulses,startingPoint);
	printf("Autonomous_Simple Initialize Complete\n");
}
Пример #16
0
void
AnimationAttributes::SetFromNode(DataNode *parentNode)
{
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("AnimationAttributes");
    if(searchNode == 0)
        return;

    DataNode *node;
    if((node = searchNode->GetNode("animationMode")) != 0)
    {
        // Allow enums to be int or string in the config file
        if(node->GetNodeType() == INT_NODE)
        {
            int ival = node->AsInt();
            if(ival >= 0 && ival < 3)
                SetAnimationMode(AnimationMode(ival));
        }
        else if(node->GetNodeType() == STRING_NODE)
        {
            AnimationMode value;
            if(AnimationMode_FromString(node->AsString(), value))
                SetAnimationMode(value);
        }
    }
    if((node = searchNode->GetNode("pipelineCachingMode")) != 0)
        SetPipelineCachingMode(node->AsBool());
    if((node = searchNode->GetNode("frameIncrement")) != 0)
        SetFrameIncrement(node->AsInt());
    if((node = searchNode->GetNode("timeout")) != 0)
        SetTimeout(node->AsInt());
    if((node = searchNode->GetNode("playbackMode")) != 0)
    {
        // Allow enums to be int or string in the config file
        if(node->GetNodeType() == INT_NODE)
        {
            int ival = node->AsInt();
            if(ival >= 0 && ival < 3)
                SetPlaybackMode(PlaybackMode(ival));
        }
        else if(node->GetNodeType() == STRING_NODE)
        {
            PlaybackMode value;
            if(PlaybackMode_FromString(node->AsString(), value))
                SetPlaybackMode(value);
        }
    }
}
Пример #17
0
ModelMenuItem::ModelMenuItem(const Model* model, BMenu* menu, bool drawText,
	bool extraPad)
	:
	BMenuItem(menu),
	fModel(*model),
	fHeightDelta(0),
	fDrawText(drawText),
	fExtraPad(extraPad)
{
	ThrowOnInitCheckError(&fModel);
	// ModelMenuItem is used in synchronously invoked menus, make sure
	// we invoke with a timeout
	SetTimeout(kSynchMenuInvokeTimeout);
}
Пример #18
0
BOOLEAN NTTIMER::Satisfy( void )
{
	// FIXME: user correct time values
	if (ApcRoutine)
		Thread->QueueApcThread( ApcRoutine, ApcContext, 0, 0 );

	// restart the timer
	if (Interval)
	{
		LARGE_INTEGER when;
		when.QuadPart = Interval * -10000LL;
		SetTimeout( &when );
	}
	return TRUE;
}
Пример #19
0
VBool VSocket::SetRecvTimeout(VCard32 msecs)
{
#if 1
    return SetTimeout (msecs);
#else
	if (LOBYTE(winsockVersion) < 2)
		return VFalse;
	int timeout=msecs;
	if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)) == SOCKET_ERROR)
	{
		return VFalse;
	}
	return VTrue;
#endif
}
Пример #20
0
void CItem::Spawn_OnTick( bool fExec )
{
	int iMinutes;
	if ( m_itSpawnChar.m_TimeHiMin <= 0 )
	{
		iMinutes = Calc_GetRandVal(30) + 1;
	}
	else
	{
		iMinutes = min( m_itSpawnChar.m_TimeHiMin, m_itSpawnChar.m_TimeLoMin ) + Calc_GetRandVal( abs( m_itSpawnChar.m_TimeHiMin - m_itSpawnChar.m_TimeLoMin ));
	}

	if ( iMinutes <= 0 )
		iMinutes = 1;

	if ( !fExec || IsTimerExpired() )
	{
		SetTimeout( iMinutes * 60 * TICK_PER_SEC );	// set time to check again.
	}

	if ( ! fExec )
		return;

	CResourceDef * pDef = Spawn_FixDef();
	if ( pDef == NULL )
	{
		RESOURCE_ID_BASE rid;
		if ( IsType(IT_SPAWN_ITEM))
		{
			rid = m_itSpawnItem.m_ItemID;
		}
		else
		{
			rid = m_itSpawnChar.m_CharID;
		}
		DEBUG_ERR(( "Bad Spawn point uid=0%lx, id=%s\n", (DWORD) GetUID(), g_Cfg.ResourceGetName(rid) ));
		return;
	}

	if ( IsType(IT_SPAWN_ITEM))
	{
		Spawn_GenerateItem(pDef);
	}
	else
	{
		Spawn_GenerateChar(pDef);
	}
}
Пример #21
0
	void DtlsTransport::ProcessDtlsData(const uint8_t* data, size_t len)
	{
		MS_TRACE();

		int written;
		int read;

		if (!IsRunning())
		{
			MS_ERROR("cannot process data while not running");

			return;
		}

		// Write the received DTLS data into the sslBioFromNetwork.
		written = BIO_write(this->sslBioFromNetwork, (const void*)data, (int)len);
		if (written != (int)len)
			MS_WARN("OpenSSL BIO_write() wrote less (%zu bytes) than given data (%zu bytes)", (size_t)written, len);

		// Must call SSL_read() to process received DTLS data.
		read = SSL_read(this->ssl, (void*)DtlsTransport::sslReadBuffer, MS_SSL_READ_BUFFER_SIZE);

		// Send data if it's ready.
		SendPendingOutgoingDtlsData();

		// Check SSL status and return if it is bad/closed.
		if (!CheckStatus(read))
			return;

		// Set/update the DTLS timeout.
		if (!SetTimeout())
			return;

		// Application data received. Notify to the listener.
		if (read > 0)
		{
			// It is allowed to receive DTLS data even before validating remote fingerprint.
			if (!this->handshakeDone)
			{
				MS_DEBUG("ignoring application data received while DTLS handshake not done");

				return;
			}

			// Notify the listener.
			this->listener->onDtlsApplicationData(this, (uint8_t*)DtlsTransport::sslReadBuffer, (size_t)read);
		}
	}
Пример #22
0
/* construct system_manifest object and initialize it from manifest */
void SystemManifestCtor(struct NaClApp *nap)
{
  struct SystemManifest *policy;

  /* check for design errors */
  assert(nap != NULL);
  assert(nap->system_manifest != NULL);

  policy = nap->system_manifest;
  policy->syscallback = 0;

  /* get zerovm settings from manifest */
  policy->version = GetValueByKey("Version");
  policy->nexe_etag = GetValueByKey("NexeEtag");

  /* check mandatory manifest keys */
  ZLOGFAIL(nap->system_manifest->version == NULL, EFAULT,
      "the manifest version is not provided");
  ZLOGFAIL(STRCMP(nap->system_manifest->version, MANIFEST_VERSION),
      EFAULT, "manifest version not supported");
  SetTimeout(policy);

  /* user data (environment, command line) */
  policy->envp = NULL;
  SetCustomAttributes(policy);

  /* prepare command line arguments for nexe */
  policy->cmd_line = NULL;
  policy->cmd_line_size = 0;
  SetCommandLine(policy);

  /* get node name and id */
  SetNodeName(nap);

  /* construct and initialize all channels */
  ChannelsCtor(nap);

  /*
   * allocate "whole memory chunk" if specified. should be the last allocation
   * in raw because after chunk allocated there will be no free user memory
   * note: will set "heap_ptr"
   */
  GET_INT_BY_KEY(nap->heap_end, "MemMax");
  PreallocateUserMemory(nap);

  /* zerovm return code */
  nap->system_manifest->ret_code = OK_CODE;
}
Пример #23
0
EXPORT_C TInt CAknNoteWrapper::ExecuteLD(TInt aResId, const TDesC& aPrompt)
    {
    TAknNoteResData resData = ReadResDataAndPrepareL(aResId);
    SetTextL(aPrompt);

	if (iTimeoutInMicroseconds == -1)
		{
		SetTimeout(resData.iTimeout);
		}

	if (iTone == STATIC_CAST(TTone,-1))
		{
		SetTone(resData.iTone);
		}
	return RunLD();
    }
Пример #24
0
 void InitWatchdog()
 {
     struct stat buf;
     if(stat(DogPath, &buf) != 0)
     {
         if(Exec::System("modprobe softdog") != 0)
             return;
     }
     do
     {
         sched_yield();
         Dog = open(DogPath, O_RDWR);
     } while(Dog == -1);
     SetTimeout(Timeout);
     Feed();
 }
Пример #25
0
AimShooterToTarget::AimShooterToTarget()
{
	// Use Requires() here to declare subsystem dependencies
	// eg. Requires(chassis);
	Requires(&*shooter);
	Requires(&*shooter_pitch);

	SetTimeout(TIMEOUT);

	pitch = 0.0;
	rpm = 0.0;
	current_pitch = 0.0;
	distance = 0.0;

	interrupted = false;
}
Пример #26
0
// Accept the SSTP connection
bool AcceptSstp(CONNECTION *c)
{
	SOCK *s;
	HTTP_HEADER *h;
	char date_str[MAX_SIZE];
	bool ret;
	bool ret2 = false;
	SOCK_EVENT *se;
	// Validate arguments
	if (c == NULL)
	{
		return false;
	}

	s = c->FirstSock;

	GetHttpDateStr(date_str, sizeof(date_str), SystemTime64());

	// Return a response
	h = NewHttpHeader("HTTP/1.1", "200", "OK");
	AddHttpValue(h, NewHttpValue("Content-Length", "18446744073709551615"));
	AddHttpValue(h, NewHttpValue("Server", "Microsoft-HTTPAPI/2.0"));
	AddHttpValue(h, NewHttpValue("Date", date_str));

	ret = PostHttp(s, h, NULL, 0);

	FreeHttpHeader(h);

	if (ret)
	{
		SetTimeout(s, INFINITE);

		se = NewSockEvent();

		JoinSockToSockEvent(s, se);

		Debug("ProcessSstpHttps Start.\n");
		ret2 = ProcessSstpHttps(c->Cedar, s, se);
		Debug("ProcessSstpHttps End.\n");

		ReleaseSockEvent(se);
	}

	Disconnect(s);

	return ret2;
}
Пример #27
0
void TCPSocket::Connect(const Endpoint& remoteEndpoint, const Endpoint* localEndpoint)
{
  assert(socket < 0);
  int socket = ::socket(static_cast<int>(remoteEndpoint.Family()), SOCK_STREAM, 0);
  if (socket < 0) throw NetworkSystemError(errno);

  auto socketGuard = util::MakeScopeError([&socket]() { close(socket); }); (void) socketGuard;
  
  int optVal = 1;
  setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, &optVal, sizeof(optVal));

  SetTimeout(socket);
  
  if (localEndpoint)
  {
    socklen_t addrLen = localEndpoint->Length();
    struct sockaddr_storage addrStor;
    memcpy(&addrStor, localEndpoint->Addr(), addrLen);
    struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(&addrStor);

    if (bind(socket, addr, addrLen) < 0)
    {
      int errno_ = errno;
      throw util::net::NetworkSystemError(errno_);
    }
  }
  
  while (connect(socket, remoteEndpoint.Addr(), remoteEndpoint.Length()) < 0)
  {
    boost::this_thread::interruption_point();
    if (errno != EINTR)
    {
      int errno_ = errno;
      if (errno_ == EWOULDBLOCK || errno_ == EAGAIN || errno_ == ETIMEDOUT)
        throw TimeoutError();
      else
        throw NetworkSystemError(errno_);
    }
  }
  
  boost::this_thread::interruption_point();
  PopulateRemoteEndpoint(socket);
  PopulateLocalEndpoint(socket);
  
  std::lock_guard<std::mutex> lock(socketMutex);
  this->socket = socket;
}
Пример #28
0
NetAsyncTCP::NetAsyncTCP()
{
#if defined(IOMTR_OS_WIN32) || defined(IOMTR_OS_WIN64)
	int retval;
	WSADATA wd;
#endif

	server_socket = INVALID_SOCKET;
	client_socket = INVALID_SOCKET;
#if defined(IOMTR_OSFAMILY_UNIX)
	server_fp.fd = client_fp.fd = -1;
	server_socket = (SOCKET) &server_fp;
	client_socket = (SOCKET) &client_fp;
	maxfd = sysconf(_SC_OPEN_MAX);    // the max # of file descriptors that select() handles.

#ifdef WORKAROUND_LISTEN_BUG
	listening = FALSE;
#endif

#endif // IOMTR_OSFAMILY_UNIX

	server_address.sin_family = AF_INET; // use Internet Protocol
	client_address.sin_family = AF_INET; // use Internet Protocol
	SetTimeout( 0, 0 );

#if defined(IOMTR_OS_WIN32) || defined(IOMTR_OS_WIN64)
	// Initialize WinSock if it has not yet been initialized in this process.
	if ( InterlockedIncrement ( &sockets_in_use ) == 1 )
	{
		#if NETWORK_DETAILS || _DEBUG
			cout << "Initializing WinSock." << endl;
		#endif

		// request WinSock version 2.0
		retval = WSAStartup( MAKEWORD(2, 0), &wd ); 

		if ( retval != 0 )
		{
			*errmsg << "*** Could not initialize WinSock!  Error " 
				<< retval << ends;
			OutputErrMsg();
			InterlockedDecrement ( &sockets_in_use );
		}
	}
#endif
}
Пример #29
0
int LClient::Write(const uint8_t *pBuffer, size_t size, uint32_t timeout)
{
    SetTimeout(SO_SNDTIMEO, timeout);
    if (!m_connected
            && 0 != connect(m_socket, (sockaddr*)&m_sockaddr, sizeof(m_sockaddr)))
    {
        return ERR::SOCKET_CONNECT_FAILED;
    }
    m_connected = true;

    if (-1 == send(m_socket, CONST_BUF(pBuffer), size, 0))
    {
        return ERR::SEND_DATA_FAILED;
    }

    return 0;
}
   SpamAssassinClient::SpamAssassinClient(const String &sFile,
                                          boost::asio::io_service& io_service, 
                                          boost::asio::ssl::context& context,
                                          std::shared_ptr<Event> disconnected,
                                          bool &testCompleted) :
               TCPConnection(CSNone, io_service, context, disconnected, ""),
               test_completed_(testCompleted),
               total_result_bytes_written_(0)
   {
      TimeoutCalculator calculator;
      SetTimeout(calculator.Calculate(IniFileSettings::Instance()->GetSAMinTimeout(), IniFileSettings::Instance()->GetSAMaxTimeout()));
      
      message_file_ = sFile;
	   spam_dsize_ = -1;
	   message_size_ = -1;

      test_completed_ = false;
   }