Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of libMiMic by
UdpSocket.h
00001 #pragma once 00002 //////////////////////////////////////////////////////////////////////////////// 00003 // UdpSocket.h 00004 //////////////////////////////////////////////////////////////////////////////// 00005 00006 #include "NyLPC_net.h" 00007 #include "IpAddr.h" 00008 00009 namespace MiMic 00010 { 00011 class UdpSocket; 00012 /** 00013 * Udp Socket Class. 00014 * The class is used by Net constructor. 00015 */ 00016 class UdpSocket 00017 { 00018 private: 00019 NyLPC_TiUdpSocket_t* _inst; 00020 public: 00021 /** wrapped base LPC class.*/ 00022 NyLPC_TiUdpSocket_t* refBaseInstance(){return this->_inst;} 00023 00024 public: 00025 /** 00026 * Create standard UDP socket. 00027 * @param i_port 00028 * port number. 00029 * @param i_nobuffer 00030 * false(default) - 00031 * UDP packets will be receive to internal buffer. It can be access by precvFrom/precvNext function. 00032 * It is accepts only "Short" packet. 00033 * MUST BE SET NyLPC_cMiMicIpNetIf_config_UDPSOCKET_MAX 1 or more when MiMicIPNetInterface using. 00034 * true - 00035 * UDP packets will be handled to onRxHandler function. 00036 * It is accepts "Full size" packet. 00037 * MUST BE SET NyLPC_cMiMicIpNetIf_config_UDPSOCKET_NB_MAX 1 or more when MiMicIPNetInterface using. 00038 */ 00039 UdpSocket(unsigned short i_port,bool i_nobuffer=false); 00040 virtual ~UdpSocket(); 00041 /** 00042 * This function return recieved data and size. 00043 * The function sets the head of the oldest readable buffer. 00044 * A position is not changed until precvnext was called. 00045 * @param i_host_addr 00046 * must be IPv4 address format. 00047 */ 00048 int precvFrom(const void* &i_rx,IpAddr* i_peer_host=NULL,unsigned short* i_port=NULL); 00049 int precvFrom(const char* &i_rx,IpAddr* i_peer_host=NULL,unsigned short* i_port=NULL); 00050 /** 00051 * This function moves rx buffer to next packet. 00052 */ 00053 void precvNext(void); 00054 /** 00055 * true if precv has data. 00056 * This can avoid the block of precv. 00057 */ 00058 bool canRecv(); 00059 00060 bool sendTo(const IpAddr& i_host,unsigned short i_port,const void* i_tx,unsigned short i_tx_size); 00061 void joinMulticast(const IpAddr& i_host); 00062 void setBroadcast(void); 00063 protected: 00064 /** 00065 * callback function. 00066 * MUST be override when used callback constructor. 00067 */ 00068 virtual void onRxHandler(const void* i_buf,const struct NyLPC_TIPv4RxInfo* i_info){}; 00069 static void rxhandler(NyLPC_TiUdpSocket_t* i_inst,const void* i_buf,const struct NyLPC_TIPv4RxInfo* i_info); 00070 00071 }; 00072 } 00073
Generated on Tue Jul 12 2022 16:22:59 by
