mbed OS5
Fork of UIPEthernet by
Embed:
(wiki syntax)
Show/hide line numbers
UIPServer.cpp
00001 /* 00002 UIPServer.cpp - Arduino implementation of a UIP wrapper class. 00003 Copyright (c) 2013 Norbert Truchsess <norbert.truchsess@t-online.de> 00004 All rights reserved. 00005 00006 This program is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 #include "UIPEthernet.h" 00020 #include "UIPServer.h" 00021 extern "C" 00022 { 00023 #include "utility/uip-conf.h" 00024 } 00025 /** 00026 * @brief 00027 * @note 00028 * @param 00029 * @retval 00030 */ 00031 UIPServer::UIPServer(uint16_t port) : 00032 _port(htons(port)) 00033 { } 00034 00035 /** 00036 * @brief 00037 * @note 00038 * @param 00039 * @retval 00040 */ 00041 UIPClient UIPServer::available(void) { 00042 uIPEthernet.tick(); 00043 for (uip_userdata_t * data = &UIPClient::all_data[0]; data < &UIPClient::all_data[UIP_CONNS]; data++) { 00044 if 00045 ( 00046 data->packets_in[0] != NOBLOCK 00047 && ( 00048 ((data->state & UIP_CLIENT_CONNECTED) && uip_conns[data->state & UIP_CLIENT_SOCKETS].lport == _port) 00049 || ((data->state & UIP_CLIENT_REMOTECLOSED) && ((uip_userdata_closed_t*)data)->lport == _port) 00050 ) 00051 ) return UIPClient(data); 00052 } 00053 00054 return UIPClient(); 00055 } 00056 00057 /** 00058 * @brief 00059 * @note 00060 * @param 00061 * @retval 00062 */ 00063 void UIPServer::begin(void) { 00064 uip_listen(_port); 00065 uIPEthernet.tick(); 00066 } 00067 00068 /** 00069 * @brief 00070 * @note 00071 * @param 00072 * @retval 00073 */ 00074 size_t UIPServer::write(uint8_t c) { 00075 return write(&c, 1); 00076 } 00077 00078 /** 00079 * @brief 00080 * @note 00081 * @param 00082 * @retval 00083 */ 00084 size_t UIPServer::write(const uint8_t* buf, size_t size) { 00085 size_t ret = 0; 00086 for (uip_userdata_t * data = &UIPClient::all_data[0]; data < &UIPClient::all_data[UIP_CONNS]; data++) { 00087 if ((data->state & UIP_CLIENT_CONNECTED) && uip_conns[data->state & UIP_CLIENT_SOCKETS].lport == _port) 00088 ret += UIPClient::_write(data, buf, size); 00089 } 00090 00091 return ret; 00092 }
Generated on Tue Jul 12 2022 18:10:58 by 1.7.2