コード例 #1
0
void CWin32Socket::SendTo(TWin32Message& aMessage)
	{
	__ASSERT_DEBUG((iSendMessage == NULL) && (iBytesSent == 0), Panic(EWinSockPrtCWin32SocketMultipleSendToRequests));
	iSendMessage = &aMessage;
	WSP_LOG(WspLog::Printf(_L("CWin32Socket::SendTo: this: 0x%x, bytes to send: %d"), this, iSendMessage->ReadBuffer().Length()));
	TPtrC8 bufPtr(iSendMessage->ReadBuffer());
	iSendBuffer.buf = reinterpret_cast<char*>(const_cast<TUint8*>(bufPtr.Ptr()));
	iSendBuffer.len = bufPtr.Length();
	iSendOverlapped.hEvent = (void*) this;
	TInetAddr address;
	address.Copy(iSendMessage->WriteBuffer());
	SOCKADDR_IN winSockAddress;
	ConvertAddress(address, winSockAddress);
	DWORD numberOfBytesSent;
	TInt ret = WSASendTo(iSocket, &iSendBuffer, 1, &numberOfBytesSent, 0, (LPSOCKADDR)&winSockAddress, sizeof(struct sockaddr_in), &iSendOverlapped, &SendToCompletion);
	if (ret == SOCKET_ERROR)
		{
		TInt err = WSAGetLastError();
		if (err != WSA_IO_PENDING)
			{
			WSP_LOG(WspLog::Printf(_L("\tsocket error: %d"), err));
			Complete(iSendMessage, MapWinSockError(err));
			}
		}
	}
コード例 #2
0
void CWin32Socket::Connect(TWin32Message& aMessage)
	{
	__ASSERT_DEBUG(iConnectMessage == NULL, Panic(EWinSockPrtCWin32SocketMultipleConnectRequests));
	iConnectMessage = &aMessage;
	WSP_LOG(WspLog::Printf(_L("CWin32Socket::Connect: this: 0x%x"), this));

	if (WSAEventSelect(iSocket, iEvent, FD_CONNECT) == SOCKET_ERROR)
		{
		TInt err = MapWinSockError(WSAGetLastError());
		CloseSocket();
		Complete(iConnectMessage, err);
		return;
		}

	const TInetAddr& address = static_cast<const TInetAddr&>(iConnectMessage->ReadBuffer());
	SOCKADDR_IN winSockAddress;
	ConvertAddress(address, winSockAddress);

	if (WSAConnect(iSocket, (LPSOCKADDR)&winSockAddress, sizeof(struct sockaddr_in), NULL, NULL, NULL, NULL) == SOCKET_ERROR)
		{
		TInt nError = WSAGetLastError();
		if (nError != WSAEWOULDBLOCK)
			{
			CloseSocket();
			Complete(iConnectMessage, MapWinSockError(nError));
			}
		}
	else
		{
		Complete(iConnectMessage, KErrNone);
		}
	}
コード例 #3
0
void CWin32Socket::Bind(TWin32Message& aMessage)
	{
	const TInetAddr& address = static_cast<const TInetAddr&>(aMessage.ReadBuffer());
	SOCKADDR_IN winSockAddress;
	ConvertAddress(address, winSockAddress);
	if (bind(iSocket, (LPSOCKADDR)&winSockAddress, sizeof(struct sockaddr_in)))
		{
		aMessage.Complete(MapWinSockError(WSAGetLastError()));
		}
	else
		{
		aMessage.Complete(KErrNone);
		}
	}
コード例 #4
0
void CWin32Socket::GetPeerName(TWin32Message& aMessage) const
	{
	SOCKADDR_IN winSockAddress;
	TInt length = sizeof(struct sockaddr_in);
	if (getpeername(iSocket, (LPSOCKADDR)&winSockAddress, &length))
		{
		aMessage.Complete(MapWinSockError(WSAGetLastError()));
		}
	else
		{
		__ASSERT_DEBUG(length == sizeof(struct sockaddr_in), Panic(EWinSockPrtCWin32SocketGetPeerNameInvalidSocketAddress));
		TInetAddr& address = static_cast<TInetAddr&>(aMessage.WriteBuffer());
		ConvertAddress(winSockAddress, address);
		aMessage.Complete(KErrNone);
		}
	}
コード例 #5
0
ファイル: wskaddr.cpp プロジェクト: GarMeridian3/Meridian59
//
/// This function sets the network address.
//
void TINetSocketAddress::SetNetworkAddress(const char* addressDottedDecimal)
{
   SetNetworkAddress(ConvertAddress(addressDottedDecimal));
}
コード例 #6
0
ファイル: wskaddr.cpp プロジェクト: GarMeridian3/Meridian59
//
/// This function constructs an object. All arguments should be in network byte
/// ordering. nNewFamily is an enumeration, so there is no specific byte ordering.
/// \note The address can also be INADDR_ANY, INADDR_LOOPBACK, INADDR_BROADCAST, or
/// INADDR_NONE.
///
/// Also note that in Windows Sockets, Microsoft defines these addresses using
/// network byte ordering format. Therefore, you don't need to convert to network
/// byte ordering upon passing to this function, or when passing to any other
/// function that expects network byte ordering.
///
/// newPort should be passed in network byte ordering.  newAddress is in the
/// format of numerical IP addressing (e.g. "132.212.43.1").  It cannot be in
/// the form of "user\@place" nFamily is in the form of AF_INET, etc.
//
TINetSocketAddress::TINetSocketAddress(ushort newPort, const char* newAddressStr, ushort newFamily)
{
  ulong newAddress = ConvertAddress(newAddressStr);
  SetAddress(newFamily, newPort, newAddress);
}
コード例 #7
0
bool Cws_machineEx::doStartStop(IEspContext &context, StringArray& addresses, char* userName, char* password, bool bStop,
                                                     IEspStartStopResponse &resp)
{
    bool containCluster = false;
    double version = context.getClientVersion();
    const int ordinality= addresses.ordinality();

    UnsignedArray threadHandles;
    IArrayOf<IEspStartStopResult> resultsArray;

    for (int index=0; index<ordinality; index++)
    {
        const char* address0 = addresses.item(index);

        //address passed in is of the form "192.168.1.4:EspProcess:2:path1"
        StringArray sArray;
        sArray.appendList(addresses.item(index), ":");

        if (sArray.ordinality() < 4)
            throw MakeStringException(ECLWATCH_MISSING_PARAMS, "Incomplete arguments");

        Owned<IEspStartStopResult> pResult = static_cast<IEspStartStopResult*>(new CStartStopResult(""));
        const char* address = sArray.item(0);
        const char* compType= sArray.item(1);
        const char* OS        = sArray.item(3);//index 2 is component name
        const char* path      = sArray.item(4);

        if (!(address && *address && compType && *compType && OS && *OS && path && *path))
            throw MakeStringExceptionDirect(ECLWATCH_INVALID_INPUT, "Invalid input");

        if (!stricmp(compType, "ThorCluster") || !stricmp(compType, "RoxieCluster"))
            containCluster = true;

#ifndef OLD_START_STOP
        {
            char* configAddress = NULL;
            char* props1 = (char*) strchr(address, '|');
            if (props1)
            {
                configAddress = props1+1;
                *props1 = '\0';
            }
            else
            {
                configAddress = (char*) address;
            }

            StringBuffer newAddress;
            ConvertAddress(address0, newAddress);
            pResult->setAddressOrig ( newAddress.str() );//can be either IP or name of component
            pResult->setAddress ( address );//can be either IP or name of component
            pResult->setCompType( compType );
            if (version > 1.04)
            {       
                pResult->setName( path );
                const char* pStr2 = strstr(path, "LexisNexis");
                if (pStr2)
                {
                    char name[256];
                    const char* pStr1 = strchr(pStr2, '|');
                    if (!pStr1)
                    {
                        strcpy(name, pStr2+11);
                    }
                    else
                    {
                        strncpy(name, pStr2+11, pStr1 - pStr2 -11);
                        name[pStr1 - pStr2 -11] = 0;
                    }
                    pResult->setName( name );
                }   
            }
            
            pResult->setOS( atoi(OS) ); 
            pResult->setPath( path );

            resultsArray.append(*pResult.getLink());

            CStartStopThreadParam* pThreadReq;
            pThreadReq = new CStartStopThreadParam(address, configAddress, bStop, m_useDefaultHPCCInit, this, context);
            pThreadReq->setResultObject( pResult );

            if (userName && *userName)
                pThreadReq->setUserID( userName );
            if (password && *password)
                pThreadReq->setPassword( password );

            PooledThreadHandle handle = m_threadPool->start( pThreadReq );
            threadHandles.append(handle);
        }
#else
        {
            StringBuffer newAddress;
            ConvertAddress(address0, newAddress);
            char* pStr = (char*) strchr(address, '|');;
            if (pStr)
                pStr[0] = 0;

            pResult->setAddressOrig ( newAddress.str() );//can be either IP or name of component
            pResult->setAddress ( address );//can be either IP or name of component
            pResult->setCompType( compType );
            pResult->setOS( atoi(OS) ); 
            pResult->setPath( path );

            resultsArray.append(*pResult.getLink());

            CStartStopThreadParam* pThreadReq;
            pThreadReq = new CStartStopThreadParam(address, bStop, this, context);
            pThreadReq->setResultObject( pResult );

            if (userName && *userName)
                pThreadReq->setUserID( userName );
            if (password && *password)
                pThreadReq->setPassword( password );

            PooledThreadHandle handle = m_threadPool->start( pThreadReq );
            threadHandles.append(handle);
        }
#endif
    }

    //block for worker theads to finish, if necessary, and then collect results
    //
    PooledThreadHandle* pThreadHandle = threadHandles.getArray();
    unsigned i=threadHandles.ordinality();
    while (i--) 
    {
        m_threadPool->join(*pThreadHandle, 30000);//abort after 30 secs in remote possibility that the command blocks
        pThreadHandle++;
    }

    resp.setStartStopResults(resultsArray);
    resp.setStop(bStop);

    if (version > 1.08)
    {
        resp.setContainCluster(containCluster);
    }
    return true;
}
コード例 #8
0
ファイル: altRuntime.cpp プロジェクト: azusanakano/labo
///
/// \brief  Get stack trace
///
/// \return  Stack trace
///
LIBALT_API altStr altRuntime::GetStackTrace()
{
#ifdef ALT_WIN
  
  HANDLE  hProcess = ::GetCurrentProcess();
  HANDLE  hThread = ::GetCurrentThread();
#if 0
  DWORD dwOpts = ::SymGetOptions();
  ::SymSetOptions (dwOpts | SYMOPT_LOAD_LINES);
#endif
  if (! ::SymInitialize (hProcess, NULL, TRUE)) {
    return ("");
  }

  CONTEXT ctx;
  ctx.ContextFlags = CONTEXT_FULL;
  ctx.ContextFlags = CONTEXT_ALL;
  std::vector<DWORD> vAddrs;

  if (::GetThreadContext (hThread, & ctx)) {
    STACKFRAME  frame;
    DWORD       dwMachine;
    memset (& frame, 0x00, sizeof (frame));
    frame.AddrPC.Mode = AddrModeFlat;

    dwMachine = IMAGE_FILE_MACHINE_I386;
    frame.AddrPC.Offset = ctx.Eip;
    frame.AddrStack.Offset = ctx.Esp;
    frame.AddrFrame.Offset = ctx.Ebp;
    frame.AddrPC.Mode = AddrModeFlat;
    frame.AddrStack.Mode = AddrModeFlat;
    frame.AddrFrame.Mode = AddrModeFlat;

#if 0
    BOOL bRet = SymLoadModule (hProcess, NULL, (PSTR)sImageName.GetCStr(), NULL, 0, 0);
#endif
    for (DWORD dw = 0; dw < 512; dw++) {
      if (! ::StackWalk (dwMachine, hProcess, hThread, & frame, & ctx, NULL, SymFunctionTableAccess, SymGetModuleBase, NULL)) {
        break;
      }
      if (frame.AddrPC.Offset != 0) {
        vAddrs.push_back (frame.AddrPC.Offset);
      }
    }
  }

  altStr  sStackTrace;
  altStr  sSym;
  for (altUInt i = 0; i < vAddrs.size(); i++) {
    ConvertAddress (hProcess, vAddrs[i], sSym);
    sStackTrace += sSym;
  }
  SymCleanup (hProcess);

  return (sStackTrace);
#endif

#ifdef ALT_LINUX
  void *      ar[100];
  altInt      nSize = 0;
  altChar **  ppStrings;
  altStr      sStackTrace;

  nSize = backtrace (ar,100);
  ppStrings = backtrace_symbols (ar, nSize);
  for (altInt i = 1; i < nSize; i++) {
    sStackTrace += "\t";
    sStackTrace += ppStrings[i];
    sStackTrace += "\n";
  }
  free (ppStrings);
  return (sStackTrace);
#endif
}
コード例 #9
0
ファイル: stacktrace.cpp プロジェクト: Joincheng/lithtech
void DoStackTrace ( LPTSTR szString  ,
                    DWORD  dwSize    ,
                    DWORD  dwNumSkip  )
{
    HANDLE hProcess = GetCurrentProcess ( ) ;

    // If the symbol engine is not initialized, do it now.
    if ( FALSE == g_bSymIsInit )
    {
        DWORD dwOpts = SymGetOptions ( ) ;

        // Turn on load lines.
        SymSetOptions ( dwOpts                |
                        SYMOPT_LOAD_LINES      ) ;

        if ( FALSE == g_cSym.SymInitialize ( hProcess ,
                                             NULL     ,
                                             FALSE     ) )
        {
            //dsi_PrintToConsole("DoStackTrace : Unable to initialize the symbol engine!!!");
        }
        else
        {
            g_bSymIsInit = TRUE ;
        }
    }

    // The symbol engine is initialized so do the stack walk.

    // The array of addresses.
    ADDRVECTOR vAddrs ;

    // The thread information.
    CONTEXT    stCtx  ;

    stCtx.ContextFlags = CONTEXT_FULL ;

    if ( GetThreadContext ( GetCurrentThread ( ) , &stCtx ) )
    {
        STACKFRAME stFrame ;
        DWORD      dwMachine ;

        ZeroMemory ( &stFrame , sizeof ( STACKFRAME ) ) ;

        stFrame.AddrPC.Mode = AddrModeFlat ;

#ifdef _M_IX86
        dwMachine                = IMAGE_FILE_MACHINE_I386 ;
#else
		dwMachine				 = IMAGE_FILE_MACHINE_AMD64;
#endif
#ifdef _M_IX86
        stFrame.AddrPC.Offset    = stCtx.Eip    ;
        stFrame.AddrStack.Offset = stCtx.Esp    ;
#else
		stFrame.AddrPC.Offset	 = stCtx.Rip	;
		stFrame.AddrStack.Offset = stCtx.Rsp	;
#endif
        stFrame.AddrStack.Mode   = AddrModeFlat ;
#ifdef _M_IX86
        stFrame.AddrFrame.Offset = stCtx.Ebp    ;
#else
		stFrame.AddrFrame.Offset = stCtx.Rbp	;
#endif
        stFrame.AddrFrame.Mode   = AddrModeFlat ;

        // Loop for the first 512 stack elements.
        for ( DWORD i = 0 ; i < 512 ; i++ )
        {
            if ( FALSE == StackWalk ( dwMachine              ,
                                      hProcess               ,
                                      hProcess               ,
                                      &stFrame               ,
                                      &stCtx                 ,
                                      NULL                   ,
                                      SymFunctionTableAccess ,
                                      GetModBase             ,
                                      NULL                    ) )
            {
				// [KLS 4/5/02] The optimization bug doesn't occur if you touch the 
				// variable "i" here (e.g., call dsi_PrintToConsole("i = %d", i); )
				// ...I love compiler bugs ;)

				break ;
            }
            if ( i > dwNumSkip )
            {
                // Also check that the address is not zero.  Sometimes
                //  StackWalk returns TRUE with a frame of zero.
                if ( 0 != stFrame.AddrPC.Offset )
                {
                    vAddrs.push_back ( stFrame.AddrPC.Offset ) ;
                }
            }
        }

        // Now start converting the addresses.
        DWORD dwSizeLeft = dwSize ;
        DWORD dwSymSize ;

        TCHAR szSym [ MAX_PATH * 2 ] ;
        LPTSTR szCurrPos = szString ;

        ADDRVECTOR::iterator loop ;
        for ( loop =  vAddrs.begin ( ) ;
              loop != vAddrs.end ( )   ;
              loop++                     )
        {

            dwSymSize = ConvertAddress ( *loop , szSym ) ;
            if ( dwSizeLeft < dwSymSize )
            {
                break ;
            }
            _tcscpy ( szCurrPos , szSym ) ;
            szCurrPos += dwSymSize ;
            dwSizeLeft -= dwSymSize ;
        }
    }
}