void UDPConnection::Update()
{
	if (!sharedSocket)
	{
		unsigned recv = 0;
		unsigned char buffer[UDPBufferSize];
		sockaddr_in fromAddr;
		while ((recv = mySocket->RecvFrom(buffer, UDPBufferSize, &fromAddr)) >= hsize)
		{
			RawPacket* data = new RawPacket(buffer, recv);
			if (CheckAddress(fromAddr))
				ProcessRawPacket(data);
			else
				; // silently drop
		}
	}
	
	const unsigned curTime = SDL_GetTicks();
	bool force = false;	// should we force to send a packet?

	if((dataRecv == 0) && lastSendTime < curTime-1000 && !unackedPackets.empty()){		//server hasnt responded so try to send the connection attempt again
		SendRawPacket(unackedPackets[0].data,unackedPackets[0].length,0);
		lastSendTime = curTime;
		force = true;
	}

	if (lastSendTime<curTime-5000 && !(dataRecv == 0)) { //we havent sent anything for a while so send something to prevent timeout
		force = true;
	}
	else if(lastSendTime<curTime-200 && !waitingPackets.empty()){	//we have at least one missing incomming packet lying around so send a packet to ensure the other side get a nak
		force = true;
	}

	Flush(force);
}
示例#2
0
size_t GetFileLineFromAddress(void* address, char* fileName, size_t size,
                              size_t* lineNumber, size_t* offsetBytes)
{
    if (size) *fileName = 0;
    if (lineNumber) *lineNumber = 0;
    if (offsetBytes) *offsetBytes = 0;
    {
        char* sourceName;
        IMAGEHLP_LINE line = { sizeof (line) };
        GC_ULONG_PTR dwOffset = 0;
        if (!SymGetLineFromAddr(GetSymHandle(), CheckAddress(address), &dwOffset,
                                &line)) {
            return 0;
        }
        if (lineNumber) {
            *lineNumber = line.LineNumber;
        }
        if (offsetBytes) {
            *offsetBytes = dwOffset;
        }
        sourceName = line.FileName;
        /* TODO: resolve relative filenames, found in 'source directories'  */
        /* registered with MSVC IDE.                                        */
        if (size) {
            strncpy(fileName, sourceName, size)[size - 1] = 0;
        }
        return strlen(sourceName);
    }
}
示例#3
0
void DoCheck (const PolyWord pt)
{
    if (pt == PolyWord::FromUnsigned(0)) return;

    if (pt.IsTagged()) return;

    CheckAddress(pt.AsStackAddr());
} 
示例#4
0
uint8_t Bowler_Server_Local(BowlerPacket * Packet){
  
        Print_Level l = getPrintLevel();
        //setPrintLevelNoPrint();
	if (GetBowlerPacket_arch(Packet)){
		//setLed(1,1,1);
                if(Packet->use.head.RPC != _PNG){
                    println_I("Got:");printPacket(Packet,INFO_PRINT);
                }
		if ( (CheckAddress(MyMAC.v,Packet->use.head.MAC.v) == true)  || ((CheckAddress((uint8_t *)Broadcast.v,(uint8_t *)Packet->use.head.MAC.v) == true)  )) {
                        float start=getMs();
                        Process_Self_Packet(Packet);
                        if(getMs()-start>5){
                            println_E("Process too long: ");p_fl_E(getMs()-start);
                        }
			for (i=0;i<6;i++){
				Packet->use.head.MAC.v[i]=MyMAC.v[i];
			}
			SetCRC(Packet);
                        start=getMs();
			PutBowlerPacket(Packet);
                        if(getMs()-start>5){
                            println_E("Return too long: ");p_fl_E(getMs()-start);
                        }
                         if(Packet->use.head.RPC != _PNG){
                            println_I("Response:");printPacket(Packet,INFO_PRINT);
                         }
		}else{
			//println_I("Packet not addressed to me: ");printByteArray(Packet->use.head.MAC.v,6); print_I(" is not mine: ");printByteArray(MyMAC.v,6);
		}
		//setLed(0,0,1);
                setPrintLevel(l);
		return true; 
	}//Have a packet
        setPrintLevel(l);
	return false; 
}
示例#5
0
void DoCheckObject (const PolyObject *base, POLYUNSIGNED L)
{

    PolyWord *pt  = (PolyWord*)base;
    CheckAddress(pt);
    MemSpace *space = gMem.SpaceForAddress(pt-1);
    if (space == 0)
        Crash ("Bad pointer 0x%08" PRIxPTR " found", (uintptr_t)pt);

    ASSERT (OBJ_IS_LENGTH(L));

    POLYUNSIGNED n   = OBJ_OBJECT_LENGTH(L);
    if (n == 0) return;

    ASSERT (n > 0);
    ASSERT(pt-1 >= space->bottom && pt+n <= space->top);

    byte flags = GetTypeBits(L);  /* discards GC flag and mutable bit */

    if (flags == F_BYTE_OBJ) /* possibly signed byte object */
        return; /* Nothing more to do */

    if (flags == F_CODE_OBJ) /* code object */
    {
        ScanCheckAddress checkAddr;
        /* We flush the instruction cache here in case we change any of the
          instructions when we update addresses. */
        machineDependent->FlushInstructionCache(pt, (n + 1) * sizeof(PolyWord));
        machineDependent->ScanConstantsWithinCode((PolyObject *)base, (PolyObject *)base, n, &checkAddr);
        /* Skip to the constants. */
        base->GetConstSegmentForCode(n, pt, n);
    }
    else if (flags == F_CLOSURE_OBJ)
    {
        n -= sizeof(PolyObject*) / sizeof(PolyWord);
        pt += sizeof(PolyObject*) / sizeof(PolyWord);
    }
    else ASSERT (flags == 0); /* ordinary word object */

    while (n--) DoCheck (*pt++);
}
示例#6
0
文件: msvc_dbg.c 项目: 97jaz/racket
size_t GetModuleNameFromAddress(void* address, char* moduleName, size_t size)
{
	if (size) *moduleName = 0;
	{
		const char* sourceName;
		IMAGEHLP_MODULE moduleInfo = { sizeof (moduleInfo) };
		if (!SymGetModuleInfo(GetSymHandle(), CheckAddress(address), &moduleInfo)) {
			return 0;
		}
		sourceName = strrchr(moduleInfo.ImageName, '\\');
		if (sourceName) {
			sourceName++;
		} else {
			sourceName = moduleInfo.ImageName;
		}
		if (size) {
			strncpy(moduleName, sourceName, size)[size - 1] = 0;
		}
		return strlen(sourceName);
	}
}
示例#7
0
size_t GetSymbolNameFromAddress(void* address, char* symbolName, size_t size,
                                size_t* offsetBytes)
{
    if (size) *symbolName = 0;
    if (offsetBytes) *offsetBytes = 0;
    __try {
        ULONG_ADDR dwOffset = 0;
        union {
            IMAGEHLP_SYMBOL sym;
            char symNameBuffer[sizeof(IMAGEHLP_SYMBOL) + MAX_SYM_NAME];
        } u;
        u.sym.SizeOfStruct  = sizeof(u.sym);
        u.sym.MaxNameLength = sizeof(u.symNameBuffer) - sizeof(u.sym);

        if (!SymGetSymFromAddr(GetSymHandle(), CheckAddress(address), &dwOffset,
                               &u.sym)) {
            return 0;
        } else {
            const char* sourceName = u.sym.Name;
            char undName[1024];
            if (UnDecorateSymbolName(u.sym.Name, undName, sizeof(undName),
                                     UNDNAME_NO_MS_KEYWORDS | UNDNAME_NO_ACCESS_SPECIFIERS)) {
                sourceName = undName;
            } else if (SymUnDName(&u.sym, undName, sizeof(undName))) {
                sourceName = undName;
            }
            if (offsetBytes) {
                *offsetBytes = dwOffset;
            }
            if (size) {
                strncpy(symbolName, sourceName, size)[size - 1] = 0;
            }
            return strlen(sourceName);
        }
    } __except (EXCEPTION_EXECUTE_HANDLER) {
        SetLastError(GetExceptionCode());
    }
    return 0;
}
/**This should get called every time a new byte is availible from the UART.
 * @param byte the new byte that just arrived.
 */
void OnByteRecieved(const unsigned char byte)
{
  //Check the interframe spacing.
  //If it has been more than that time it is either an error or a new packet.
  //also check if we arent recieving a message at all.
  //Either of these conditions indicate that this byte could be the start of a new character.
  if (((TimeSinceLastByteWasRecieved() >= CurrentTimeOut)) | !(RecievingMessage))

  {
    //A byte time of silence or more always delimits packets
    //So reset the recieve pointer to clear any garbage and reset the hash state.
    RecievePointer = 0;
    HashState = 0;


    //Consider this the start of a new packet ONLY if it matches the valid start code
    //And ONLY if the required interframe distance has been met or exceeded.
    //This lets us send one byte messages outside of a full packet
    if (byte == 0x55)
    {
      RecievingMessage = 1;
    }
    else
    {
      //If we don't see the valid start code we stay idle
      RecievingMessage = 0;
    }
    return;
  }

  //Only if a valid start code was detected at the start should we enter the byte in the buffer.
  else
  {
    RecieveBuffer[RecievePointer] = byte;
    RecievePointer++;
    //Update the checksum as we go so we don't have to do one huge batch of calculations
    //At the end, which would suck for realtime performance.

    //Also dont CRC the CRC because that would
    //not make sense unless we did that weird crc(message +crc)=0 thing
    if (!((RecievePointer >= (RecieveBuffer[LENGTH_OFFSET]-1)) &(RecievePointer>LENGTH_OFFSET)))
    {

      HashUpdate(byte);
    }



    //Not only check and see if we have as mny bytes as the length field says,
    //But also check that we even have the length field.
    if ((RecievePointer >= RecieveBuffer[LENGTH_OFFSET]) &(RecievePointer>LENGTH_OFFSET))
    {
      //If we have recieved a complete message, Check the checksum.
      //	DisableReciever(); //We must re enable this to be ready for the next packet.
      RecievingMessage = 0;
      //Do nothing with the packet if we have just been waiting for the end of it.

      if (CheckAddress(RecieveBuffer))
      {
        //Don't do anything with incorrect packets, they are bad.

        if (GetByteOf(0,HashState ) == RecieveBuffer[RecievePointer-1])
        {
          if(GetByteOf(1,HashState) == RecieveBuffer[RecievePointer-2])
          {
            HandleNewPacket(RecieveBuffer);
          }
        }
      }

    }
  }
}
MdErrEnum MdDataDeal(Md_Tcp_Dep *Tcp)
{

    MdErrEnum ret;
   //  1. 地址判断
    #define MD_DEV_ADDR_CHK
    if(CheckAddress(Tcp))
    {
        return MD_DEV_ADDR_ERR;
    }
//  2. 判断命令
    #define MD_CMD_CHK
    if(Tcp->RawData[MD_DEV_CMD_INDEX] != MD_CMD_WRP && 
       Tcp->RawData[MD_DEV_CMD_INDEX] != MD_CMD_WR && 
       Tcp->RawData[MD_DEV_CMD_INDEX] != MD_CMD_RD)
    {
        return MD_CMD_ERR;
    }
//  3. 判断CRC
    #define MD_CRC_CHK
    if(1)
    {
        uint16 tmpCRC1 = GetCRC16(Tcp->RawData,Tcp->RawDataLen-2);
        uint16 tmpCRC2 = Tcp->RawData[Tcp->RawDataLen-1]*256+Tcp->RawData[Tcp->RawDataLen-2];
        if(tmpCRC1 != tmpCRC2)
        {
            return  MD_CRC_ERR;
        }
    }
//  3. 判断包总长度
    if(Tcp->RawData[MD_DEV_CMD_INDEX] == MD_CMD_WRP||
       Tcp->RawData[MD_DEV_CMD_INDEX] == MD_CMD_WR)
    {
        #define MD_WRITINGING_TOTAL_CHK
        if(Tcp->RawDataLen == MD_SHORT_CMD_LEN)
        {
            ;
        }
        else if (Tcp->RawDataLen == (MD_0X10_EXTRA_BYTE+Tcp->RawData[MD_0X03_TRG_NUM_INDEX]) &&
                 (Tcp->RawData[MD_0X03_TRG_NUM_INDEX] == (Tcp->RawData[MD_0X03_TRG_NUM_INDEX-1]*2)))
        {
            ;
        }
        else
        {
            return  MD_WRITE_TOTAL_LEN_ERR;
        }
    }
    else
    {
        #define MD_READING_TOTAL_CHK
        if(Tcp->RawDataLen == MD_SHORT_CMD_LEN)
        {
            ;
        }
        else if (Tcp->RawDataLen == (MD_0X03_EXTRA_BYTE+Tcp->RawData[MD_0X03_RSP_NUM_INDEX]))
        {
            ;
        }
        else
        {
            return  MD_READ_TOTAL_LEN_ERR;
        }
    }
    


//  4. 判断命令长度
    #define MD_LEN_CHK_SHORT
    if(Tcp->RawDataLen == MD_SHORT_CMD_LEN)
    {
        if(Tcp->RawData[MD_DEV_CMD_INDEX] == MD_CMD_WRP||
           Tcp->RawData[MD_DEV_CMD_INDEX] == MD_CMD_WR)
        {
            //NO ECHO
            return  MD_ERR_OK;
        }
        else
        {
            #define MD_READING_RSP
            uint16 trgaddr   = Tcp->RawData[MD_0X10_TRG_ADDR_INDEX]*256+Tcp->RawData[MD_0X10_TRG_ADDR_INDEX+1];
            uint16 length     = Tcp->RawData[MD_0X10_TRG_LEN_INDEX+1];

            ret = (*Tcp->LenChkCheck)(trgaddr,length);
            if(ret != MD_ERR_OK)
            {
               return ret;
            }
            
            // Data Setup
            Tcp->rePkglen=Slave_ModbusDataSetup(Tcp);
            return  MD_ERR_OK;
        }
    }

//  5. 按需要回复
    #define MD_LEN_CHK_LONG
    if(Tcp->RawData[MD_DEV_CMD_INDEX] == MD_CMD_WRP||
       Tcp->RawData[MD_DEV_CMD_INDEX] == MD_CMD_WR)
    {
        //slave data deal
        #define SLAVE_DATA_DEAL
        uint16 trgaddr   = Tcp->RawData[MD_0X10_TRG_ADDR_INDEX]*256+Tcp->RawData[MD_0X10_TRG_ADDR_INDEX+1];
        uint16 length     = Tcp->RawData[MD_0X10_TRG_LEN_INDEX]*256+Tcp->RawData[MD_0X10_TRG_LEN_INDEX+1];

        ret = (*Tcp->LenChkCheck)(trgaddr,length);
        if(ret != MD_ERR_OK)
        {
           return ret;
        }
        //数据处理
        #define DATA_WRITING
        if( 1 )
        {
            uint16 itmp;
            uint16 tmpindex = MD_MST_DATA_INDEX;
            uint08 tmp;
            for(tmp=0;tmp<length;tmp++)
            {
                itmp = Tcp->p2trg[tmpindex++]*256;
                itmp +=Tcp->p2trg[tmpindex++];
                (*Tcp->WrData)((trgaddr+tmp),itmp);
            }
        }
        

        //长的,写命令,回复一个短回复
        Tcp->rePkglen=Slave_ModbusDataSetup(Tcp);
        return  MD_ERR_OK;
    }
    else
    {
        //长的,读命令,不需要回复
        //NO ECHO
        
        return  MD_ERR_OK;
    }
    
}
    void
    QualityOfServiceData::ReadDistributionChannels()
    {
        //insert Local channel first
        m_DistributionChannelNameTable.insert(std::make_pair(L"Local",LOCAL_DISTRIBUTION_CHANNEL));

        int nextChannelNumber = SYSTEM_DISTRIBUTION_CHANNEL; //start at 64. System must always get this number
        try
        {
            for (int ix = 0; ix < Dob::DistributionChannelParameters::DistributionChannelsArraySize(); ++ix)
            {
                Dob::DistributionChannelPtr channelItem = Dob::DistributionChannelParameters::DistributionChannels(ix);

                const std::wstring name = channelItem->Name().GetVal();
                if (name.empty())
                {
                    throw Dob::Typesystem::ConfigurationErrorException(L"Illegal distribution channel name",__WFILE__,__LINE__);
                }

                boost::uint64_t includedNodes;
                int numNodesInChannel;
                int theSingleNode; //is only used when numNodesInChannel == 1
                ConvertNodesString(channelItem->IncludedNodes().GetVal(),includedNodes,numNodesInChannel, theSingleNode);

                lllout << LLL_PREFIX << "Read DistributionChannel '" << name << "' ";

                //special handling for the System distribution channel.
                if (ix == 0)
                {
                    //check that the first one is System
                    if(name != L"System")
                    {
                        throw Dob::Typesystem::ConfigurationErrorException(L"System must be first defined distribution channel",__WFILE__,__LINE__);
                    }

                    const std::string multicastAddress = channelItem->MulticastAddress().Utf8String();
                    if (multicastAddress == "127.0.0.1")
                    {
                        m_bIsStandalone = true;
                        lllout << " which is local (all messages will be local and no other channels or priorities will be read)" <<std::endl;
                        return;
                    }
                }
                if (ix == 1)
                {
                    //check that the second one is PoolDistribution
                    if(name != L"PoolDistribution")
                    {
                        throw Dob::Typesystem::ConfigurationErrorException(L"PoolDistribution must be second defined distribution channel",__WFILE__,__LINE__);
                    }
                }

                if (numNodesInChannel == 0)
                {
                    throw Dob::Typesystem::ConfigurationErrorException(L"Channel must contain at least one node",__WFILE__,__LINE__);
                }
                else if (numNodesInChannel == 1)
                {
                    //is this node the single node --> use Local
                    const int nodeId=Dob::ThisNodeParameters::NodeNumber();
                    if (theSingleNode == nodeId)
                    {
                        m_DistributionChannelNameTable.insert(std::make_pair(name,LOCAL_DISTRIBUTION_CHANNEL));
                        lllout <<  "which is this node, so data will be local" << std::endl;
                    }
                    else
                    {
                        //use singlecast for this distribution channel name
                        m_DistributionChannelNameTable.insert(std::make_pair(name,theSingleNode));
                        lllout << "which will use singlecast to node " << theSingleNode <<std::endl;
                    }
                }
                else
                {
                    const std::string multicastAddress = channelItem->MulticastAddress().Utf8String();
                    if (!CheckAddress(multicastAddress))
                    {
                        throw Dob::Typesystem::ConfigurationErrorException(std::wstring(L"Illegal multicast address: ") +
                                                                           channelItem->MulticastAddress().GetVal(),__WFILE__,__LINE__);
                    }

                    m_DistributionChannelTable.insert(std::make_pair
                                                      (nextChannelNumber,DistributionChannelData(includedNodes,multicastAddress)));
                    m_DistributionChannelNameTable.insert(std::make_pair(name,nextChannelNumber));

                    ++nextChannelNumber;

                    lllout << " (id="
                             << nextChannelNumber - 1
                             << ") with included nodes '"
                             << std::hex << includedNodes << std::dec
                             << "'" <<std::endl;
                }
            }

        }
        catch (const Dob::Typesystem::FundamentalException &)
        {
            std::wcout << "Failed to read QoS DistributionChannel parameters" <<std::endl;
            throw;
        }
    }
示例#11
0
 virtual PolyObject *ScanObjectAddress(PolyObject *pt) { CheckAddress((PolyWord*)pt); return pt; }