• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ UDPSocket类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中UDPSocket的典型用法代码示例。如果您正苦于以下问题:C++ UDPSocket类的具体用法?C++ UDPSocket怎么用?C++ UDPSocket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了UDPSocket类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: test_bring_up_down

void test_bring_up_down() {
    NetworkInterface* net = MBED_CONF_APP_OBJECT_CONSTRUCTION;

    for (int i = 0; i < COUNT; i++) {
        int err = MBED_CONF_APP_CONNECT_STATEMENT;
        TEST_ASSERT_EQUAL(0, err);

        printf("MBED: IP Address %s\r\n", net->get_ip_address());
        TEST_ASSERT(net->get_ip_address());

        UDPSocket udp;
        err = udp.open(net);
        TEST_ASSERT_EQUAL(0, err);
        err = udp.close();
        TEST_ASSERT_EQUAL(0, err);

        TCPSocket tcp;
        err = tcp.open(net);
        TEST_ASSERT_EQUAL(0, err);
        err = tcp.close();
        TEST_ASSERT_EQUAL(0, err);

        err = net->disconnect();
        TEST_ASSERT_EQUAL(0, err);
    }
}
开发者ID:Archcady,项目名称:mbed-os,代码行数:26,代码来源:main.cpp


示例2: use_connection

/**
 * Use a connection, checking that it is good
 * Checks via doing an NTP transaction
 */
static void use_connection(OnboardCellularInterface *driver)
{
    const char *ip_address = driver->get_ip_address();
    const char *net_mask = driver->get_netmask();
    const char *gateway = driver->get_gateway();

    TEST_ASSERT(driver->is_connected());

    TEST_ASSERT(ip_address != NULL);
    tr_debug("IP address %s.", ip_address);
    TEST_ASSERT(net_mask != NULL);
    tr_debug("Net mask %s.", net_mask);
    TEST_ASSERT(gateway != NULL);
    tr_debug("Gateway %s.", gateway);

    UDPSocket sock;
    SocketAddress host_address;

    TEST_ASSERT(driver->gethostbyname(MBED_CONF_APP_ECHO_SERVER, &host_address) == 0);
    host_address.set_port(MBED_CONF_APP_ECHO_UDP_PORT);

    tr_debug("UDP: Server %s address: %s on port %d.",
             MBED_CONF_APP_ECHO_SERVER, host_address.get_ip_address(),
             host_address.get_port());

    TEST_ASSERT(sock.open(driver) == 0)

    sock.set_timeout(10000);
    do_udp_echo(&sock, &host_address, 1);

    sock.close();
}
开发者ID:MarceloSalazar,项目名称:mbed-os,代码行数:36,代码来源:main.cpp


示例3: main

int main (void) {
    MBED_HOSTTEST_TIMEOUT(20);
    MBED_HOSTTEST_SELECT(udpecho_server_auto);
    MBED_HOSTTEST_DESCRIPTION(UDP echo server);
    MBED_HOSTTEST_START("NET_5");

    EthernetInterface eth;
    eth.init(); //Use DHCP
    eth.connect();
    printf("MBED: Server IP Address is %s:%d\r\n", eth.getIPAddress(), ECHO_SERVER_PORT);

    UDPSocket server;
    server.bind(ECHO_SERVER_PORT);

    Endpoint client;
    char buffer[BUFFER_SIZE] = {0};
    printf("MBED: Waiting for packet...\r\n");
    while (true) {
        int n = server.receiveFrom(client, buffer, sizeof(buffer));
        if (n > 0) {
            //printf("Received packet from: %s\n", client.get_address());
            const int buffer_string_end_index = n >= BUFFER_SIZE ? BUFFER_SIZE-1 : n;
            buffer[buffer_string_end_index] = '\0';
            //printf("Server received: %s\n", buffer);
            server.sendTo(client, buffer, n);
        }
    }
}
开发者ID:1deus,项目名称:tmk_keyboard,代码行数:28,代码来源:main.cpp


示例4: UDPSOCKET_SENDTO_TIMEOUT

void UDPSOCKET_SENDTO_TIMEOUT()
{
    char tx_buffer[100];
    fill_tx_buffer_ascii(tx_buffer, sizeof(tx_buffer));

    UDPSocket sock;
    TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));

    SocketAddress udp_addr;
    get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
    udp_addr.set_port(9);

    Timer timer;
    timer.start();
    int sent = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer));
    timer.stop();
    TEST_ASSERT_EQUAL(sizeof(tx_buffer), sent);
    TEST_ASSERT(timer.read_ms() <= 100);

    timer.reset();
    timer.start();
    sent = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer));
    timer.stop();
    TEST_ASSERT_EQUAL(sizeof(tx_buffer), sent);
    TEST_ASSERT(timer.read_ms() <= 100);
    printf("MBED: Time taken: %fs\n", timer.read());

    TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
}
开发者ID:MarceloSalazar,项目名称:mbed-os,代码行数:29,代码来源:udpsocket_sendto_timeout.cpp


示例5: UDPSOCKET_BIND_ADDRESS

void UDPSOCKET_BIND_ADDRESS()
{
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
    int count = fetch_stats();
    for (int j = 0; j < count; j++) {
        TEST_ASSERT_EQUAL(SOCK_CLOSED,  udp_stats[j].state);
    }
#endif

    UDPSocket *sock = new UDPSocket;
    if (!sock) {
        TEST_FAIL();
    }
    TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
    SocketAddress sockAddr = SocketAddress(NetworkInterface::get_default_instance()->get_ip_address(), 80);
    nsapi_error_t bind_result = sock->bind(sockAddr);
    if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
        TEST_IGNORE_MESSAGE("bind() not supported");
    } else {
        TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, bind_result);
    }

    delete sock;

#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
    count = fetch_stats();
    for (int j = 0; j < count; j++) {
        TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state);
    }
#endif
}
开发者ID:pan-,项目名称:mbed,代码行数:31,代码来源:udpsocket_bind_address.cpp


示例6: listenerFlow

/* ===  FUNCTION  ==============================================================
 *         Name:  listenerFlow
 *  Description:  The pig listens for incoming messages here. This is the only
 *                way to trigger events on a pig. Everything on the pig is in
 *                response to some message.
 * =============================================================================
 */
static void listenerFlow (int listenerPort)
{

  gPigOwnNode.portNumber = listenerPort;
  UDPSocket listenSocket (COM_IP_ADDR, listenerPort);

  while (true)
  {
    // Block for msg receipt
    int inMsgSize;
    char *inMsg;
    inMsg = (char *)malloc (MAX_MSG_SIZE);
    memset(inMsg, 0, MAX_MSG_SIZE);
    try
    {
      inMsgSize = listenSocket.recv(inMsg, MAX_MSG_SIZE);
    }
    catch (SocketException &e)
    {
      cout<<gPigOwnNode.portNumber<<": "<<e.what()<<endl;
    }
    inMsg[inMsgSize] = '\0';

    thread handlerThread (pigMsgHandler, inMsgSize, inMsg);
    handlerThread.detach();
  }
}		/* -----  end of function listenerFlow  ----- */
开发者ID:guptha-,项目名称:birdypigs,代码行数:34,代码来源:pigmain.cpp


示例7: main

int main(int argc, char *argv[]) {
  if ((argc < 4) || (argc > 5)) {   // Test for correct number of arguments
    cerr << "Usage: " << argv[0] 
         << " <Destination Address> <Destination Port> <Send String> [<TTL>]\n";
    exit(1);
  }

  string servAddress = argv[1];         // First arg: multicast address
  unsigned short port = atoi(argv[2]);  // Second arg: port
  char* sendString = argv[3];           // Third arg: string to echo

  unsigned char multicastTTL = 1;       // Default TTL
  if (argc == 5) {
    multicastTTL = atoi(argv[4]);       // Command-line TTL
  }

  try {
    UDPSocket sock;

    sock.setMulticastTTL(multicastTTL);

    // Repeatedly send the string to the server
    for (;;) {
      sock.sendTo(sendString, strlen(sendString), servAddress, port);
      sleep(3);
    }
  } catch (SocketException &e) {
    cerr << e.what() << endl;
    exit(1);
  }

  return 0;
}
开发者ID:AaronMR,项目名称:AaronMR_Robotic_Stack,代码行数:33,代码来源:MulticastSender.cpp


示例8: udp_server_task

void udp_server_task(void const *argument)
{
    DigitalOut indicator(LED1);
    UDPSocket server;

    server.bind(ECHO_SERVER_PORT);
    // printf("[udp_server_task] Start\r\n");

    Endpoint client;
    char buffer[BUFFER_SIZE] = { 0 };
    while (true) {
        //printf("[udp_server_task] Wait for packet...\r\n");
        int n = server.receiveFrom(client, buffer, sizeof(buffer));
        if (n > 0) {
            //printf("[udp_server_task] Received packet from: %s\r\n", client.get_address());
            const int buffer_string_end_index = n >= BUFFER_SIZE ? BUFFER_SIZE - 1 : n;
            buffer[buffer_string_end_index] = '\0';
            //printf("[udp_server_task] Server received: %s\r\n", buffer);
            if (host_port == 0) {
                strcpy(host_address, client.get_address());
                host_port = ECHO_SERVER_PORT + 1;
                //printf("[udp_server_task] Set host address and port: %s:%d\r\n", host_address, host_port);
            }
            // Dispatch data to client for sending to test HOST
            cli_serv_mutex.lock(); // LOCK
            // Push to datagram queue
            datagram_queue.push_front(std::string(buffer));
            max_queue_len = datagram_queue.size() > max_queue_len ? datagram_queue.size() : max_queue_len;
            received_packets++;
            cli_serv_mutex.unlock(); // LOCK
            indicator = !indicator;
        }
    }
}
开发者ID:23chrischen,项目名称:mbed,代码行数:34,代码来源:main.cpp


示例9: main

int main(int argc, char *argv[]) {
  if ((argc < 3) || (argc > 4)) {   // Test for correct number of arguments
    cerr << "Usage: " << argv[0] 
         << " <Destination Address> <Destination Port> <Send String>\n";
    exit(1);
  }

  string destAddress = argv[1];             // First arg:  destination address
  unsigned short destPort = atoi(argv[2]);  // Second arg: destination port
  char* sendString = argv[3];               // Third arg:  string to broadcast

  try {
    UDPSocket sock;
  
    // Repeatedly send the string (not including \0) to the server
    for (;;) {
      sock.sendTo(sendString, strlen(sendString), destAddress, destPort);
      sleep(3);
    }
  } catch (SocketException &e) {
    cerr << e.what() << endl;
    exit(1);
  }
  
  return 0;
}
开发者ID:alexlee-gk,项目名称:surgical,代码行数:26,代码来源:BroadcastSender.cpp


示例10: udp_client_task

void udp_client_task(void const *argument)
{
    while (host_port == 0) {
        // Waiting for HOST port notification
    }

    DigitalOut indicator(LED2);
    UDPSocket socket;
    socket.init();

    Endpoint echo_server;
    echo_server.set_address(host_address, host_port);
    //printf("[udp_client_task] Start: %s:%d\r\n", host_address, host_port);

    while (1) {
        std::string datagram;
        bool sent_datagram = false;
        cli_serv_mutex.lock(); // LOCK
        if (datagram_queue.size() > 0) {
            // POP from datagram queue
            datagram = datagram_queue.back();
            datagram_queue.pop_back();
            sent_datagram = true;
        }
        cli_serv_mutex.unlock(); // LOCK
        if (sent_datagram) {
            //printf("[udp_client_task] Forwarded datagram: %s\r\n", datagram.c_str());
            socket.sendTo(echo_server, (char *)datagram.c_str(), datagram.length());
            forwarded_packets++;
            indicator = !indicator;
        }
    }
}
开发者ID:23chrischen,项目名称:mbed,代码行数:33,代码来源:main.cpp


示例11: dis_req

void CTunnelingConnection::HandleDisconnectRequest(unsigned char* buffer)
{	
	CDisconnectRequest dis_req(buffer);
	if(dis_req.GetChannelID() != _state._channelid){
		return;
	}

	CDisconnectResponse dis_resp(_state._channelid,E_NO_ERROR);
	unsigned char buf[256];
	dis_resp.FillBuffer(buf,256);
	UDPSocket sock;

	LOG_DEBUG("[Send] [BUS] [Disconnect Response]");
	
	sock.SendTo(buf,dis_resp.GetTotalSize(),_device_control_address,_device_control_port);
	
	_heartbeat->Close();

	JTCSynchronized s(*this);
        _state._channelid = 0;
        _state._recv_sequence = 0;
        _state._send_sequence = 0;

        SetStatusDisconnected();
}
开发者ID:Paolo-Maffei,项目名称:eibsuite,代码行数:25,代码来源:TunnelConnection.cpp


示例12: sendPairRequest

void PairingHandler::sendPairRequest() {    
    // grab the node socket from the NodeList singleton
    UDPSocket *nodeSocket = NodeList::getInstance()->getNodeSocket();
    
    // prepare the pairing request packet
    
    // use the getLocalAddress helper to get this client's listening address
    int localAddress = getLocalAddress();
    
    char pairPacket[24] = {};
    sprintf(pairPacket, "Find %d.%d.%d.%d:%hu",
            localAddress & 0xFF,
            (localAddress >> 8) & 0xFF,
            (localAddress >> 16) & 0xFF,
            (localAddress >> 24) & 0xFF,
            NodeList::getInstance()->getSocketListenPort());
    
    qDebug("Sending pair packet: %s\n", pairPacket);
    
    sockaddr_in pairingServerSocket;
    
    pairingServerSocket.sin_family = AF_INET;
    
    // lookup the pairing server IP by the hostname
    struct hostent* hostInfo = gethostbyname(PAIRING_SERVER_HOSTNAME);
    memcpy(&pairingServerSocket.sin_addr, hostInfo->h_addr_list[0], hostInfo->h_length);
    pairingServerSocket.sin_port = htons(PAIRING_SERVER_PORT);
    
    // send the pair request to the pairing server
    nodeSocket->send((sockaddr*) &pairingServerSocket, pairPacket, strlen(pairPacket));
}
开发者ID:imclab,项目名称:hifi,代码行数:31,代码来源:PairingHandler.cpp


示例13: TEST

TEST(Reflection, Variable)
{
	AM_DECLARE_VAR(g_instance, int, "MyInteger", 2);
	ASSERT_TRUE(g_instance == 2);
	
	g_instance = 3;
	ASSERT_TRUE(g_instance == 3);

	AM_ASSIGN_VAR("MyInteger", 4);
	ASSERT_TRUE(g_instance == 4);
	
	AM_ASSIGN_VAR_STR("MyInteger", "5");
	ASSERT_TRUE(g_instance == 5);
	
	UDPWriteDesc writeDesc;
	writeDesc.port = 5005;
	writeDesc.address = "localhost";
	std::string str = "MyInteger 6";
	UDPSocket writeSocket;
	ASSERT_TRUE(writeSocket.connect(writeDesc));
	ASSERT_EQ(writeSocket.write(str.c_str(), str.length()), str.length());
	std::this_thread::sleep_for(std::chrono::seconds(1));
	ASSERT_TRUE(g_instance == 6);
	GlobalVariableHandler::destroyInstance();
	
}
开发者ID:christofferpettersson,项目名称:Aftermath,代码行数:26,代码来源:main.cpp


示例14: UDPSOCKET_BIND_ADDRESS_PORT

void UDPSOCKET_BIND_ADDRESS_PORT()
{
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
    int count = fetch_stats();
    for (int j = 0; j < count; j++) {
        TEST_ASSERT_EQUAL(SOCK_CLOSED,  udp_stats[j].state);
    }
#endif

    UDPSocket *sock = new UDPSocket;
    if (!sock) {
        TEST_FAIL();
    }
    TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
    TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->bind(get_interface()->get_ip_address(), 80));

    delete sock;

#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
    count = fetch_stats();
    for (int j = 0; j < count; j++) {
        TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state);
    }
#endif
}
开发者ID:MarceloSalazar,项目名称:mbed-os,代码行数:25,代码来源:udpsocket_bind_address_port.cpp


示例15: Create

    UDPSocket UDPSocket::Create(std::int32_t domain)
    {
        UDPSocket socket;
        socket.Init(domain);

        return socket;
    }
开发者ID:0of,项目名称:android-net-adapter,代码行数:7,代码来源:Socket.cpp


示例16: socket_address

/**
 * Check that we send OSC messages correctly.
 */
void OSCNodeTest::testSendBlob() {
  // First up create a UDP socket to receive the messages on.
  // Port 0 means 'ANY'
  IPV4SocketAddress socket_address(IPV4Address::Loopback(), 0);
  // Bind the socket, set the callback, and register with the select server.
  OLA_ASSERT_TRUE(m_udp_socket.Bind(socket_address));
  m_udp_socket.SetOnData(NewCallback(this, &OSCNodeTest::UDPSocketReady));
  OLA_ASSERT_TRUE(m_ss.AddReadDescriptor(&m_udp_socket));
  // Store the local address of the UDP socket so we know where to tell the
  // OSCNode to send to.
  OLA_ASSERT_TRUE(m_udp_socket.GetSocketAddress(&socket_address));

  // Setup the OSCTarget pointing to the local socket address
  OSCTarget target(socket_address, TEST_OSC_ADDRESS);
  // Add the target to the node.
  m_osc_node->AddTarget(TEST_GROUP, target);
  // Send the data
  OLA_ASSERT_TRUE(m_osc_node->SendData(TEST_GROUP, OSCNode::FORMAT_BLOB,
                  m_dmx_data));

  // Run the SelectServer this will return either when UDPSocketReady
  // completes, or the abort timeout triggers.
  m_ss.Run();

  // Remove target
  OLA_ASSERT_TRUE(m_osc_node->RemoveTarget(TEST_GROUP, target));
  // Try to remove it a second time
  OLA_ASSERT_FALSE(m_osc_node->RemoveTarget(TEST_GROUP, target));

  // Try to remove the target from a group that doesn't exist
  OLA_ASSERT_FALSE(m_osc_node->RemoveTarget(TEST_GROUP + 1, target));
}
开发者ID:Jazeido,项目名称:ola,代码行数:35,代码来源:OSCNodeTest.cpp


示例17: QTSS_Milliseconds

SInt64 ProxyTask::Run()
{
    const UInt32 kMaxRTCPPacketSize = 2048;
    char thePacketBuffer[kMaxRTCPPacketSize];
    QTSS_PacketStruct thePacketStruct;
    thePacketStruct.packetTransmitTime = QTSS_Milliseconds();
    thePacketStruct.packetData = thePacketBuffer;

    (void)this->GetEvents();    

    OSMutexLocker locker(sSocketPool->GetMutex());
    for (OSQueueIter iter(sSocketPool->GetSocketQueue()); !iter.IsDone(); iter.Next())
    {
        UInt32 theRemoteAddr = 0;
        UInt16 theRemotePort = 0;

        UDPSocketPair* thePair = (UDPSocketPair*)iter.GetCurrent()->GetEnclosingObject();
        Assert(thePair != NULL);
        
        for (UInt32 x = 0; x < 2; x++)
        {
            QTSS_WriteFlags theFlags = qtssWriteFlagsNoFlags;
            
            UDPSocket* theSocket = NULL;
            if (x == 0)
            {
                theFlags = qtssWriteFlagsIsRTP;
                theSocket = thePair->GetSocketA();
            }
            else
            {
                theFlags = qtssWriteFlagsIsRTCP;
                theSocket = thePair->GetSocketB();
            }
            
            Assert(theSocket->GetDemuxer() != NULL);
            OSMutexLocker locker(theSocket->GetDemuxer()->GetMutex());
            
            //get all the outstanding packets for this socket
            while (true)
            {
                UInt32 thePacketLen = 0;
                theSocket->RecvFrom(&theRemoteAddr, &theRemotePort, thePacketStruct.packetData, 
                                kMaxRTCPPacketSize, &thePacketLen);
                if (thePacketLen == 0)
                    break;//no more packets on this socket!
                    
                ProxyDemuxerTask* theDemuxerTask = (ProxyDemuxerTask*)theSocket->GetDemuxer()->GetTask(theRemoteAddr, 0);
                if (theDemuxerTask != NULL)
                {
                    QTSS_RTPStreamObject theStream = theDemuxerTask->GetStream();
                    (void)QTSS_Write(theStream, &thePacketStruct, thePacketLen, NULL, theFlags);
                }
            }
        }
    }
    return kProxyTaskPollIntervalMsec;
}
开发者ID:12307,项目名称:EasyDarwin,代码行数:58,代码来源:QTSSProxyModule.cpp


示例18: main

int
main(int argc, char** argv)
{
  if (argc < 4)
  {
    std::fprintf(stderr, "Usage: %s <destination host> <destination port> <entity> <true|false>\n", argv[0]);
    return 1;
  }

  Address dest(argv[1]);

  // Parse port.
  unsigned port = 0;
  if (!castLexical(argv[2], port))
  {
    fprintf(stderr, "ERROR: invalid port '%s'\n", argv[2]);
    return 1;
  }

  if (port > 65535)
  {
    fprintf(stderr, "ERROR: invalid port '%s'\n", argv[2]);
    return 1;
  }

  IMC::EntityParameter p;
  p.name = "Active";
  p.value = argv[4];

  IMC::SetEntityParameters msg;
  msg.name = argv[3];
  msg.params.push_back(p);
  msg.setTimeStamp();

  uint8_t bfr[1024] = {0};
  uint16_t rv = IMC::Packet::serialize(&msg, bfr, sizeof(bfr));

  UDPSocket sock;
  try
  {
    sock.write(bfr, rv, dest, port);

    fprintf(stderr, "Raw:");
    for (int i = 0; i < rv; ++i)
      fprintf(stderr, " %02X", bfr[i]);
    fprintf(stderr, "\n");

    msg.toText(std::cerr);
  }
  catch (std::runtime_error& e)
  {
    std::cerr << "ERROR: " << e.what() << std::endl;
    return 1;
  }

  return 0;
}
开发者ID:Aero348,项目名称:dune,代码行数:57,代码来源:activation.cpp


示例19: sendMsg

/* ===  FUNCTION  ==============================================================
 *         Name:  sendMsg
 *  Description:  This function sends the given msg to the give port
 * =============================================================================
 */
void sendMsg(char *outMsg, int outMsgSize, unsigned short int destPort)
{
  try {
    static UDPSocket sendSocket;
    sendSocket.sendTo(outMsg, outMsgSize, COM_IP_ADDR, destPort);
  } catch (SocketException &e) {
    cout<<"db: Cannot send msg"<<endl;
  }
  return;
}   /* -----  end of function sendMsg  ----- */
开发者ID:guptha-,项目名称:birdypigs3,代码行数:15,代码来源:dbmsg.cpp


示例20: memset

int BufferManager::read(UDPSocket &sock)
{
    int ret ;
    
    m_InReq.ioBuf = NULL;
    memset(&m_InReq.m_msgHeader,0,HEADER_SIZE);
    m_iLen = HEADER_SIZE;
    
    if((ret = sock.readSocket(((char *)(&m_InReq.m_msgHeader)),HEADER_SIZE,m_InReq.oppoAddr)) < 0)
    {
        handleSyscallError("BufferManager::read UDPSocket");
        return FAILED;
    }
    
    else if((unsigned int) ret < HEADER_SIZE)
    {
        handleSyscallError("BufferManager::read(UDPSocket)");
        return FAILED;
    }

    m_iLen = m_InReq.m_msgHeader.length;
    if(m_iLen == 0)
    {
        m_InReq.ioBuf = NULL;
        if(m_pAgent)
            m_pAgent->readBack(m_InReq);

        return SUCCESSFUL;
    }
    
    m_InReq.ioBuf = new char[m_iLen + 1];
    memset(m_InReq.ioBuf,0,m_iLen + 1);
    if((ret =  sock.readSocket(m_InReq.ioBuf,m_iLen,m_InReq.oppoAddr)) < 0)
    {
        handleSyscallError("BufferManager::read UDPSocket data");
        return FAILED;
    }

    if((unsigned int)ret < m_iLen)
    {
        handleError("BufferManager::read UDPSocket data incomplete");
    }
    
    if(m_pAgent)
        m_pAgent->readBack(m_InReq);
    else
        handleError("BufferManager don't be relate with a Agent");

    delete [] (char *)m_InReq.ioBuf;
    m_bInit = true;
    
    return SUCCESSFUL;
}
开发者ID:ytaoWang,项目名称:CSLogChecker,代码行数:53,代码来源:BufferManager.cpp



注:本文中的UDPSocket类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ UDSEntry类代码示例发布时间:2022-05-31
下一篇:
C++ UDP类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap