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
NyLPC_iUdpSocket.h
00001 /********************************************************************************* 00002 * PROJECT: MiMic 00003 * -------------------------------------------------------------------------------- 00004 * 00005 * This file is part of MiMic 00006 * Copyright (C)2011 Ryo Iizuka 00007 * 00008 * MiMic is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published 00010 * by the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00020 * 00021 * For further information please contact. 00022 * http://nyatla.jp/ 00023 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp> 00024 * 00025 *********************************************************************************/ 00026 #ifndef NYLPC_IIUDPSOCKET_H_ 00027 #define NYLPC_IIUDPSOCKET_H_ 00028 00029 00030 #include "NyLPC_stdlib.h" 00031 #include "NyLPC_os.h" 00032 #include "NyLPC_NetIf_ip_types.h" 00033 #include "NyLPC_iTcpSocket.h" 00034 #ifdef __cplusplus 00035 extern "C" { 00036 #endif /* __cplusplus */ 00037 00038 typedef struct NyLPC_TiUdpSocket NyLPC_TiUdpSocket_t; 00039 /********************************************************************** 00040 * Struct 00041 **********************************************************************/ 00042 00043 /** 00044 * 受信情報を格納する構造体 00045 */ 00046 struct NyLPC_TIPv4RxInfo 00047 { 00048 NyLPC_TUInt16 size;//パケットサイズ 00049 NyLPC_TUInt16 port;//受信ポート 00050 NyLPC_TUInt16 peer_port;//PEERポート 00051 struct NyLPC_TIPv4Addr ip;//受信IP 00052 struct NyLPC_TIPv4Addr peer_ip;//PEERIP 00053 }; 00054 00055 00056 /********************************************************************** 00057 * Event 00058 **********************************************************************/ 00059 00060 /** 00061 * 受信時に非同期にコールされるハンドラ 00062 * UIPサービスタスクが実行する。 00063 * @return 00064 * TRUEならパケットを受信キューへ追加する。FALSEならパケットを受信キューへ追加しない。 00065 */ 00066 typedef NyLPC_TBool (*NyLPC_TiUdpSocket_onRxHandler)(NyLPC_TiUdpSocket_t* i_inst,const void* i_buf,const struct NyLPC_TIPv4RxInfo* i_info); 00067 00068 /** 00069 * 非同期にコールされるハンドラ。 00070 * UIPサービスタスクが実行する。 00071 */ 00072 typedef void (*NyLPC_TiUdpSocket_onPeriodicHandler)(NyLPC_TiUdpSocket_t* i_inst); 00073 00074 /********************************************************************** 00075 * Function 00076 **********************************************************************/ 00077 00078 00079 00080 /** 00081 * マルチキャストアドレスに参加する。 00082 * @param i_addr 00083 * 参加するマルチキャストグループを指定する。 00084 * 同じマルチキャスとグループに参加できるのは、システムの中で1つに限られます。 00085 * 0を指定した場合、マルチキャスとグループから離脱します。 00086 */ 00087 typedef void (*NyLPC_TiUdpSocket_joinMulticast)(NyLPC_TiUdpSocket_t* i_inst,const struct NyLPC_TIPv4Addr* i_addr); 00088 00089 /** 00090 * ブロードキャストに参加する。 00091 */ 00092 typedef void (*NyLPC_TiUdpSocket_setBroadcast)(NyLPC_TiUdpSocket_t* i_inst); 00093 00094 00095 /** 00096 * この関数は、ソケットの受信バッファの読み取り位置と、読み出せるデータサイズを返却します。 00097 * 関数はポインターを返却するだけで、バッファの読み取り位置をシークしません。 00098 * シークするにはNyLPC_cTcpSocket_pseekを使います。 00099 */ 00100 typedef NyLPC_TInt32 (*NyLPC_TiUdpSocket_precv)(NyLPC_TiUdpSocket_t* i_inst,const void** o_buf_ptr,const struct NyLPC_TIPv4RxInfo** o_info,NyLPC_TUInt32 i_wait_msec); 00101 /** 00102 * 受信バッファを次のバッファまでシークします。 00103 */ 00104 typedef void (*NyLPC_TiUdpSocket_pseek)(NyLPC_TiUdpSocket_t* i_inst); 00105 00106 /** 00107 * 送信バッファを割り当てて返します。 00108 * 割り当てたメモリは、releaseSendBuf関数か、psend関数を成功させて開放する必要があります。 00109 * @param i_hint 00110 * 取得したいメモリサイズをセットします。 00111 * 関数は要求サイズより小さいメモリを返すことがあります。 00112 */ 00113 typedef void* (*NyLPC_TiUdpSocket_allocSendBuf)(NyLPC_TiUdpSocket_t* i_inst,NyLPC_TUInt16 i_hint,NyLPC_TUInt16* o_buf_size,NyLPC_TUInt32 i_wait_in_msec); 00114 00115 typedef void (*NyLPC_TiUdpSocket_releaseSendBuf)(NyLPC_TiUdpSocket_t* i_inst,void* i_buf_ptr); 00116 00117 /** 00118 * 事前にAllocしたTxパケットを送信します。 00119 * このAPIはゼロコピー送信をサポートするためのものです。 00120 * @param i_buf_ptr 00121 * allocSendBufで取得したメモリを指定します。 00122 * @return 00123 * 関数が失敗した場合、i_buf_ptrは「開放されません。」 00124 */ 00125 typedef NyLPC_TBool (*NyLPC_TiUdpSocket_psend)(NyLPC_TiUdpSocket_t* i_inst,const struct NyLPC_TIPv4Addr* i_addr,NyLPC_TUInt16 i_port,void* i_buf_ptr,int i_len); 00126 00127 /** 00128 * 最大送信サイズは1200バイトです。 00129 */ 00130 typedef NyLPC_TInt32 (*NyLPC_TiUdpSocket_send)(NyLPC_TiUdpSocket_t* i_inst,const struct NyLPC_TIPv4Addr* i_addr,NyLPC_TUInt16 i_port,const void* i_buf_ptr,NyLPC_TInt32 i_len,NyLPC_TUInt32 i_wait_in_msec); 00131 00132 /** 00133 * 非同期パケットハンドラを設定する。 00134 */ 00135 typedef void (*NyLPC_TiUdpSocket_setOnRxHandler)(NyLPC_TiUdpSocket_t* i_inst,NyLPC_TiUdpSocket_onRxHandler i_handler); 00136 00137 /** 00138 * 非同期タイマ呼び出しハンドラを設定する。 00139 */ 00140 typedef void (*NyLPC_TiUdpSocket_setOnPeriodicHandler)(NyLPC_TiUdpSocket_t* i_inst,NyLPC_TiUdpSocket_onPeriodicHandler i_handler); 00141 00142 00143 /** 00144 * ソケットのローカルIPのアドレスを返す。 00145 * 値はuipが動作中のみ有効。 00146 */ 00147 typedef const struct NyLPC_TIPv4Addr* (*NyLPC_TiUdpSocket_getSockIP)(const NyLPC_TiUdpSocket_t* i_inst); 00148 00149 typedef void (*NyLPC_TiUdpSocket_finalize)(NyLPC_TiUdpSocket_t* i_inst); 00150 00151 00152 /********************************************************************** 00153 * Interface 00154 **********************************************************************/ 00155 00156 /** 00157 */ 00158 struct NyLPC_TiUdpSocket_Interface 00159 { 00160 NyLPC_TiUdpSocket_joinMulticast joinMulticast; 00161 NyLPC_TiUdpSocket_setBroadcast setBroadcast; 00162 NyLPC_TiUdpSocket_precv precv; 00163 NyLPC_TiUdpSocket_pseek pseek; 00164 NyLPC_TiUdpSocket_allocSendBuf allocSendBuf; 00165 NyLPC_TiUdpSocket_releaseSendBuf releaseSendBuf; 00166 NyLPC_TiUdpSocket_psend psend; 00167 NyLPC_TiUdpSocket_send send; 00168 NyLPC_TiUdpSocket_setOnRxHandler setOnRxHandler; 00169 NyLPC_TiUdpSocket_setOnPeriodicHandler setOnPeriodicHandler; 00170 NyLPC_TiUdpSocket_getSockIP getSockIP; 00171 NyLPC_TiUdpSocket_finalize finalize; 00172 }; 00173 00174 struct NyLPC_TiUdpSocket 00175 { 00176 const struct NyLPC_TiUdpSocket_Interface* _interface; 00177 void* _tag; 00178 }; 00179 00180 00181 #define NyLPC_iUdpSocket_joinMulticast(i_inst,i_addr) ((i_inst)->_interface->joinMulticast((i_inst),(i_addr))) 00182 #define NyLPC_iUdpSocket_setBroadcast(i_inst) ((i_inst)->_interface->setBroadcast((i_inst))) 00183 #define NyLPC_iUdpSocket_precv(i_inst,o_buf_ptr,o_info,i_wait_msec) ((i_inst)->_interface->precv((i_inst),(o_buf_ptr),(o_info),(i_wait_msec))) 00184 #define NyLPC_iUdpSocket_pseek(i_inst) ((i_inst)->_interface->pseek((i_inst))) 00185 #define NyLPC_iUdpSocket_allocSendBuf(i_inst,i_hint,o_buf_size,i_wait_in_msec) ((i_inst)->_interface->allocSendBuf((i_inst),(i_hint),(o_buf_size),(i_wait_in_msec))) 00186 #define NyLPC_iUdpSocket_releaseSendBuf(i_inst,i_buf_ptr) ((i_inst)->_interface->releaseSendBuf((i_inst),(i_buf_ptr))) 00187 #define NyLPC_iUdpSocket_psend(i_inst,i_addr,i_port,i_buf_ptr,i_len) ((i_inst)->_interface->psend((i_inst),(i_addr),(i_port),(i_buf_ptr),(i_len))) 00188 #define NyLPC_iUdpSocket_send(i_inst,i_addr,i_port,i_buf_ptr,i_len,i_wait_in_msec) ((i_inst)->_interface->send((i_inst),(i_addr),(i_port),(i_buf_ptr),(i_len),(i_wait_in_msec))) 00189 #define NyLPC_iUdpSocket_setOnRxHandler(i_inst,i_handler) ((i_inst)->_interface->setOnRxHandler((i_inst),(i_handler))) 00190 #define NyLPC_iUdpSocket_setOnPeriodicHandler(i_inst,i_handler) ((i_inst)->_interface->setOnPeriodicHandler((i_inst),(i_handler))) 00191 #define NyLPC_iUdpSocket_getSockIP(i_inst) ((i_inst)->_interface->getSockIP((i_inst))) 00192 #define NyLPC_iUdpSocket_finalize(i_inst) ((i_inst)->_interface->finalize((i_inst))) 00193 00194 00195 #ifdef __cplusplus 00196 } 00197 #endif /* __cplusplus */ 00198 00199 #endif /* NYLPC_IIUDPSOCKET_H_ */
Generated on Tue Jul 12 2022 16:22:59 by
