// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
//		¥ CreateErrorString
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
// To create the error string it first looks if the context record has an error string on it
// If so it uses that, if not it uses the UError class to generate the error code.
// If an error occurs a null string is returned and false is returned. If OK then true is returned and the string is filled
// out.
bool CAEDescException::CreateErrorString(
	Str255			outString) const
{
	outString[0]=0;
	
	Try_
	{
		StAEDescriptor		errorDesc(mContextRecord,keyErrorString,typeText);
	
		if (errorDesc.IsNotNull())
		{
			UExtractFromAEDesc::ThePString(errorDesc,outString);
			return true;
		}
		else
		{
			// No string, generate using context record
			return UErrors::GetErrorMessage(GetErrorCode(),mContextRecord,outString);
		}
	}
	Catch_(err)
	{
		return false;
	}
	
	return true;
}
Example #2
0
void DryadSubGraphVertex::VertexCompleted(DrError status,
                                          DryadMetaData* errorData)
{
    bool finished = false;

    {
        AutoCriticalSection acs(&m_baseCS);

        LogAssert(GetErrorCode() != DryadError_VertexCompleted);
        if (status == DryadError_VertexCompleted)
        {
            status = DrError_OK;
        }

        if (NoError())
        {
            ReportError(status, errorData);
        }

        LogAssert(m_outstandingVertices > 0);
        --m_outstandingVertices;

        if (m_outstandingVertices == 0)
        {
            finished = true;
        }
    }

    if (finished)
    {
        /* the real status will be returned in AsyncPostCompletion
           after we have exited all handlers. */
        m_handler->ProgramCompleted();
    }
}
/*
========================
idLBCache::Scroll
========================
*/
bool idLBCache::Scroll( int amount ) {
	if ( GetErrorCode() != LEADERBOARD_DISPLAY_ERROR_NONE ) {
		return false;	// don't allow scrolling on errors
	}

	// Remember old offsets so we know if anything moved
	int oldEntryIndex = entryIndex;
	int oldRowOffset = rowOffset;

	// Move cursor index by scroll amount
	entryIndex += amount;

	// Clamp cursor index (scrolling row offset if we can)
	if ( entryIndex < 0 ) {
		rowOffset += entryIndex;
		entryIndex = 0;
	} else if ( entryIndex >= numRowsInLeaderboard ) {
		entryIndex = numRowsInLeaderboard - 1;
		rowOffset = entryIndex - ( MAX_STAT_LISTINGS - 1 );
	} else if ( entryIndex >= MAX_STAT_LISTINGS ) {
		rowOffset += entryIndex - ( MAX_STAT_LISTINGS - 1 );
		entryIndex = MAX_STAT_LISTINGS - 1;
	}	

	// Clamp row offset
	rowOffset = idMath::ClampInt( 0, Max( numRowsInLeaderboard - MAX_STAT_LISTINGS, 0 ), rowOffset );

	// Let caller know if anything actually changed
	return ( oldEntryIndex != entryIndex || oldRowOffset != rowOffset );
}
Example #4
0
void SetPyException(const std::exception& ex)
{
    const char* message = ex.what();
    if (dynamic_cast<const MI::TypeConversionException*>(&ex))
    {
        PyErr_SetString(PyExc_TypeError, message);
    }
    else
    {
        PyObject* d = PyDict_New();
        PyObject* pyEx = nullptr;
        if (dynamic_cast<const MI::MITimeoutException*>(&ex))
        {
            pyEx = PyMITimeoutError;
        }
        else
        {
            pyEx = PyMIError;
        }

        if (dynamic_cast<const MI::MIException*>(&ex))
        {
            auto miex = static_cast<const MI::MIException*>(&ex);
            PyDict_SetItemString(d, "error_code", PyLong_FromUnsignedLong(miex->GetErrorCode()));
            PyDict_SetItemString(d, "mi_result", PyLong_FromUnsignedLong(miex->GetResult()));
        }

        PyDict_SetItemString(d, "message", PyUnicode_FromString(message));
        PyErr_SetObject(pyEx, d);
        Py_DECREF(d);
    }
}
/********************************************************************
 *         同 步 POST  ,Content-type: multipart/form-data            *
 *********************************************************************/
HTTP_RESULTCODE	CHttp::SyncUploadFormData(const std::string & strUrl, const std::map<std::string,std::string> & mapData, const std::map<std::string,std::string> & mapFile, std::string & strResult)
{
	if (strUrl.empty())
	{
		return HTTPRESULT_FAIL;
	}

	if( m_bRunning )
	{
		return HTTPRESULT_FAIL;
	}

	m_bRunning  = true;
	Reset();

	m_strUrl			  = strUrl;
	m_mapPostData =  mapData;
	m_mapPostFile	  =  mapFile;

	CURLcode eErrorCode = DoHttpPostFormData();
	std::string strTemp;
	bool  bResult = GetResultData(strResult);
	
	m_bRunning  = false;

	if (bResult && eErrorCode == CURLE_OK)
	{
		return HTTPRESULT_OK;
	}

	return GetErrorCode(eErrorCode);
}
/*
========================
idLBCache::ScrollOffset
========================
*/
bool idLBCache::ScrollOffset( int amount ) {
	if ( GetErrorCode() != LEADERBOARD_DISPLAY_ERROR_NONE ) {
		return false;	// don't allow scrolling on errors
	}

	// Remember old offsets so we know if anything moved
	int oldEntryIndex = entryIndex;
	int oldRowOffset = rowOffset;

	rowOffset += amount;

	// Clamp row offset
	rowOffset = idMath::ClampInt( 0, Max( numRowsInLeaderboard - MAX_STAT_LISTINGS, 0 ), rowOffset );

	if ( rowOffset != oldRowOffset ) {
		entryIndex -= amount;	// adjust in opposite direction so same item stays selected
		entryIndex = idMath::ClampInt( 0, rowOffset + ( MAX_STAT_LISTINGS - 1 ), entryIndex );
	} else {
		entryIndex += amount;
		entryIndex = idMath::ClampInt( 0, numRowsInLeaderboard - 1, entryIndex );
	}	

	// Let caller know if anything actually changed
	return ( oldEntryIndex != entryIndex || oldRowOffset != rowOffset );
}
EXCEL_RC EvaluateX(double* newVars, int numVars, int numCons,
                   const double* bestSolution, bool feasibility,
                   double* newCons) {
  EXCEL_RC rc;

  rc = CheckForEscapeKeypress(true);
  if (rc != SUCCESS) {
    goto ErrorHandler;
  }

  rc = UpdateVars(newVars, numVars, bestSolution, feasibility);
  if (rc != SUCCESS) {
    goto ErrorHandler;
  }

  rc = RecalculateValues();
  if (rc != SUCCESS) {
    goto ErrorHandler;
  }

  rc = GetConstraintValues(numCons, newCons);
  if (rc != SUCCESS) {
    goto ErrorHandler;
  }

  return SUCCESS;

ErrorHandler:
  // Confirm whether the error is the result of an escape keypress
  if (GetErrorCode(CheckForEscapeKeypress(false)) == ESC_ABORT) {
    return ESC_ABORT;
  } else {
    return rc;
  }
}
Example #8
0
bool
StatementObject::GetProperty(NPIdentifier name, NPVariant *result)
{
//sprintf(tmp, "stmt GetProperty [%s]\n", NPN_UTF8FromIdentifier(name)); log(tmp);
  VOID_TO_NPVARIANT(*result);

  if (name == mc_rowCount_id)
    {
      INT32_TO_NPVARIANT(m_rowCount, *result);
      return true;
    }
  else if (name == mc_columnCount_id)
    {
      INT32_TO_NPVARIANT(m_columnCount, *result);
      return true;
    }
  else if (name == mc_errorMessage_id)
    {
      STRING_TO_NPVARIANT(GetErrorString(), *result);
      return true;
    }
  else if (name == mc_errorCode_id)
    {
      INT32_TO_NPVARIANT(GetErrorCode(), *result);
      return true;
    }
  else if (name == mc_errorState_id)
    {
      STRING_TO_NPVARIANT(GetErrorState(), *result);
      return true;
    }
  return false;

}
Example #9
0
UDT_API(s32) udtParseDemoFiles(udtParserContextGroup** contextGroup, const udtParseArg* info, const udtMultiParseArg* extraInfo)
{
	if(contextGroup == NULL || info == NULL || extraInfo == NULL ||
	   !IsValid(*extraInfo) || !HasValidPlugInOptions(*info))
	{
		return (s32)udtErrorCode::InvalidArgument;
	}

	udtDemoThreadAllocator threadAllocator;
	const bool threadJob = threadAllocator.Process(extraInfo->FilePaths, extraInfo->FileCount, extraInfo->MaxThreadCount);
	const u32 threadCount = threadJob ? threadAllocator.Threads.GetSize() : 1;
	if(!CreateContextGroup(contextGroup, threadCount))
	{
		// We must stop here because we can't store the data the user will later want to retrieve.
		return (s32)udtErrorCode::OperationFailed;
	}

	if(!threadJob)
	{
		return udtParseMultipleDemosSingleThread(udtParsingJobType::General, (*contextGroup)->Contexts, info, extraInfo, NULL);
	}
	
	udtMultiThreadedParsing parser;
	const bool success = parser.Process((*contextGroup)->Contexts, threadAllocator, info, extraInfo, udtParsingJobType::General, NULL);

	return GetErrorCode(success, info->CancelOperation);
}
//PCSCREADERDRIVERDLL_API unsigned short CCONV HD_ClosePort(short ivPortNo, HANDLE devNo)
PCSCREADERDRIVERDLL_API unsigned short CCONV HD_ClosePort(HANDLE devNo)
{
	
	if( ContextHandle == NULL)
		return EXCUTE_SUC ;	

	if (!CanReleaseRef())
	{
		if (g_RefCount)
			DebugMessage(1);
		else
			DebugMessage(1);
		return EXCUTE_SUC;
	}
	//
	//The SCardDisconnect function terminates a connection previously opened 
	//between the calling application and a smart card in the target reader.
	//

	//SCARD_LEAVE_CARD  Don't do anything special. 
	//SCARD_RESET_CARD  Reset the card. 
	//SCARD_UNPOWER_CARD  Power down the card. 
	//SCARD_EJECT_CARD  Eject the card. 

/*	ret = SCardDisconnect((SCARDHANDLE)devNo, SCARD_UNPOWER_CARD);
	if (ret != SCARD_S_SUCCESS)
	{
//	    MessageBox(NULL,"CER_PCSC_SCardDisconnect","Err",MB_OK);
//		GetErrorCode(ret);
		return CER_PCSC_SCardDisconnect ;	
	}
	
 
	ret = SCardCancel(ContextHandle);
	if (ret != SCARD_S_SUCCESS)
	{
//		GetErrorCode(ret);
		return CER_PCSC_SCardCancel;
	}*/


	//
	//The SCardReleaseContext function closes an established resource manager context, 
	//freeing any resources allocated under that context, 
	//including SCARDHANDLE objects and memory allocated using the SCARD_AUTOALLOCATE 
	//length designator.
	//

	ret = SCardReleaseContext(ContextHandle);
	if (ret != SCARD_S_SUCCESS)
	{
		GetErrorCode(ret);
		return CER_PCSC_SCardReleaseContext;
	}

	ContextHandle = NULL;

//	ReaderStatus[ivPortNo-1][1]=0;
	return EXCUTE_SUC ;	
}
Example #11
0
UDT_API(s32) udtConvertDemoFiles(const udtParseArg* info, const udtMultiParseArg* extraInfo, const udtProtocolConversionArg* conversionArg)
{
	if(info == NULL || extraInfo == NULL || conversionArg == NULL ||
	   !IsValid(*extraInfo) || !HasValidOutputOption(*info) || !IsValid(*conversionArg))
	{
		return (s32)udtErrorCode::InvalidArgument;
	}

	udtDemoThreadAllocator threadAllocator;
	const bool threadJob = threadAllocator.Process(extraInfo->FilePaths, extraInfo->FileCount, extraInfo->MaxThreadCount);
	if(!threadJob)
	{
		return udtParseMultipleDemosSingleThread(udtParsingJobType::Conversion, NULL, info, extraInfo, conversionArg);
	}

	udtParserContextGroup* contextGroup;
	if(!CreateContextGroup(&contextGroup, threadAllocator.Threads.GetSize()))
	{
		return udtParseMultipleDemosSingleThread(udtParsingJobType::Conversion, NULL, info, extraInfo, conversionArg);
	}

	udtMultiThreadedParsing parser;
	const bool success = parser.Process(contextGroup->Contexts, threadAllocator, info, extraInfo, udtParsingJobType::Conversion, conversionArg);

	DestroyContextGroup(contextGroup);

	return GetErrorCode(success, info->CancelOperation);
}
/*****************************************************************
 *          同 步 GET          *
 *****************************************************************/
HTTP_RESULTCODE	CHttp::SyncDownload(const std::string &strUrl, std::string & strResult)
{
	if (strUrl.empty())
	{
		return HTTPRESULT_FAIL;
	}

	if( m_bRunning )
	{
		return HTTPRESULT_FAIL;
	}

	m_bRunning	= true;
	Reset();	
	m_strUrl = strUrl;

	CURLcode eErrorCode = DoHttpGet();
	bool  bResult = GetResultData(strResult);
	m_bRunning	= false;

	if (bResult && CURLE_OK == eErrorCode)
	{
		return HTTPRESULT_OK;
	}	

	return GetErrorCode(eErrorCode);
}
HTTP_RESULTCODE HTTPRequest::startSynchronous()
{
	HTTP_RESULTCODE rCode = HTTPRESULT_FAIL;
	if (url.empty())
	{
		return rCode;
	}

	if( isRunning )
	{
		return rCode;
	}

	isRunning	= true;
	CURLcode code;
	switch (requestMethod)
	{
	case HttpMethod_GET:
		code = DoHttpGet();
		break;
	case HttpMethod_POST:
		code = DoHttpPost();
		break;
	case HttpMethod_HEAD:
		code = DoHttpHead();
		break;
	case HttpMethod_PUT:
		code = DoHttpPut();
		break;
	case HttpMethod_DELETE:
		code = DoHttpDelete();
		break;
	default:
		break;
	}
	isRunning = false;
	rCode = GetErrorCode(code);
	
	printf("%s",_pchResultData);
	/*
	//分发消息
	if (delegate != NULL)
	{
		if (rCode == HTTPRESULT_OK)
		{

			delegate->OnHttpComplete(this);
		}
		else
		{
			delegate->OnHttpFailed(this,rCode);
		}
		
	}
	*/
	return rCode;
}
Example #14
0
void DryadSubGraphVertex::AsyncPostCompletion()
{
    ShutDownFifos();

    if (GetErrorCode() == DrError_OK)
    {
        ReportError(DryadError_VertexCompleted);
    }
}
int CTCPSocketAsync::Peek(char* pBuffer,
						  unsigned long ulBufferLength)
{
	try
	{
		//Try to receive
		int iResult;
		if ((iResult=CTCPSocket::Peek(pBuffer,
										 ulBufferLength))>=0)
			return iResult;
		//Check is it an error
		else if (GetSystemLastError()==WSAEWOULDBLOCK)
			return 0;
		else
			return GetErrorCode();
	}
	ERROR_HANDLER_RETURN("Peek",GetErrorCode())
}
BOOL CTCPSocketAsync::SendBlockedBuffer(const CBlockedBuffer::CBlockedData& rData)
{
	try
	{
		//Try to send it
		return SendNoAdd(rData.GetData(),
						 rData.GetDataSize())!=GetErrorCode();
	}
	ERROR_HANDLER_RETURN("SendBlockedBuffer",FALSE)
}
Example #17
0
string CZipCompression::FormatErrorMessage(string where,
        unsigned long pos) const
{
    string str = "[" + where + "]  " + GetErrorDescription();
    if ( !pos ) {
        pos = STREAM->total_in;
    }
    str += ";  error code = " + NStr::IntToString(GetErrorCode()) +
           ", number of processed bytes = " + NStr::ULongToString(pos);
    return str + ".";
}
//PCSCREADERDRIVERDLL_API unsigned short CCONV HD_ProbeCard(HANDLE ContextNo, HANDLE devNo, short ivPortNo, short ivCardSeat)	
//PCSCREADERDRIVERDLL_API unsigned short CCONV HD_ProbeCard(HANDLE ContextNo,  short ivPortNo, short ivCardSeat)	
PCSCREADERDRIVERDLL_API unsigned short CCONV HD_ProbeCard(HANDLE devNo,short	ivCardSeat)		
{
	SCARDCONTEXT		ContextNo=NULL;
	
	ret = SCardEstablishContext(SCARD_SCOPE_USER, NULL, NULL, &ContextNo);
	if (ret != SCARD_S_SUCCESS) 
	{
//		GetErrorCode(ret);			
		return CER_PCSC_SCardEstablishContext ;
	}

	SCARD_READERSTATE udtReaderState[2];
	DWORD EventStatetpm;
	char Reader[300];

	strcpy(Reader,"Gemplus GemPC430 0\0");
	udtReaderState[0].szReader=Reader;
	//udtReaderState[0].dwCurrentState = SCARD_STATE_UNAVAILABLE;
	//udtReaderState[0].dwCurrentState = SCARD_STATE_PRESENT;
	udtReaderState[0].dwCurrentState = SCARD_STATE_UNAWARE;
//	udtReaderState[0].dwEventState = SCARD_STATE_UNKNOWN |SCARD_STATE_CHANGED|SCARD_STATE_IGNORE;
//	udtReaderState[0].dwEventState = SCARD_STATE_PRESENT;
//	udtReaderState[0].dwEventState = SCARD_STATE_EMPTY;
	ret = SCardGetStatusChange(ContextNo, 0, udtReaderState, 1);
	if (ret != SCARD_S_SUCCESS)
	{
//		GetErrorCode(ret);
//		EventStatetpm = udtReaderState[0].dwEventState;
//		WriteLog("SCardGetStatusChange1", ivPortNo,EventStatetpm);
		SCardReleaseContext(ContextNo);
		ContextHandle = NULL;
		return CER_PCSC_SCardGetStatusChange;
	}
	EventStatetpm = udtReaderState[0].dwEventState;

	if ((EventStatetpm & 0x00000010)==0x00000010)	//0x00000010 -->SCARD_STATE_EMPTY
	{
//		GetErrorCode(ret);
		SCardReleaseContext(ContextNo);
		ContextHandle = NULL;
		return CER_NOCARD;
	}

	ret = SCardReleaseContext(ContextNo);
	if (ret != SCARD_S_SUCCESS)
	{
		GetErrorCode(ret);
		return CER_PCSC_SCardReleaseContext;
	}
	ContextNo = NULL;


	return EXCUTE_SUC;
}
/********************************************************************
 *           upload formdata 线程运行函数         *
 ********************************************************************/
UINT __stdcall  thread_run_uploadformdata(LPVOID lpParam)
{
	CHttp * pHttp= (CHttp *) lpParam;
	CURLcode eErrorCode = pHttp->DoHttpPostFormData();

    HTTP_RESULTCODE eHttpError = GetErrorCode(eErrorCode);	

	::PostMessage(CHttpProxy::GetInstance()->GethWnd(), MSG_HTTP_COMPLETE, (WPARAM)pHttp,(LPARAM)eHttpError);

	return 0;
}
int PostgresPreparedStatementWrapper::RunQuery()
{
  long nRows = -1;
  int nParameters = m_Parameters.GetSize();
  char** paramValues = m_Parameters.GetParamValues();
  int* paramLengths = m_Parameters.GetParamLengths();
  int* paramFormats = m_Parameters.GetParamFormats();
  int nResultFormat = 0; // 0 = text, 1 = binary (all or none on the result set, not column based)
  wxCharBuffer statementNameBuffer = ConvertToUnicodeStream(m_strStatementName);
  PGresult* pResult = m_pInterface->GetPQexecPrepared()(m_pDatabase, statementNameBuffer, nParameters, paramValues, paramLengths, paramFormats, nResultFormat);
  if (pResult != NULL)
  {
    ExecStatusType status = m_pInterface->GetPQresultStatus()(pResult);
    if ((status != PGRES_COMMAND_OK) && (status != PGRES_TUPLES_OK))
    {
      SetErrorCode(PostgresDatabaseLayer::TranslateErrorCode(status));
      SetErrorMessage(ConvertFromUnicodeStream(m_pInterface->GetPQresultErrorMessage()(pResult)));
    }

    if (GetErrorCode() == DATABASE_LAYER_OK)
    {
      wxString rowsAffected = ConvertFromUnicodeStream(m_pInterface->GetPQcmdTuples()(pResult));
      rowsAffected.ToLong(&nRows);
    }
    m_pInterface->GetPQclear()(pResult);
  }
  delete []paramValues;
  delete []paramLengths;
  delete []paramFormats;

  if (GetErrorCode() != DATABASE_LAYER_OK)
  {
    ThrowDatabaseException();
    return DATABASE_LAYER_QUERY_RESULT_ERROR;
  }

  return (int)nRows;
}
void DebugMessage(long ret)
{
#ifdef WRITE_DEBUG_MESSAGE

	char szPath[MAX_PATH];
	GetModuleFileName(NULL, szPath, MAX_PATH);
	PathRemoveFileSpec(szPath);

	strcat(szPath, "\\PCSCReaderDriverDll_DEBUGINFO.txt");
	FILE *f = fopen(szPath, "a+");
	GetErrorCode(ret);
	fprintf(f, "%x==%s", DevNo, message);
	fclose(f);
#endif
}
BOOL CUDPSocketAsync::Send(const std::string& rDestinationAddress, 
						   unsigned short usDestinationPort,
						   const char* pBuffer,
						   unsigned short usBufferLength)
{
	try
	{
		//Delegate call
		return CUDPSocket::Send(rDestinationAddress,
								usDestinationPort,
								pBuffer,
								usBufferLength);
	}
	ERROR_HANDLER_RETURN("Send",GetErrorCode())
}
Example #23
0
int main(int argc, char *argv[])
{
	HIJACK *hijack;
	FUNC *func;
	unsigned long addr;
	PLT *plts, *plt;
	
	if (argc != 2)
		usage(argv[0]);
	
	hijack = InitHijack();
    ToggleFlag(hijack, F_DEBUG);
    ToggleFlag(hijack, F_DEBUG_VERBOSE);
	AssignPid(hijack, atoi(argv[1]));
	
	if (Attach(hijack) != ERROR_NONE)
	{
		fprintf(stderr, "[-] Couldn't attach!\n");
		exit(EXIT_FAILURE);
	}

	if (LocateAllFunctions(hijack) != ERROR_NONE)
	{
		fprintf(stderr, "[-] Couldn't locate all functions!\n");
		exit(EXIT_FAILURE);
	}

    if (LocateSystemCall(hijack) != ERROR_NONE) {
        fprintf(stderr, "[-] Couldn't locate system call!\n");
        exit(EXIT_FAILURE);
    }

    addr = MapMemory(hijack, NULL, 8192, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_SHARED);
    if (GetErrorCode(hijack) != ERROR_NONE) {
        fprintf(stderr, "[-] %s\n", GetErrorString(hijack));
        perror("ptrace");
    }
	
	printf("[*] PLT/GOT @ 0x%016lx\n", hijack->pltgot);
	printf("[*] Baseaddr @ 0x%016lx\n", hijack->baseaddr);
    printf("[*] Syscall @ 0x%016lx\n", hijack->syscalladdr);
    printf("[*] addr @ 0x%016lx\n", addr);

	Detach(hijack);
	
	return 0;
}
// Connect to BVH server (for e.g. Axis Neuron SW)
bool APerceptionNeuronController::Connect(FString HostName, int32 Port)
{
	if (bConnected == true)
		return false;

	// Set up reference bone handling
	// Template does not support transition for the reference bone yet
	// Should be no problem, because normally reference bone does not change values.
	if (bReference == true)
	{
		// Skip reference bone x,y,z translation and x,y,z rotation 
		// regardless if displacement is active or not (Axis Neuron sends always 6 floats)
		FloatSkip = 6; 
	}

	// Create TCP Socket and connect
	ISocketSubsystem* const SocketSubSystem = ISocketSubsystem::Get(); 
	if (SocketSubSystem)
	{
		ReceiverSocket = SocketSubSystem->CreateSocket(NAME_Stream, TEXT("PerceptionNeuronSocket"), false);
		if (ReceiverSocket == NULL)
			return false;
	
		auto ResolveInfo = SocketSubSystem->GetHostByName(TCHAR_TO_ANSI(*HostName));
		while (!ResolveInfo->IsComplete());

		if (ResolveInfo->GetErrorCode() == 0)
		{
			const FInternetAddr* Addr = &ResolveInfo->GetResolvedAddress();
			uint32 IP;
			Addr->GetIp(IP);
			
			TSharedRef<FInternetAddr> InetAddr = SocketSubSystem->CreateInternetAddr();
			InetAddr->SetIp(IP);
			InetAddr->SetPort(Port);

			bConnected = ReceiverSocket->Connect(*InetAddr);
		}
	}

	return bConnected;
}
CString CXTPRegistryManager::GetErrorMessage() const
{
	LPVOID lpMsgBuf = 0;

	::FormatMessage(
		FORMAT_MESSAGE_ALLOCATE_BUFFER |
		FORMAT_MESSAGE_FROM_SYSTEM |
		FORMAT_MESSAGE_IGNORE_INSERTS,
		NULL,
		GetErrorCode(),
		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
		(LPTSTR) &lpMsgBuf,
		0,
		NULL
		);

	CString csMessage((LPCTSTR)lpMsgBuf);

	// Free the buffer.
	::LocalFree( lpMsgBuf );

	return csMessage;
}
int CTCPSocketAsync::SendNoAdd(const char* pBuffer,
							   unsigned long ulBufferLength)
{
	try
	{
		//Quit if not ok
		if (!CheckSocketValid())
			return FALSE;

		//Send the data
		int iResult;

		//And send it
		iResult=send(GetHandle(),
					 pBuffer,
					 ulBufferLength,
					 NULL);

		//And exit
		return iResult;
	}
	ERROR_HANDLER_RETURN("SendNoAdd",GetErrorCode())
}
unsigned __stdcall  thread_http_get(LPVOID lpParam)
{
	HTTPRequest * pHttp= (HTTPRequest *) lpParam;
	CURLcode rCode = pHttp->DoHttpGet();
	pHttp->isRunning = false;
     HTTP_RESULTCODE eHttpError = GetErrorCode(rCode);	
	 //分发消息
	if (pHttp->delegate != NULL)
	{
		if (rCode == HTTPRESULT_OK)
		{

			pHttp->delegate->OnHttpComplete(pHttp);
		}
		else
		{
			pHttp->delegate->OnHttpFailed(pHttp,eHttpError);
		}
		
	}

	
	return 0;
}
NS_IMETHODIMP
TransportSecurityInfo::GetErrorCode(int32_t* state)
{
    *state = GetErrorCode();
    return NS_OK;
}
Example #29
0
const tchar* XmlParser::GetErrorString() 
{
    return XML_ErrorString( GetErrorCode() );
}
int CTCPSocketAsync::Send(const char *pBuffer,
						  unsigned long ulBufferLength)
{
	try
	{
		//Reset the event
		ResetEvent();

		//Send the data
		int iResult;
		iResult=SendNoAdd(pBuffer,
						  ulBufferLength);

		//Did we succeed ?
		if (iResult==GetErrorCode())
			//Is it blocked send ?
			if (WSAGetLastError()==WSAEWOULDBLOCK)
				if (GetBlockedBuffer())
				{
					//Add to the buffer, if we have one
					GetBlockedBuffer()->AddRecord(CBlockedBuffer::CBlockedData(pBuffer,
																			   ulBufferLength));

					//We have not error
					iResult=0;
				}
				else if (IsBlockSend())
					//Are we in the same thread?
					if (!IsInThread())
						if (WaitForBlockEvent())
						{
							//Set the error
							::SetLastError(WSAENOTCONN);

							//Exit
							return GetErrorCode();
						}
						else
							//Retry to send
							return Send(pBuffer,
										ulBufferLength);
					else
					{
						//We'll have to do a loop
						Sleep(10);

						//Try again
						if (SendNoAdd(pBuffer,
									  ulBufferLength)==GetErrorCode())
							//Which error
							if (WSAGetLastError()==WSAEWOULDBLOCK)
								return 0;
							else
								return GetErrorCode();
					}
				//Blocking error (not really an error)
				else
					return 0;
			else
				//Set the error code
				SetLastError("Send");

		//Done
		return iResult;
	}
	ERROR_HANDLER_RETURN("Send",GetErrorCode())
}