예제 #1
0
bool IocpTransmitStrategy::PostSend() {
    auto& socketBuffer = m_transmitSocket.TheSocketBuffer();

    const auto sendLength = socketBuffer.PrepareSendPlan();
    if (sendLength < 1) {
        m_sendOperation.SetBusy(false);
        return true;
    }

    const auto count = socketBuffer.SetupSendIov(m_sendOperation.m_iov);

    DWORD bytesSent = 0;
    const auto& transmitSockId = m_transmitSocket.GetSockId();
    const auto ret = WSASend(transmitSockId
        , m_sendOperation.m_iov
        , count
        , &bytesSent
        , 0
        , &m_sendOperation.m_overlapped
        , NULL);
    if (ret != 0) {
        const auto error = WSAGetLastError();
        if (error != ERROR_IO_PENDING) {
            HandleFailure(&m_sendOperation, 0, error);
            return false;
        }
    }

    return true;
}
예제 #2
0
bool IocpTransmitStrategy::PostRecv() {
    auto& socketBuffer = m_transmitSocket.TheSocketBuffer();

    const auto recvLength = socketBuffer.PrepareRecvPlan();

    const auto count = socketBuffer.SetupRecvIov(m_recvOperation.m_iov);

    DWORD bytesRecvd = 0;
    DWORD flags = 0;
    const auto& transmitSockId = m_transmitSocket.GetSockId();
    const auto ret = WSARecv(transmitSockId
        , m_recvOperation.m_iov
        , count
        , &bytesRecvd
        , &flags
        , &m_recvOperation.m_overlapped
        , NULL);
    if (ret != 0) {
        const auto error = WSAGetLastError();
        if (error != ERROR_IO_PENDING) {
            HandleFailure(&m_recvOperation, 0, error);
            return false;
        }
    }

    return true;
}
예제 #3
0
void mcurlconn::HandleError(CURL *easy, long httpcode, CURLcode res, std::unique_ptr<mcurlconn> &&this_owner) {
	errorcount++;
	MCC_HTTPERRTYPE err = MCC_RETRY;
	if (res == CURLE_OK) {	//http error, not socket error
		err = CheckHTTPErrType(httpcode);
	}
	if (errorcount >= 3 && err < MCC_FAILED) {
		err = MCC_FAILED;
	}
	if (err == MCC_RETRY && mcflags & MCF::NORETRY) {
		err = MCC_FAILED;
	}

	LogSocketErrorMessage(this, easy, httpcode, res, err);

	switch (err) {
		case MCC_RETRY:
			sm.RetryConn(std::move(this_owner));
			break;

		case MCC_FAILED:
			HandleFailure(httpcode, res, std::move(this_owner));
			break;
	}
}
예제 #4
0
	void Process()
	{
#ifndef USING_GLES2
		if (g_Config.iRewindFlipFrequency != 0 && gpuStats.numFlips != 0)
			CheckRewindState();
#endif

		if (!needsProcess)
			return;
		needsProcess = false;

		if (!__KernelIsRunning())
		{
			ERROR_LOG(COMMON, "Savestate failure: Unable to load without kernel, this should never happen.");
			return;
		}

		std::vector<Operation> operations = Flush();
		SaveStart state;

		for (size_t i = 0, n = operations.size(); i < n; ++i)
		{
			Operation &op = operations[i];
			CChunkFileReader::Error result;
			bool callbackResult;
			std::string reason;

			I18NCategory *s = GetI18NCategory("Screen");
			// I couldn't stand the inconsistency.  But trying not to break old lang files.
			const char *i18nLoadFailure = s->T("Load savestate failed", "");
			const char *i18nSaveFailure = s->T("Save State Failed", "");
			if (strlen(i18nLoadFailure) == 0)
				i18nLoadFailure = s->T("Failed to load state");
			if (strlen(i18nSaveFailure) == 0)
				i18nSaveFailure = s->T("Failed to save state");

			switch (op.type)
			{
			case SAVESTATE_LOAD:
				INFO_LOG(COMMON, "Loading state from %s", op.filename.c_str());
				result = CChunkFileReader::Load(op.filename, REVISION, PPSSPP_GIT_VERSION, state, &reason);
				if (result == CChunkFileReader::ERROR_NONE) {
					osm.Show(s->T("Loaded State"), 2.0);
					callbackResult = true;
				} else if (result == CChunkFileReader::ERROR_BROKEN_STATE) {
					HandleFailure();
					osm.Show(i18nLoadFailure, 2.0);
					ERROR_LOG(COMMON, "Load state failure: %s", reason.c_str());
					callbackResult = false;
				} else {
					osm.Show(s->T(reason.c_str(), i18nLoadFailure), 2.0);
					callbackResult = false;
				}
				break;

			case SAVESTATE_SAVE:
				INFO_LOG(COMMON, "Saving state to %s", op.filename.c_str());
				result = CChunkFileReader::Save(op.filename, REVISION, PPSSPP_GIT_VERSION, state);
				if (result == CChunkFileReader::ERROR_NONE) {
					osm.Show(s->T("Saved State"), 2.0);
					callbackResult = true;
				} else if (result == CChunkFileReader::ERROR_BROKEN_STATE) {
					HandleFailure();
					osm.Show(i18nSaveFailure, 2.0);
					ERROR_LOG(COMMON, "Save state failure: %s", reason.c_str());
					callbackResult = false;
				} else {
					osm.Show(i18nSaveFailure, 2.0);
					callbackResult = false;
				}
				break;

			case SAVESTATE_VERIFY:
				INFO_LOG(COMMON, "Verifying save state system");
				callbackResult = CChunkFileReader::Verify(state) == CChunkFileReader::ERROR_NONE;
				break;

			case SAVESTATE_REWIND:
				INFO_LOG(COMMON, "Rewinding to recent savestate snapshot");
				result = rewindStates.Restore();
				if (result == CChunkFileReader::ERROR_NONE) {
					osm.Show(s->T("Loaded State"), 2.0);
					callbackResult = true;
				} else if (result == CChunkFileReader::ERROR_BROKEN_STATE) {
					// Cripes.  Good news is, we might have more.  Let's try those too, better than a reset.
					if (HandleFailure()) {
						// Well, we did rewind, even if too much...
						osm.Show(s->T("Loaded State"), 2.0);
						callbackResult = true;
					} else {
						osm.Show(i18nLoadFailure, 2.0);
						callbackResult = false;
					}
				} else {
					osm.Show(i18nLoadFailure, 2.0);
					callbackResult = false;
				}
				break;

			default:
				ERROR_LOG(COMMON, "Savestate failure: unknown operation type %d", op.type);
				callbackResult = false;
				break;
			}

			if (op.callback)
				op.callback(callbackResult, op.cbUserData);
		}
	}
예제 #5
0
MojErr SmtpSendMailCommand::HandleResponse(const std::string& line)
{
	try {
		switch (m_write_state) {
		case State_SendMailFrom:
		{
			MojLogInfo(m_log, "MAIL FROM command response");

			if (m_status == Status_Ok) {
				MojLogInfo(m_log, "MAIL FROM command +OK");
				m_toIdx = 0;
				if(m_toIdx < m_toAddress.size()) {
					m_write_state = State_SendRcptTo;
				} else {
					m_error.errorCode = MailError::BAD_RECIPIENTS; // Error out if for some reason there is no recipient.
					m_error.errorOnEmail = true;
					m_error.errorOnAccount = false;
					m_error.internalError = "Error setting forward address";
					m_write_state = State_SendErrorRset;
				}
				WriteEmail();
			} else {
				MojLogInfo(m_log, "MAIL FROM command -ERR");
				m_error = GetStandardError();
				m_error.internalError = "Error setting reverse address";
				m_write_state = State_SendErrorRset;
				WriteEmail();
			}
			break;
		}
		case State_SendRcptTo:
		{
			MojLogInfo(m_log, "RCPT TO command response");
 
			if (m_status == Status_Ok) {
				m_toIdx++;
				if (m_toIdx < m_toAddress.size()) {
					MojLogInfo(m_log, "RCPT TO command +OK, more to come");
					m_write_state = State_SendRcptTo;
				} else {
					MojLogInfo(m_log, "RCPT TO command +OK, done");
					m_write_state = State_SendData;
				}
				WriteEmail();
			
			} else {
				MojLogInfo(m_log, "RCPT TO command -ERR");
				m_error =  GetStandardError();
				if (m_status == 550) { // general failure means bad recipient
					m_error.errorCode = MailError::BAD_RECIPIENTS;
					m_error.errorOnEmail = true;
					m_error.errorOnAccount = false;
				}
				// 452 is technically a non-fatal error that says no more recipients can be
				// added, on the expectation we'll go and send our mail, and then send a
				// copy to the next batch of recipients. Instead, we'll treat this as a 
				// permanent error, and not send it to anyone (by sending RSET, and not DATA).
				// 552 is (as the spec says) an old and occasionally seen typo of 452.
				if (m_status == 452 || m_status == 552) {
					m_error.errorCode = MailError::BAD_RECIPIENTS; // too many, actually
					m_error.errorOnEmail = true;
					m_error.errorOnAccount = false;
				}
				m_error.internalError = "Error setting forward address";
				m_write_state = State_SendErrorRset;
				WriteEmail();
			}
			break;
		}
		case State_SendData:
		{
			MojLogInfo(m_log, "DATA command response");

			if (m_status == Status_Ok) {
				MojLogInfo(m_log, "DATA command +OK");
				m_write_state = State_SendBody;
				WriteEmail();
			
			} else {
				MojLogInfo(m_log, "DATA command -ERR");
				m_error = GetStandardError();
				m_error.internalError = "Error starting mail body";
				m_write_state = State_SendErrorRset;
				WriteEmail();
			}
			break;
		}
		case State_SendBody:
		{
			MojLogInfo(m_log, "BODY command response");

			if (m_status == Status_Ok) {
				MojLogInfo(m_log, "BODY command +OK");
				m_write_state = State_SendRset;
				WriteEmail();
			
			} else {
				MojLogInfo(m_log, "BODY command -ERR");
				m_error = GetStandardError();
				m_error.internalError = "Error completing send";
				m_write_state = State_SendErrorRset;
				WriteEmail();
			}
			break;
		}
		case State_SendRset:
		{
			MojLogInfo(m_log, "RSET command response");

			if (m_status == Status_Ok) {
				MojLogInfo(m_log, "RSET command +OK");
				SendDone();
			} else {
				MojLogInfo(m_log, "RSET command -ERR");
				m_error = GetStandardError();
				m_error.internalError = "Error resetting";
				HandleSmtpError(m_error);
			}
			break;
		}
		case State_SendErrorRset:
		{
			// Handle an error response after clearing an error: if we had one bad e-mail, we want to
			// be sure we are in a good state before going to the next e-mail.
			HandleSmtpError(m_error);
			break;
		}
		default:
		{
			MojLogInfo(m_log, "Unknown write mail state %d in SmtpSendMailCommand::HandleResponse", m_write_state);
			HandleFailure("bad HandleResponse state");
			break;
		}
		}

	} catch(const std::exception& e) {
		HandleException(e, __func__, __FILE__, __LINE__);
	} catch(...) {
		HandleUnknownException();
	}
	
	return MojErrNone;
}
예제 #6
0
void SmtpSendMailCommand::WriteEmail()
{
	try {
		switch (m_write_state) {
		case State_SendMailFrom:
		{
			MojLogInfo(m_log, "Sending MAIL FROM command");
			//MojLogInfo(m_log, "From address is %s\n", m_email.GetFrom()->GetAddress().c_str());

			std::string userCommand = std::string(FROM_COMMAND_STRING) + " <" + m_email.GetFrom()->GetAddress() + ">";
		
			// If SIZE extension is present, place message size on FROM line so that the server
			// can potentially reject it now, instead of after we transmit the data.
			if (m_session.GetSizeMax()) {
				char buf[64];
				memset(buf, '\0', sizeof(buf));
				snprintf(buf, sizeof(buf)-1, " SIZE=%d", m_bytesLeft);
				userCommand += buf;

				MojLogInfo(m_log, "...with SIZE");
			}
		
			SendCommand(userCommand, SmtpSession::TIMEOUT_MAIL_FROM);
			break;
		}
		case State_SendRcptTo:
		{
			MojLogInfo(m_log, "Sending RCPT TO command");
			//MojLogInfo(m_log, "To address is %s\n", m_toAddress[m_toIdx].c_str());

			std::string userCommand = std::string(TO_COMMAND_STRING) + " <" + m_toAddress[m_toIdx] + ">";
			SendCommand(userCommand, SmtpSession::TIMEOUT_RCPT_TO);
			break;
		}
		case State_SendData:
		{
			MojLogInfo(m_log, "Sending DATA command");
		
			std::string userCommand = DATA_COMMAND_STRING;
			SendCommand(userCommand, SmtpSession::TIMEOUT_DATA_INITIATION);
			break;
		}
		case State_SendBody:
		{
			MojLogInfo(m_log, "Sending BODY");
		
			assert(m_emailWriter.get());

			OutputStreamPtr outputStream = m_session.GetConnection()->GetOutputStream();
		
			// Wrap the mail writer in a CRLF fixer stream, which ensures that the stream ends with 
			// CRLF, so we can safely write out a DOT to end the body, without the risk that it'll end
			// up on the end of a body line.
			m_crlfTerminator.reset( new CRLFTerminatedOutputStream(outputStream) );

			// connect mail writer
			m_emailWriter->SetOutputStream(m_crlfTerminator);
		
			// FIXME: set up timeout on writing email body blocks
			//m_emailWriter->SetDataTimeout(SmtpSession::TIMEOUT_DATA_BLOCK);

			// Set up flow control
			AsyncOutputStream* asyncOs = dynamic_cast<AsyncOutputStream*>(outputStream.get());
			if(asyncOs) {
				m_flowControl.reset(new AsyncFlowControl(m_emailWriter, asyncOs));
			}
	
			// Send the DOT after the body is written.
			m_emailWriter->WriteEmail(m_writeDoneSlot);
			break;
		}
		case State_SendRset:
		{
			MojLogInfo(m_log, "Sending RSET");
		
			std::string userCommand = RESET_COMMAND_STRING;
			SendCommand(userCommand);
			break;
		}
		case State_SendErrorRset:
		{
			MojLogInfo(m_log, "Sending RSET after error");
		
			std::string userCommand = RESET_COMMAND_STRING;
			SendCommand(userCommand);
			break;
		}
		default:
		{
			MojLogInfo(m_log, "Unknown SmtpSendMailCommand::WriteEmail write mail state %d", m_write_state);
			HandleFailure("bad WriteEmail state");
			break;
		}
		}

	} catch(const std::exception& e) {
		HandleException(e, __func__, __FILE__, __LINE__);
	} catch(...) {
		HandleUnknownException();
	}
}
예제 #7
0
void
CMArray2DCommand::HandleFailure()
{
	HandleFailure(1, "");
	itsDirector->UpdateNext();
}
예제 #8
0
	/// Called to do non-default actions when assertion fails.
	void operator ()() { HandleFailure(); }
예제 #9
0
	void Process()
	{
#ifndef MOBILE_DEVICE
		if (g_Config.iRewindFlipFrequency != 0 && gpuStats.numFlips != 0)
			CheckRewindState();
#endif

		if (!needsProcess)
			return;
		needsProcess = false;

		if (!__KernelIsRunning())
		{
			ERROR_LOG(COMMON, "Savestate failure: Unable to load without kernel, this should never happen.");
			return;
		}

		std::vector<Operation> operations = Flush();
		SaveStart state;

		for (size_t i = 0, n = operations.size(); i < n; ++i)
		{
			Operation &op = operations[i];
			CChunkFileReader::Error result;
			bool callbackResult;
			std::string callbackMessage;
			std::string reason;

			I18NCategory *sc = GetI18NCategory("Screen");
			const char *i18nLoadFailure = sc->T("Load savestate failed", "");
			const char *i18nSaveFailure = sc->T("Save State Failed", "");
			if (strlen(i18nLoadFailure) == 0)
				i18nLoadFailure = sc->T("Failed to load state");
			if (strlen(i18nSaveFailure) == 0)
				i18nSaveFailure = sc->T("Failed to save state");

			switch (op.type)
			{
			case SAVESTATE_LOAD:
				INFO_LOG(COMMON, "Loading state from %s", op.filename.c_str());
				result = CChunkFileReader::Load(op.filename, PPSSPP_GIT_VERSION, state, &reason);
				if (result == CChunkFileReader::ERROR_NONE) {
					callbackMessage = sc->T("Loaded State");
					callbackResult = true;
					hasLoadedState = true;
				} else if (result == CChunkFileReader::ERROR_BROKEN_STATE) {
					HandleFailure();
					callbackMessage = i18nLoadFailure;
					ERROR_LOG(COMMON, "Load state failure: %s", reason.c_str());
					callbackResult = false;
				} else {
					callbackMessage = sc->T(reason.c_str(), i18nLoadFailure);
					callbackResult = false;
				}
				break;

			case SAVESTATE_SAVE:
				INFO_LOG(COMMON, "Saving state to %s", op.filename.c_str());
				result = CChunkFileReader::Save(op.filename, g_paramSFO.GetValueString("TITLE"), PPSSPP_GIT_VERSION, state);
				if (result == CChunkFileReader::ERROR_NONE) {
					callbackMessage = sc->T("Saved State");
					callbackResult = true;
				} else if (result == CChunkFileReader::ERROR_BROKEN_STATE) {
					HandleFailure();
					callbackMessage = i18nSaveFailure;
					ERROR_LOG(COMMON, "Save state failure: %s", reason.c_str());
					callbackResult = false;
				} else {
					callbackMessage = i18nSaveFailure;
					callbackResult = false;
				}
				break;

			case SAVESTATE_VERIFY:
				callbackResult = CChunkFileReader::Verify(state) == CChunkFileReader::ERROR_NONE;
				if (callbackResult) {
					INFO_LOG(COMMON, "Verified save state system");
				} else {
					ERROR_LOG(COMMON, "Save state system verification failed");
				}
				break;

			case SAVESTATE_REWIND:
				INFO_LOG(COMMON, "Rewinding to recent savestate snapshot");
				result = rewindStates.Restore();
				if (result == CChunkFileReader::ERROR_NONE) {
					callbackMessage = sc->T("Loaded State");
					callbackResult = true;
					hasLoadedState = true;
				} else if (result == CChunkFileReader::ERROR_BROKEN_STATE) {
					// Cripes.  Good news is, we might have more.  Let's try those too, better than a reset.
					if (HandleFailure()) {
						// Well, we did rewind, even if too much...
						callbackMessage = sc->T("Loaded State");
						callbackResult = true;
						hasLoadedState = true;
					} else {
						callbackMessage = i18nLoadFailure;
						callbackResult = false;
					}
				} else {
					callbackMessage = i18nLoadFailure;
					callbackResult = false;
				}
				break;

			case SAVESTATE_SAVE_SCREENSHOT:
				callbackResult = TakeGameScreenshot(op.filename.c_str(), SCREENSHOT_JPG, SCREENSHOT_RENDER);
				if (!callbackResult) {
					ERROR_LOG(COMMON, "Failed to take a screenshot for the savestate! %s", op.filename.c_str());
				}
				break;

			default:
				ERROR_LOG(COMMON, "Savestate failure: unknown operation type %d", op.type);
				callbackResult = false;
				break;
			}

			if (op.callback)
				op.callback(callbackResult, callbackMessage, op.cbUserData);
		}
		if (operations.size()) {
			// Avoid triggering frame skipping due to slowdown
			__DisplaySetWasPaused();
		}
	}