예제 #1
0
//---------------------------------------------------------------------------------------
static void ProcessPGNCmd_Release( tGroupRegistration* pGroup, const tNmea2KMsg *pMsg, tcPgn65280NavicoData* pPgn )
{
    int result;

    UNUSED_PARAM( pMsg );

    if (pGroup->state == State_IsMaster)
    {
        // current master has given up
        assert( pMsg->sourceAddr == pGroup->master );

        result = AppCommand( pGroup, ArbitrationCmd_MasterQuit, pPgn->flags, pPgn->data24 );
        if (result == ARBITRATION_OK_ACQUIRE && IsAllowedToAcquire( pGroup ))
        {
            DoSend( pGroup, ArbitrationPGNCmd_Acquire );
        }
        else
        {
            pGroup->state = State_NoMaster;
            pGroup->timer = TIMEOUT_NOMASTER_FIRST;
        }
    }
    else if (pGroup->state == State_Master)
    {
        // assert my authority
        DoSend( pGroup, ArbitrationPGNCmd_Master );
    }
}
예제 #2
0
파일: TestPatch.cpp 프로젝트: edwig/Marlin
int TestPatching(HTTPClient* p_client)
{
  int errors = 0;

  // URL with resource and parameters
  CString url;
  url.Format("http://%s:%d/MarlinTest/Patching/FirstPatchTest?type=ab&rhesus=neg",MARLIN_HOST,TESTING_HTTP_PORT);

  // Test 1: Send through a HTTP-VERB Tunnel
  xprintf("TESTING STANDARD HTTP MESSAGE TO /Key2Test/Patching/\n");
  xprintf("======================================================\n");
  HTTPMessage* msg1 = new HTTPMessage(HTTPCommand::http_patch,url);
  msg1->SetBody("Example one: 56123\n"
                "Example two: 98127\n");
  // Test with or without HTTP-VERB tunneling
  msg1->SetVerbTunneling(true);
  // Set extra headers
  msg1->AddHeader("EdosHeader","16-05-1986");

  errors += DoSend(p_client,msg1);


  // Test 2: Now send as a RAW HTTP PATCH command
  HTTPMessage* msg2 = new HTTPMessage(HTTPCommand::http_patch,url);
  msg2->SetBody("Example one: 56123\n"
                "Example two: 98127\n");
  // Test with or without HTTP-VERB tunneling
  msg2->SetVerbTunneling(false);
  // Set extra headers
  msg2->AddHeader("EdosHeader","16-05-1986");

  errors += DoSend(p_client,msg2);

  return errors;
}
예제 #3
0
//---------------------------------------------------------------------------------------
static void ProcessPGNCmd_Acquire( tGroupRegistration* pGroup, const tNmea2KMsg *pMsg, tcPgn65280NavicoData* pPgn )
{
    int cmp;
    int result;
    eState state;

    state = pGroup->state;
    if (state != State_Acquire && state != State_Master)
        return;

    if (pGroup->statusFlags & (ArbitrationFlags_Watcher|ArbitrationFlags_NotSuitable))
    {
        assert( 0 );
        return;
    }

    cmp = ComparePriorities( pGroup, pMsg->sourceAddr, pPgn->flags, pPgn->data24 );
    if (cmp < 0)
    {
        // they are better than me
        if (state == State_Master)
        {
            // but I'm already master, see if we want to allow them to take over
            result = AppCommand( pGroup, ArbitrationCmd_MasterChallenge, pPgn->flags, pPgn->data24 );
            if (result == ARBITRATION_OK_RELEASE)
            {
                // we've had enough, let them take over
                MasterRelease( pGroup, tTrue );
            }
            else
            {
                // assert my authority
                DoSend( pGroup, ArbitrationPGNCmd_Master );
            }
        }
        else
        {
            // give up trying to be the master
            pGroup->state = State_Unknown;
            pGroup->timer = TIMEOUT_ACQUIRE_ABORTED;
            ClearSend( pGroup );
        }
    }
    else
    {
        assert( cmp > 0 );   //TODO: should never be the same, but what if it is?

        // assume I'm better than them
        if (state == State_Master)
        {
            // assert my authority
            DoSend( pGroup, ArbitrationPGNCmd_Master );
        }
    }
}
BOOL CNetPTCPConnection::OnEpollEvent(UINT EventID)
{
	if(m_Socket.IsConnected())
	{
		if(EventID&(EPOLLERR|EPOLLHUP))
		{
			PrintNetLog(0xffffffff,"CNetPTCPConnection::Epoll发生错误%d!",errno);
			Disconnect();
			return TRUE;
		}
		if(EventID&EPOLLIN)
		{
			DoRecv();
		}
		if(EventID&EPOLLOUT)
		{
			DoSend();
		}
	}
	else
	{
		PrintNetLog(0xffffffff,"(%d)Connection未连接,Epoll事件被忽略!",GetID());
	}


	return FALSE;
}
예제 #5
0
void CUdpServer::HandleZeroBytes(CONNID dwConnID, TUdpBufferObj* pBufferObj)
{
	if(pBufferObj->operation == SO_RECEIVE)
	{
		if(dwConnID == 0)
			dwConnID = HandleAccept(pBufferObj);
		
		if(dwConnID != 0)
		{
			TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID);

			if(TUdpSocketObj::IsValid(pSocketObj))
			{
				pSocketObj->detectFails = 0;
				DoSend(pSocketObj, nullptr, 0);
			}
			
			TRACE("<S-CNNID: %Iu> recv 0 bytes (detect package)\n", dwConnID);
		}

		DoReceive(pBufferObj);
	}
	else
	{
		ASSERT(dwConnID != 0);
		TRACE("<S-CNNID: %Iu> send 0 bytes (detect package)\n", dwConnID);
	}
}
예제 #6
0
void CClient::DoSend(unsigned short protocolID, unsigned long long clientTick, const char* text)
{
	char buf[_MSG_BUF_LEN];
	zsummer::protocol4z::WriteStream ws(buf, _MSG_BUF_LEN);
	ws << protocolID << clientTick << text;
	DoSend(buf, ws.GetWriteLen());
}
예제 #7
0
void CWin32Socket::Send(TWin32Message& aMessage)
	{
	__ASSERT_DEBUG((iSendMessage == NULL) && (iBytesSent == 0), Panic(EWinSockPrtCWin32SocketMultipleSendRequests));
	iSendMessage = &aMessage;
	WSP_LOG(WspLog::Printf(_L("CWin32Socket::Send: this: 0x%x, bytes to send: %d"), this, iSendMessage->ReadBuffer().Length()));
	DoSend();
	}
예제 #8
0
EnIocpAction CUdpServer::CheckIocpCommand(OVERLAPPED* pOverlapped, DWORD dwBytes, ULONG_PTR ulCompKey)
{
	EnIocpAction action = IOCP_ACT_GOON;

	if(pOverlapped == nullptr)
	{
		if(dwBytes == IOCP_CMD_SEND)
		{
			DoSend((CONNID)ulCompKey);
			action = IOCP_ACT_CONTINUE;
		}
		else if(dwBytes == IOCP_CMD_ACCEPT)
		{
			DoAccept();
			action = IOCP_ACT_CONTINUE;
		}
		else if(dwBytes == IOCP_CMD_DISCONNECT)
		{
			ForceDisconnect((CONNID)ulCompKey);
			action = IOCP_ACT_CONTINUE;
		}
		else if(dwBytes == IOCP_CMD_EXIT && ulCompKey == 0)
			action = IOCP_ACT_BREAK;
		else
			VERIFY(FALSE);
	}

	return action;
}
예제 #9
0
파일: zrcolafrm.cpp 프로젝트: Amebis/ZRCola
void wxZRColaFrame::OnSendDecomposed(wxCommandEvent& event)
{
    if (m_hWndSource)
        DoSend(m_panel->m_decomposed->GetValue());

    event.Skip();
}
예제 #10
0
void CClient::SendOnce()
{
	if (!m_bEstablished)
	{
		LOGD("client is dead. no send again");
		return;
	}
	DoSend(1, NOW_TIME, g_text);
	if (g_sendType != 0 && g_sendType != 0)
	{
		if (g_intervalMs > 0)
		{
			m_process.GetZSummer().CreateTimer(g_intervalMs, std::bind(&CClient::SendOnce, shared_from_this()));
		}
		else
		{
			if (m_lastDelayTime < 2000)
			{
				m_process.GetZSummer().Post(std::bind(&CClient::SendOnce, shared_from_this()));
			}
			else
			{
				m_process.GetZSummer().CreateTimer(100, std::bind(&CClient::SendOnce, shared_from_this()));
			}
		}
	}
}
예제 #11
0
//---------------------------------------------------------------------------------------
static void ProcessPGNCmd_WhoIsMaster( tGroupRegistration* pGroup, const tNmea2KMsg *pMsg, tcPgn65280NavicoData* pPgn )
{
    UNUSED_PARAM( pMsg );
    UNUSED_PARAM( pPgn );

    if (pGroup->state == State_Master)
        DoSend( pGroup, ArbitrationPGNCmd_Master );
}
예제 #12
0
int CUdpServer::DoSend(CONNID dwConnID)
{
	TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID);

	if(TUdpSocketObj::IsValid(pSocketObj))
		return DoSend(pSocketObj);

	return ERROR_OBJECT_NOT_FOUND;
}
예제 #13
0
int CTcpAgent::DoSend(CONNID dwConnID)
{
	TSocketObj* pSocketObj = FindSocketObj(dwConnID);

	if(TSocketObj::IsValid(pSocketObj))
		return DoSend(pSocketObj);

	return ERROR_OBJECT_NOT_FOUND;
}
예제 #14
0
/*
 *  @brief  EDP协议向自己透传数据,用于测试,将src_dev替换成目标DEVICE ID即可
 */
void Push_DataToMyself(void)
{
    EdpPacket* send_pkg;
    int8_t push_data[] = {44};
    printf("%s %d\n", __func__, __LINE__);
    send_pkg = PacketPushdata(src_dev, push_data, sizeof(push_data));
    DoSend(0, (const uint8_t *)send_pkg->_data, send_pkg->_write_pos);
    DeleteBuffer(&send_pkg);
    mDelay(1000);
}
예제 #15
0
  bool Producer::HandleSend(const string& topic_name, int partition_id,
                            const vector<string> &msgs)
  {
    int32_t broker_id = topic_info_.GetBrokerId(topic_name, partition_id);
    if (broker_id == -1) return false;

    BrokerChannel *channel = broker_pool_.GetBrokerChannel(broker_id);
    int remaining_tries = max_retries_;
    do {
      if (DoSend(channel, topic_name, partition_id, msgs)) {
        if (CheckResponse(channel, topic_name, partition_id)) {
          return true;
        }
      } else {
        std::cerr << "Error in sending data." << std::endl;
        break;
      }
    } while(--remaining_tries);

    // This could ne potential used by multiple threads and hence could
    // block if waiting for a lock.
    if (!topic_info_.UpdateInfo(topic_name)) {
      std::cerr << "Failed to update topic info. " << std::endl;
      return false;
    }
    // Update Broker pool.
    broker_pool_.UpdatePool(topic_info_);  // COPY of topic_info_ is passed.
    remaining_tries = max_retries_;
    broker_id = topic_info_.GetBrokerId(topic_name, partition_id);
    if (broker_id == -1) return false;
    channel = broker_pool_.GetBrokerChannel(broker_id);

    do {
      if (DoSend(channel, topic_name, partition_id, msgs)) {
        if (CheckResponse(channel, topic_name, partition_id)) {
          return true;
        }
      }
    } while(--remaining_tries);

    return false;
  }
예제 #16
0
//---------------------------------------------------------------------------------------
int ArbitrationBecomeMaster( tArbitrationGroupID groupID )
{
    tGroupRegistration* pGroup = FindGroupRegistration( groupID );
    if (pGroup == NULL)
        return ARBITRATION_ERROR_INVALID_GROUP;

    if (pGroup->state == State_Master)
        return ARBITRATION_ERROR_WE_ARE_MASTER;

    if (pGroup->state != State_Acquire)
        DoSend( pGroup, ArbitrationPGNCmd_Acquire );
    return ARBITRATION_OK;
}
예제 #17
0
/*
 *  @brief  发送PING包维持心跳
 */
void Ping_Server(void)
{
    EdpPacket *send_pkg;
    printf("%s %d\n", __func__, __LINE__);
    /* 组装ping包 */
    send_pkg = PacketPing();

    DoSend(0, (const uint8_t *)send_pkg->_data,
           send_pkg->_write_pos);
    mDelay(500);
    /* 必须释放这个内存,否则造成泄露 */
    DeleteBuffer(&send_pkg);
    mDelay(100);
}
예제 #18
0
BOOL CUdpServer::Send(CONNID dwConnID, const BYTE* pBuffer, int iLength)
{
	ASSERT(pBuffer && iLength > 0 && iLength <= (int)m_dwMaxDatagramSize);

	if(!pBuffer || iLength <= 0 || iLength > (int)m_dwMaxDatagramSize)
		return FALSE;

	TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID);

	if(pSocketObj == nullptr)
		return FALSE;

	DoSend(pSocketObj, pBuffer, iLength);
	
	return TRUE;
}
// actions
void CPingController::SendFirstRequestL()
{
	iPingCount = 0;
	iPingControllerState = ESendTo;
	InitSocket();

	if (iRemoteAddr.Input(iRemote)!= KErrNone)
	{
		iObserver->NotifyErrorL(KErrArgument);
		return; //?
	}
	delete iIcmpPacket;
	iIcmpPacket = CEchoPacket::NewL(GetTime(), iDataSize);
	
	DoSend();
}
예제 #20
0
BOOL CTcpServer::Send(CONNID dwConnID, const BYTE* pBuffer, int iLength)
{
	ASSERT(pBuffer && iLength > 0);

	TSocketObj* pSocketObj = FindSocketObj(dwConnID);

	if(!TSocketObj::IsValid(pSocketObj))
		return FALSE;

	int result = DoSend(dwConnID, pSocketObj, pBuffer, iLength);

	if(result != NO_ERROR)
		CheckError(dwConnID, SO_SEND, result);

	return (result == NO_ERROR);
}
예제 #21
0
/*
 *  @brief  EDP协议向Onenet上传湿度信息,数据点格式TYPE=3
 */
void Save_HumToOneNet(void)
{
    EdpPacket* send_pkg;
    uint16_t hum[1];
    SHT20_read_user_reg();
    mDelay(200);//延迟,设备没有那么快的响应时间,否则总线处理忙等待
    SHT2x_MeasureHM(SHT20_Measurement_RH_NHM, hum);

    printf("%s %d hum:%d\n", __func__, __LINE__, (uint32_t)hum[0]);

    send_pkg = PacketSavedataInt(kTypeSimpleJsonWithoutTime, NULL, "hum", (uint32_t)hum[0], 0, NULL);

    DoSend(0, (const uint8_t *)send_pkg->_data, send_pkg->_write_pos);
    DeleteBuffer(&send_pkg);
    mDelay(1000);
}
예제 #22
0
int CTcpNetHandler::HandleEvent(int iConn, int iType) {
	switch (iType) {
	case TCP_SERVER_ACCEPT:
		DoConn(iConn);
		break;
	case TCP_SERVER_READ:
		DoRecv(iConn);
		break;
	case TCP_SERVER_SEND:
		DoSend(iConn);
		break;
	case TCP_SERVER_CLOSE:
		DoClose(iConn);
		break;
	}
	return 0;
}
예제 #23
0
void Connection::OnSend() {
	_sending = false;

	u32 size = 0;
	char * buf = RingBufferRead(_sendBuf, &size);
	if (buf && size > 0) {
		if (!DoSend()) {
			CloseForce();
			return;
		}
		_sending = true;
	}
	else {
		if (_closing)
			CloseForce();
	}
}
예제 #24
0
void Connection::Send(const void * context, const s32 size) {
	if (_closing)
		return;

	if (!RingBufferWriteBlock(_sendBuf, context, size)) {
		Close();
		return;
	}
	
	if (!_sending) {
		if (!DoSend())
			CloseForce();
		else {
			_sending = true;
		}
	}
}
예제 #25
0
EnIocpAction CTcpAgent::CheckIocpCommand(OVERLAPPED* pOverlapped, DWORD dwBytes, ULONG_PTR ulCompKey)
{
	ASSERT(pOverlapped == nullptr);

	EnIocpAction action = IOCP_ACT_CONTINUE;

		if(dwBytes == IOCP_CMD_SEND)
			DoSend((CONNID)ulCompKey);
		else if(dwBytes == IOCP_CMD_DISCONNECT)
			ForceDisconnect((CONNID)ulCompKey);
		else if(dwBytes == IOCP_CMD_EXIT && ulCompKey == 0)
			action = IOCP_ACT_BREAK;
		else
			VERIFY(FALSE);

	return action;
}
예제 #26
0
BOOL CNetPTCPConnection::QuerySend(LPCVOID pData,int Size)
{
	//CAutoLock Lock(m_EasyCriticalSection);


	if(m_Socket.IsConnected())
	{
		while(Size)
		{
			int PacketSize=Size;
			if(PacketSize>MAX_DATA_PACKET_SIZE)
				PacketSize=MAX_DATA_PACKET_SIZE;
			Size-=PacketSize;

			CEpollEventObject * pEpollEventObject=GetServer()->CreateEventObject();
			if(pEpollEventObject==NULL)
			{
				PrintNetLog(0xffffffff,"Connection创建Send用OverLappedObject失败!");
				return FALSE;
			}

			pEpollEventObject->SetType(IO_SEND);
			pEpollEventObject->GetDataBuff()->SetUsedSize(0);
			pEpollEventObject->SetParentID(GetID());

			if(!pEpollEventObject->GetDataBuff()->PushBack(pData,PacketSize))
			{
				GetServer()->DeleteEventObject(pEpollEventObject);
				PrintNetLog(0xffffffff,"Connection要发送的数据包过大!");
				return FALSE;
			}
			pData=(char *)pData+PacketSize;

			if(!m_SendQueue.PushBack(pEpollEventObject))
			{
				PrintNetLog(0xffffffff,"CNetPTCPConnection::发送队列已满!");
				GetServer()->DeleteEventObject(pEpollEventObject);
				Disconnect();
				return FALSE;
			}
		}
		DoSend();
		return TRUE;
	}
	return FALSE;
}
예제 #27
0
void CUdpServer::HandleSend(CONNID dwConnID, TUdpBufferObj* pBufferObj)
{
	if(FireSend(dwConnID, (BYTE*)pBufferObj->buff.buf, pBufferObj->buff.len) == HR_ERROR)
	{
		TRACE1("<S-CNNID: %Iu> OnSend() event should not return 'HR_ERROR' !!\n", dwConnID);
		ASSERT(FALSE);
	}

	AddFreeBufferObj(pBufferObj);

	TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID);

	if(TUdpSocketObj::IsValid(pSocketObj))
	{
		long sndCount = ::InterlockedDecrement(&pSocketObj->sndCount);
		if(sndCount == 0) DoSend(pSocketObj);
	}
}
예제 #28
0
EnIocpAction CTcpServer::CheckIocpCommand(OVERLAPPED* pOverlapped, DWORD dwBytes, ULONG_PTR ulCompKey)
{
	ASSERT(pOverlapped == nullptr);

	EnIocpAction action = IOCP_ACT_CONTINUE;
	CONNID dwConnID		= (CONNID)ulCompKey;

	switch(dwBytes)
	{
	case IOCP_CMD_SEND		: DoSend(dwConnID)			; break;
	case IOCP_CMD_ACCEPT	: DoAccept()				; break;
	case IOCP_CMD_DISCONNECT: ForceDisconnect(dwConnID)	; break;
	case IOCP_CMD_EXIT		: action = IOCP_ACT_BREAK	; break;
	default					: CheckError(FindSocketObj(dwConnID), SO_CLOSE, (int)dwBytes);
	}

	return action;
}
예제 #29
0
void Connect_RequestType1(int8_t *devid, int8_t *api_key)
{
    EdpPacket *send_pkg;

    send_pkg = PacketConnect1((const int8_t *)devid, (const int8_t *)api_key);
    if(send_pkg == NULL)
    {
        return;
    }
    /* send_pkg = PacketConnect2("433223", "{ \"SYS\" : \"0DEiuApATHgLurKNEl6vY4bLwbQ=\" }"); */
    /* send_pkg = PacketConnect2("433223", "{ \"13982031959\" : \"888888\" }"); */

    /* 向设备云发送连接请求 */
    printf("send connect to server, bytes: %d\n", send_pkg->_write_pos);
    DoSend(0, (const uint8_t *)send_pkg->_data, send_pkg->_write_pos);
    /* 必须释放这个内存,否则造成泄露 */
    DeleteBuffer(&send_pkg);
    mDelay(1000);
}
예제 #30
0
void CClient::MessageEntry(zsummer::protocol4z::ReadStream & rs)
{
	//协议流异常会被上层捕获并关闭连接
	unsigned short protocolID = 0;
	rs >> protocolID;
	switch (protocolID)
	{
	case 1:
		{
			unsigned long long clientTick = 0;
			m_recvTextCache.clear();
			rs >> clientTick >> m_recvTextCache;
			if (g_startType == 0)
			{
				DoSend(protocolID, clientTick, m_recvTextCache.c_str());
			}
			else
			{
				unsigned long long tick = NOW_TIME;
				if (tick < clientTick)
				{
					LOGE("now time[" << tick << "] < last time[" << clientTick << "].");
					throw std::runtime_error("now time < last time");
				}
				tick -= clientTick;
				m_lastDelayTime = tick;
				m_process.AddTotalEcho(1);
				m_process.AddTotalEchoTime(tick);
				if (g_sendType == 0)
				{
					SendOnce();
				}
			}
		}
		break;
	default:
		{
			LOGI("unknown protocol id = " << protocolID);
		}
		break;
	}
}