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
TcpSocket.cpp
00001 //////////////////////////////////////////////////////////////////////////////// 00002 // TcpSocket.h 00003 //////////////////////////////////////////////////////////////////////////////// 00004 00005 #include "TcpSocket.h" 00006 #include "mbed.h" 00007 00008 namespace MiMic 00009 { 00010 #define TIMEOUT_IN_MSEC (5*1000) 00011 00012 TcpSocket::TcpSocket() 00013 { 00014 this->_inst=NyLPC_cNet_createTcpSocketEx(NyLPC_TSocketType_TCP_NORMAL); 00015 if(this->_inst==NULL){ 00016 mbed_die(); 00017 } 00018 } 00019 TcpSocket::~TcpSocket() 00020 { 00021 NyLPC_iTcpSocket_finalize(this->_inst); 00022 } 00023 bool TcpSocket::connect (const IpAddr& i_addr,unsigned short i_port, unsigned int timeout) 00024 { 00025 return NyLPC_iTcpSocket_connect(this->_inst,&(i_addr.addr.v4),i_port,timeout)?true:false; 00026 } 00027 00028 bool TcpSocket::send(const void* i_tx,unsigned short i_tx_size) 00029 { 00030 int l,t; 00031 l=i_tx_size; 00032 while(l>0){ 00033 t=NyLPC_iTcpSocket_send(this->_inst,((const char*)i_tx)+(i_tx_size-l),l,TIMEOUT_IN_MSEC); 00034 if(t<0){ 00035 return false; 00036 } 00037 l-=t; 00038 } 00039 return true; 00040 } 00041 bool TcpSocket::canRecv() 00042 { 00043 const void* rx; 00044 return NyLPC_iTcpSocket_precv(this->_inst,&rx,0)>0; 00045 } 00046 int TcpSocket::precv(const void* &i_rx, unsigned int timeout) 00047 { 00048 return NyLPC_iTcpSocket_precv(this->_inst,&i_rx,timeout); 00049 } 00050 int TcpSocket::precv(const char* &i_rx, unsigned int timeout) 00051 { 00052 return NyLPC_iTcpSocket_precv(this->_inst,(const void**)&i_rx,timeout); 00053 } 00054 void TcpSocket::pseek(unsigned short i_rx_seek) 00055 { 00056 NyLPC_iTcpSocket_pseek(this->_inst,i_rx_seek); 00057 } 00058 void TcpSocket::close() 00059 { 00060 return NyLPC_iTcpSocket_close(this->_inst,TIMEOUT_IN_MSEC); 00061 } 00062 }
Generated on Tue Jul 12 2022 16:22:59 by
