Esempio n. 1
0
void CRealControlSocket::OnSend()
{
	if (m_pSendBuffer)
	{
		if (!m_nSendBufferLen)
		{
			delete [] m_pSendBuffer;
			m_pSendBuffer = 0;
			return;
		}

		int error;
		int written = m_pBackend->Write(m_pSendBuffer, m_nSendBufferLen, error);
		if (written < 0)
		{
			if (error != EAGAIN)
			{
				LogMessage(MessageType::Error, _("Could not write to socket: %s"), CSocket::GetErrorDescription(error));
				if (GetCurrentCommandId() != Command::connect)
					LogMessage(MessageType::Error, _("Disconnected from server"));
				DoClose();
			}
			return;
		}

		if (written)
		{
			SetAlive();
			m_pEngine->SetActive(CFileZillaEngine::send);
		}

		if (written == m_nSendBufferLen)
		{
			m_nSendBufferLen = 0;
			delete [] m_pSendBuffer;
			m_pSendBuffer = 0;
		}
		else
		{
			memmove(m_pSendBuffer, m_pSendBuffer + written, m_nSendBufferLen - written);
			m_nSendBufferLen -= written;
		}
	}
}
Esempio n. 2
0
bool CRealControlSocket::Send(const char *buffer, int len)
{
	SetWait(true);
	if (m_pSendBuffer)
	{
		char *tmp = m_pSendBuffer;
		m_pSendBuffer = new char[m_nSendBufferLen + len];
		memcpy(m_pSendBuffer, tmp, m_nSendBufferLen);
		memcpy(m_pSendBuffer + m_nSendBufferLen, buffer, len);
		m_nSendBufferLen += len;
		delete [] tmp;
	}
	else
	{
		int error;
		int written = m_pBackend->Write(buffer, len, error);
		if (written < 0)
		{
			if (error != EAGAIN)
			{
				LogMessage(::Error, _("Could not write to socket: %s"), CSocket::GetErrorDescription(error).c_str());
				LogMessage(::Error, _("Disconnected from server"));
				DoClose();
				return false;
			}
			written = 0;
		}

		if (written)
			m_pEngine->SetActive(CFileZillaEngine::send);

		if (written < len)
		{
			char *tmp = m_pSendBuffer;
			m_pSendBuffer = new char[m_nSendBufferLen + len - written];
			memcpy(m_pSendBuffer, tmp, m_nSendBufferLen);
			memcpy(m_pSendBuffer + m_nSendBufferLen, buffer, len - written);
			m_nSendBufferLen += len - written;
			delete [] tmp;
		}
	}

	return true;
}
Esempio n. 3
0
void CControlSocket::OnTimer(wxTimerEvent&)
{
	int timeout = m_pEngine->GetOptions()->GetOptionVal(OPTION_TIMEOUT);
	if (!timeout)
		return;

	if (m_pCurOpData && m_pCurOpData->waitForAsyncRequest)
		return;

	if (IsWaitingForLock())
		return;

	if (m_stopWatch.Time() > (timeout * 1000))
	{
		LogMessage(MessageType::Error, _("Connection timed out"));
		DoClose(FZ_REPLY_TIMEOUT);
		wxASSERT(!m_timer.IsRunning());
	}
}
Esempio n. 4
0
bool CRealControlSocket::Send(const char *buffer, int len)
{
	SetWait(true);
	if (m_pSendBuffer)
	{
		char *tmp = m_pSendBuffer;
		m_pSendBuffer = new char[m_nSendBufferLen + len];
		memcpy(m_pSendBuffer, tmp, m_nSendBufferLen);
		memcpy(m_pSendBuffer + m_nSendBufferLen, buffer, len);
		m_nSendBufferLen += len;
		delete [] tmp;
	}
	else
	{
		m_pBackend->Write(buffer, len);
		int numsent = 0;
		if (m_pBackend->Error())
		{
			if (m_pBackend->LastError() != wxSOCKET_WOULDBLOCK)
			{
				DoClose();
				return false;
			}
		}
		else
			numsent = m_pBackend->LastCount();

		if (numsent)
			m_pEngine->SetActive(false);

		if (numsent < len)
		{
			char *tmp = m_pSendBuffer;
			m_pSendBuffer = new char[m_nSendBufferLen + len - numsent];
			memcpy(m_pSendBuffer, tmp, m_nSendBufferLen);
			memcpy(m_pSendBuffer + m_nSendBufferLen, buffer, len - numsent);
			m_nSendBufferLen += len - numsent;
			delete [] tmp;
		}
	}

	return true;
}
Esempio n. 5
0
/*
 *************************************************************************
 *  MiniportHalt
 *************************************************************************
 *
 *  Halts the network interface card.
 *
 */
VOID MiniportHalt(IN NDIS_HANDLE MiniportAdapterContext)
{
	IrDevice *thisDev = CONTEXT_TO_DEV(MiniportAdapterContext);

	DBGOUT(("MiniportHalt(0x%x)", (UINT)MiniportAdapterContext));

	/*
	 *  Remove this device from our global list
	 */

	if (thisDev == firstIrDevice){
		firstIrDevice = firstIrDevice->next;
	}
	else {
		IrDevice *dev;
		for (dev = firstIrDevice; dev && (dev->next != thisDev); dev = dev->next){ }
		if (dev){
			dev->next = dev->next->next;
		}
		else {
			/*
			 *  Don't omit this error check.  I've seen NDIS call MiniportHalt with
			 *  a bogus context when the system gets corrupted.
			 */
			DBGERR(("Bad context in MiniportHalt"));
			return;
		}
	}


	/*
	 *  Now destroy the device object.
	 */
	DoClose(thisDev);

	NdisMDeregisterIoPortRange(	thisDev->ndisAdapterHandle,
								thisDev->portInfo.ioBase,
								8,
								(PVOID)thisDev->mappedPortRange);
	FreeDevice(thisDev);


}
NS_IMETHODIMP
npAPInsIInputStreamShim::CopyFromPluginHostToBuffer(int32 len, void* buf, 
                                                    int32 * outWritten)
{
    nsresult rv = NS_ERROR_NULL_POINTER;
    if (nsnull == outWritten) {
        return rv;
    }

    if (mDoClose) {
        DoClose();
        return NS_ERROR_NOT_AVAILABLE;
    }

    rv = EnsureBuffer(len);
    if (NS_FAILED(rv)) {
        return rv;
    }
    
    mNumWrittenFromPluginHost = len;
    *outWritten = mNumWrittenFromPluginHost;
    if (0 < mNumWrittenFromPluginHost) {
        // copy the bytes the from the plugin host into our buffer
        memcpy(((char *) mBuffer) + mCountFromPluginHost, buf, 
               (size_t) mNumWrittenFromPluginHost);

        mCountFromPluginHost += mNumWrittenFromPluginHost;
        mAvailableForPluglet = mCountFromPluginHost - mCountFromPluglet;
    }

    // if we have bytes available for the pluglet, and they have
    // requested a callback when bytes are available.
    if (mCallback && 0 < mAvailableForPluglet
        && !(mCallbackFlags & WAIT_CLOSURE_ONLY)) {
        rv = mCallback->OnInputStreamReady(this);
        mCallback = nsnull;
        mCallbackFlags = nsnull;
    }

    rv = NS_OK;
    
    return rv;
}
Esempio n. 7
0
int TcpClient::HandleClose()
{
    if (m_state == kConnecting)
    {
        int err = GetSocketError();
        if (err)
        {
            LOG_ERROR("Connector::HandleClose fd:%d - SO_ERROR %d %s", m_iFD, err, strerror(err));
        }
    }
    
    if (m_state != kDisconnected)
    {
        DoClose();
    }
    // 清理所有的缓存buf,如果要保证容灾可信通讯,需上层自己实现
    m_SendBuf.Retrieve(m_SendBuf.ReadableBytes());
    m_RecvBuf.Retrieve(m_RecvBuf.ReadableBytes());
    return 0;
}
Esempio n. 8
0
bool CTcpSocket::DoRecv()
{
	char *pRecvBuffer = m_szRecvBuffer + m_wHaveRecvLength;
	USHORT wFreeRecvLength = MAX_RECV_BUFFER_LENGTH - m_wHaveRecvLength;

	if (0 == wFreeRecvLength)
	{
		LOGError("单个消息包过长,断开连接。");

		// 单个消息包过长,断开连接
		DoClose();
		
		return false;
	}

	m_pSock->async_read_some(buffer(pRecvBuffer, wFreeRecvLength), 
		bind(&CTcpSocket::OnRecv, this, placeholders::error, placeholders::bytes_transferred));

	return true;
}
void CSSLClientAsync::_Close()
{
    if (m_ssl)
    {
        UnInitSSL();
    }
    if (GetSocket() != S_INVALID_SOCKET)
    {
        if (m_pio)
        {
            m_pio->Remove_Handler(this);
        }
        SetSSLConnectStatus(FALSE);
        S_CloseSocket(GetSocket());
        SOCKET_IO_WARN("close ssl socket, sock %d, real sock: %d.", GetSocketID(), GetSocket());
        m_socket = S_INVALID_SOCKET;
        DoClose(GetSocketID());
        _ClearSendBuffer();
    }
}
Esempio n. 10
0
void CRealControlSocket::OnSend()
{
	if (m_pSendBuffer)
	{
		if (!m_nSendBufferLen)
		{
			delete [] m_pSendBuffer;
			m_pSendBuffer = 0;
			return;
		}

		m_pBackend->Write(m_pSendBuffer, m_nSendBufferLen);
		if (m_pBackend->Error())
		{
			if (m_pBackend->LastError() != wxSOCKET_WOULDBLOCK)
				DoClose();
			return;
		}

		int numsent = m_pBackend->LastCount();

		if (numsent)
		{
			SetAlive();
			m_pEngine->SetActive(false);
		}

		if (numsent == m_nSendBufferLen)
		{
			m_nSendBufferLen = 0;
			delete [] m_pSendBuffer;
			m_pSendBuffer = 0;
		}
		else
		{
			memmove(m_pSendBuffer, m_pSendBuffer + numsent, m_nSendBufferLen - numsent);
			m_nSendBufferLen -= numsent;
		}
	}
}
Esempio n. 11
0
void CTcpSocket::OnRecv( const system::error_code& ec, size_t nByteTransferred )
{
	if (ec)
	{
		LOGError(ec.message().c_str());

		DoClose();
		return ;
	}

	m_wHaveRecvLength += nByteTransferred;

	// 黏包解析
	USHORT wReadLength = 0;	//解析长度修改都是完整消息包

	while (true)
	{
		const char *pPacketHead = m_szRecvBuffer + wReadLength;
		USHORT wRemainLength = m_wHaveRecvLength - wReadLength;

		USHORT wReadPacketLength = ReadPacket(pPacketHead, wRemainLength);
		if (wReadPacketLength > 0)
		{
			wReadLength += wReadPacketLength;
		}
		else
		{
			if ((wRemainLength > 0) 
				&& (wRemainLength != m_wHaveRecvLength))
			{
				memcpy(m_szRecvBuffer, m_szRecvBuffer+wReadLength, wRemainLength);
			}
			
			m_wHaveRecvLength = wRemainLength;
			break;
		}
	}

	DoRecv();
}
Esempio n. 12
0
void CControlSocket::OnTimer(fz::timer_id)
{
	m_timer = 0; // It's a one-shot timer, no need to stop it

	int const timeout = engine_.GetOptions().GetOptionVal(OPTION_TIMEOUT);
	if (timeout > 0) {
		fz::duration elapsed = fz::monotonic_clock::now() - m_lastActivity;

		if ((!m_pCurOpData || !m_pCurOpData->waitForAsyncRequest) && !IsWaitingForLock()) {
			if (elapsed > fz::duration::from_seconds(timeout)) {
				LogMessage(MessageType::Error, wxPLURAL("Connection timed out after %d second of inactivity", "Connection timed out after %d seconds of inactivity", timeout), timeout);
				DoClose(FZ_REPLY_TIMEOUT);
				return;
			}
		}
		else {
			elapsed = fz::duration();
		}

		m_timer = add_timer(fz::duration::from_milliseconds(timeout * 1000) - elapsed, true);
	}
}
npAPInsIInputStreamShim::~npAPInsIInputStreamShim()
{
    this->doLock();

    DoClose();

    mPlugletListener = nsnull;
    mStreamInfo = nsnull;

    NPN_MemFree(mBuffer);
    mBuffer = nsnull;
    mBufferLength = 0;

    this->doUnlock();

    mAvailableForPluglet = 0;
    mNumWrittenFromPluginHost = 0;
    mDoClose = PR_TRUE;
    mDidClose = PR_TRUE;
    PR_DestroyLock(mLock);
    mLock = nsnull;

}
Esempio n. 14
0
//LAWYER: (BUILD MENU) Define the pressing of buttons
void CBuildMenu::OnCommand( const char *command )
{
	if (Q_stricmp( command, "vguicancel" ) != 0)
	{
		//TGB: some special commands need the current spawn idx
		if (Q_strnicmp( command, "summon", 6 ) == 0 || //both summon commands
			Q_strnicmp( command, "buildmenu_", 10 ) == 0) //remove last and clear queue commands
		{
			char buffer[256];
			Q_snprintf(buffer, sizeof(buffer), command, m_iCurrentSpawn);
			engine->ClientCmd( const_cast<char *>( buffer ) );
			return;
		}
		else if (Q_stricmp( command, "toggle_rally") == 0)
		{
			//engine->ClientCmd( const_cast<char *>( command ) );

			//TGB: instead of going through server, send a rallymode cmd to vgui_viewport
			KeyValues *msg = new KeyValues("ButtonCommand");
			msg->SetString("command", "MODE_RALLY");
			IViewPortPanel *pview = gViewPortInterface->FindPanelByName(PANEL_VIEWPORT);
			if (pview)
				PostMessage(pview->GetVPanel(), msg);

			//no return here means the buildmenu will close, as it should in this case
		}
		else
		{
			engine->ClientCmd( const_cast<char *>( command ) );
			return;
		}
	}

	DoClose();

	BaseClass::OnCommand(command);
}
Esempio n. 15
0
void ClientHandler::CloseAllBrowsers(bool force_close)
{
	if (!CefCurrentlyOn(TID_UI)) {
		// Execute on the UI thread.
		CefPostTask(TID_UI,
		            NewCefRunnableMethod(this, &ClientHandler::CloseAllBrowsers,
		                                 force_close));
		return;
	}

	if (!m_PopupBrowsers.empty()) {
		// Request that any popup browsers close.
		BrowserList::const_iterator it = m_PopupBrowsers.begin();
		for (; it != m_PopupBrowsers.end(); ++it)
			(*it)->GetHost()->CloseBrowser(force_close);
	}

	for (auto it : ofxClientBrowserMap) {
		for (auto &cefbrowser : it.second) {
			DoClose(cefbrowser);
		}
		ofxClientBrowserMap.erase(it.first);
	}
}
Esempio n. 16
0
void QTFPopUp::CancelMode() {
	DoClose();
}
Esempio n. 17
0
void CEffectVis::OnClose()
//------------------------
{
	DoClose();
}
Esempio n. 18
0
wxManualNotifMsgImpl::~wxManualNotifMsgImpl()
{
    if ( ms_icon )
        DoClose();
}
Esempio n. 19
0
bool Stream::Close()
{
	return DoClose(_sig);
}
int CTcpNetHandler::DoSend(int iConn) {
	write(iConn, m_pReactor->m_arrMsg[iConn].sBuf, strlen(m_pReactor->m_arrMsg[iConn].sBuf));//响应客户端
	DoClose(iConn);
	return 0;
}
Esempio n. 21
0
void KVSpIdGUI::SpiderIdentification()
{
   if ((!fHisto) || (!fGrid)) return;

   TVirtualPad* pad = fGrid->GetPad();
   fGrid->UnDraw();

   fZp = fZpEntry->GetIntNumber();
   if (!fUserParameter) fSpFactor = GetFactor();
   else fSpFactor = fSpiderFactorEntry->GetNumber();

   fAnglesUp   = fAngleUpEntry->GetIntNumber();
   fAnglesDown = fAngleDownEntry->GetIntNumber();
   fAlpha      = fApertureUpEntry->GetNumber();
   fPiedType   = fPiedChoice->GetSelected();
   fMatrixType = fTypeChoice->GetSelected();
   Int_t type  = fMatrixType;

   TH2*   tmpHisto = fHisto;
   TList* tmpCut   = 0;
   if (fUseCut) {
      tmpHisto = (TH2*)fHisto->Clone(Form("%s_cut", fHisto->GetName()));
      tmpHisto->Reset();
      for (int i = 1; i <= fHisto->GetNbinsX(); i++) {
         for (int j = 1; j <= fHisto->GetNbinsY(); j++) {
            Stat_t ww = fHisto->GetBinContent(i, j);
            Axis_t x0 = fHisto->GetXaxis()->GetBinCenter(i);
            Axis_t y0 = fHisto->GetYaxis()->GetBinCenter(j);
            if (fGrid->IsIdentifiable(x0, y0)) tmpHisto->Fill(x0, y0, ww);
         }
      }
      tmpCut = (TList*)fGrid->GetCuts()->Clone("tmpCuts");
   }

   fGrid->Clear();

   if (fScaledHisto) delete fScaledHisto;
   KVHistoManipulator hm;

   TF1 RtLt("RtLt", Form("x*%lf", fSfx), 0, tmpHisto->GetXaxis()->GetXmax());
   TF1 RtLty("RtLty", Form("x*%lf", fSfy), 0, tmpHisto->GetXaxis()->GetXmax());
   fScaledHisto = (TH2F*)hm.ScaleHisto(tmpHisto, &RtLt, &RtLty);

   if (fIdentificator) delete fIdentificator;
   fIdentificator = new KVSpiderIdentificator(fScaledHisto, fXm * fSfx, fYm * fSfy);

   switch (fPiedType) {
      case kUser:
         fIdentificator->SetX0(fPdx * fSfx);
         fIdentificator->SetY0(fPdy * fSfy);
         break;
      case kAuto:
         break;
      case kNone:
         fIdentificator->SetX0(0.);
         fIdentificator->SetY0(0.);
   }

   fIdentificator->SetParameters(fSpFactor);
   fIdentificator->SetNangles(fAnglesUp, fAnglesDown);
   fIdentificator->SetAlpha(fAlpha);

   fProgressBar->SetRange(0, fAnglesUp + fAnglesDown + 1);
   fProgressBar->Reset();
   fIdentificator->Connect("Increment(Float_t)", "TGHProgressBar", fProgressBar, "SetPosition(Float_t)");

   fTestButton->SetEnabled(kFALSE);
   fCloseButton->SetEnabled(kFALSE);
   fIdentificator->ProcessIdentification();
   fTestButton->SetEnabled(kTRUE);
   fCloseButton->SetEnabled(kTRUE);

   fIdentificator->Disconnect("Increment(Float_t)", fProgressBar, "SetPosition(Float_t)");
   fProgressBar->Reset();

   if (fDebug) fIdentificator->Draw(fOption.Data());

   TList* ll = (TList*)fIdentificator->GetListOfLines();

   KVIDZALine* TheLine = 0;
   int zmax = 0;

   KVSpiderLine* spline = 0;
   TIter next_line(ll);
   while ((spline = (KVSpiderLine*)next_line())) {
      if ((spline->GetN() > 10)) { //&&(spline->GetX(0)<=fIdentificator->GetX0()+200.))
         TF1* ff1 = 0;
         if (type == kSiCsI) ff1 = spline->GetFunction(fPdx * fSfx, TMath::Max(fScaledHisto->GetXaxis()->GetXmax() * 0.9, spline->GetX(spline->GetN() - 1)));
         else if (type == kSiSi)  ff1 = spline->GetFunction(fPdx * fSfx, TMath::Min(fScaledHisto->GetXaxis()->GetXmax() * 0.9, spline->GetX(spline->GetN() - 1) * 1.5));
         else if (type == kChIoSi)  ff1 = spline->GetFunction(fPdx * fSfx, TMath::Min(fScaledHisto->GetXaxis()->GetXmax() * 0.9, spline->GetX(spline->GetN() - 1) * 1.5));
         else ff1 = spline->GetFunction();
         if ((type == kSiCsI) && (ff1->GetParameter(1) >= 3000. || (ff1->GetParameter(2) <= 0.35) || (ff1->GetParameter(2) >= 1.))) {
            Info("SpiderIdentification", "Z = %d has been rejected (fit parameters)", spline->GetZ());
            continue;
         }
         TheLine = (KVIDZALine*)((KVIDZAGrid*)fGrid)->NewLine("ID");
         TheLine->SetZ(spline->GetZ());
         double min, max;
         ff1->GetRange(min, max);
         double step = TMath::Min((max - min) * 0.05, 20.); //20.;
         double stepmax = (max - min) * 0.2; //800.;
         double x = 0.;
         for (x = min + 1; x < max + step; x += step) {
            if (step <= stepmax) step *= 1.3;
            if (ff1->Eval(x) < 4000) TheLine->SetPoint(TheLine->GetN(), x, ff1->Eval(x));
         }
         if (max > x) TheLine->SetPoint(TheLine->GetN(), max, ff1->Eval(max));

         fGrid->Add("ID", TheLine);
         if (spline->GetZ() >= zmax) zmax = spline->GetZ();
      } else {
         Info("SpiderIdentification", "Z = %d has been rejected (too few points)", spline->GetZ());
      }
   }

   TF1 fx("fx12", Form("x/%lf", fSfx), 0., fScaledHisto->GetNbinsX() * 1.);
   TF1 fy("fy12", Form("x/%lf", fSfy), 0., fScaledHisto->GetNbinsY() * 1.);
   fGrid->Scale(&fx, &fy);

   if (fUseCut) delete tmpHisto;

   if (tmpCut) fGrid->GetCuts()->AddAll(tmpCut);
   pad->cd();
   fGrid->Draw();
   pad->Modified();
   pad->Update();

   DoClose();
}
Esempio n. 22
0
	void                OnClose             (wxCloseEvent&) { DoClose(); }
Esempio n. 23
0
	void                OnOk                (wxCommandEvent& e) { DoClose(); }
Esempio n. 24
0
int TcpClient::Disconnect()
{
    m_isAutoReconnect = false;
    DoClose();
    return 0;
}
Esempio n. 25
0
// ---------------------------------------------------------
// CConnection::~CConnection()
// ---------------------------------------------------------
//
CConnection::~CConnection()
    {
    Cancel();
    DoClose();
    }
Esempio n. 26
0
/**
Closes this reference counting object.

The default behaviour decrements the reference count by one. If this becomes 
zero, then the function calls DoClose on this reference counting object.
 
Where a derived class implements its own version of this function, it can 
use the protected member functions Dec() & DoClose() or make a base call to 
this function.

@see CFsObject::DoClose
*/
EXPORT_C void CFsObject::Close()
	{
	__THRD_PRINT(_L("CFsObject::Close()"));
	if(Dec()==1)
		DoClose();
	}
Esempio n. 27
0
void TWindow::Close()
{
	DoClose();
}
Esempio n. 28
0
ECode PdfEditor::Close()
{
    FAIL_RETURN(ThrowIfClosed());
    DoClose();
    return NOERROR;
}
void unLogFrame::OnCloseWindow( wxCloseEvent& WXUNUSED(event) )
{
	DoClose();
}
Esempio n. 30
0
void QTFPopUp::Deactivate() {
	if(open)
		DoClose();
}