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.
Dependencies: DHT WIZnetInterface mbed-src
TCPSocketConnectionArdu.cpp
00001 /* Copyright (C) 2012 mbed.org, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00005 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00006 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00007 * furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 #include "TCPSocketConnectionArdu.h" 00020 00021 00022 ssize_t TCPSocketConnectionArdu::write(uint8_t b) { 00023 return write((char*)&b,1); 00024 } 00025 00026 /** Send data to the remote host. 00027 \param data The buffer to send to the host. 00028 \param length The length of the buffer to send. 00029 \return the number of written bytes on success (>=0) or -1 on failure 00030 */ 00031 ssize_t TCPSocketConnectionArdu::write(const void *buf, size_t size) { 00032 return send((char*)buf, size); 00033 } 00034 00035 int TCPSocketConnectionArdu::available(){ 00036 return eth->wait_readable(_sock_fd, 1500, 0); 00037 } 00038 00039 int TCPSocketConnectionArdu::read(){ 00040 uint8_t b; 00041 if(receive((char*)b, 1) > 0) return b; 00042 return -1; 00043 } 00044 00045 ssize_t TCPSocketConnectionArdu::read(void *buf, size_t size) { 00046 return receive((char*)buf, size); 00047 } 00048 00049 int TCPSocketConnectionArdu::readBytes(uint8_t* buf, size_t size) { return read(buf,size);} 00050 00051 int TCPSocketConnectionArdu::peek(){ 00052 if(available()==0) return -1; 00053 return available(); 00054 } 00055 00056 void TCPSocketConnectionArdu::flush() { 00057 while(available()>0) read(); 00058 } 00059 00060 void TCPSocketConnectionArdu::stop(){ 00061 if (_sock_fd == -1) 00062 return; 00063 00064 // attempt to close the connection gracefully (send a FIN to other side) 00065 TCPSocketConnection::close(); 00066 _sock_fd = -1; 00067 00068 } 00069 00070 /** Check if the socket is connected 00071 \return true if connected, false otherwise. 00072 */ 00073 uint8_t TCPSocketConnectionArdu::connected(){ 00074 return is_connected(); 00075 } 00076 00077 TCPSocketConnectionArdu::operator bool() { return _sock_fd != -1;} 00078
Generated on Wed Jul 13 2022 02:25:39 by
