Skip to content

Commit 277013b

Browse files
committed
Using global namespace trick for socket API's (instead of renaming)
1 parent 1635653 commit 277013b

File tree

3 files changed

+5
-47
lines changed

3 files changed

+5
-47
lines changed

src/socket/include/socket.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,12 +1205,7 @@ NMI_API SOCKET socket(uint16 u16Domain, uint8 u8Type, uint8 u8Flags);
12051205
}
12061206
@endcode
12071207
*/
1208-
#ifdef ARDUINO
1209-
NMI_API sint8 bindSocket(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen);
1210-
#else
12111208
NMI_API sint8 bind(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen);
1212-
#endif
1213-
12141209
/** @} */
12151210

12161211
/** @defgroup ListenFn listen
@@ -1332,11 +1327,7 @@ This example demonstrates the call of the listen socket operation after a succes
13321327
13331328
@endcode
13341329
*/
1335-
#ifdef ARDUINO
1336-
NMI_API sint8 listenSocket(SOCKET sock, uint8 backlog);
1337-
#else
13381330
NMI_API sint8 listen(SOCKET sock, uint8 backlog);
1339-
#endif
13401331
/** @} */
13411332
/** @defgroup AcceptFn accept
13421333
* @ingroup SocketAPI
@@ -1470,11 +1461,7 @@ NMI_API sint8 accept(SOCKET sock, struct sockaddr *addr, uint8 *addrlen);
14701461
}
14711462
@endcode
14721463
*/
1473-
#ifdef ARDUINO
1474-
NMI_API sint8 connectSocket(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen);
1475-
#else
14761464
NMI_API sint8 connect(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen);
1477-
#endif
14781465
/** @} */
14791466
/** @defgroup ReceiveFn recv
14801467
* @ingroup SocketAPI
@@ -1820,11 +1807,7 @@ NMI_API sint16 send(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint1
18201807
@return
18211808
The function returns @ref SOCK_ERR_NO_ERROR for successful operation and a negative value (indicating the error) otherwise.
18221809
*/
1823-
#ifdef ARDUINO
1824-
NMI_API sint16 sendtoSocket(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags, struct sockaddr *pstrDestAddr, uint8 u8AddrLen);
1825-
#else
18261810
NMI_API sint16 sendto(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags, struct sockaddr *pstrDestAddr, uint8 u8AddrLen);
1827-
#endif
18281811
/** @} */
18291812
/** @defgroup CloseSocketFn close
18301813
* @ingroup SocketAPI
@@ -1853,12 +1836,7 @@ NMI_API sint16 sendto(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uin
18531836
@return
18541837
The function returned @ref SOCK_ERR_NO_ERROR for successful operation and a negative value (indicating the error) otherwise.
18551838
*/
1856-
#ifdef ARDUINO
1857-
NMI_API sint8 closeSocket(SOCKET sock);
1858-
#else
18591839
NMI_API sint8 close(SOCKET sock);
1860-
#endif
1861-
18621840
/** @} */
18631841
/** @defgroup InetAddressFn nmi_inet_addr
18641842
* @ingroup SocketAPI

src/socket/source/socket.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,7 @@ Version
623623
Date
624624
5 June 2012
625625
*********************************************************************/
626-
#ifdef ARDUINO
627-
sint8 bindSocket(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
628-
#else
629626
sint8 bind(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
630-
#endif
631627
{
632628
sint8 s8Ret = SOCK_ERR_INVALID_ARG;
633629
if((pstrAddr != NULL) && (sock >= 0) && (gastrSockets[sock].bIsUsed == 1) && (u8AddrLen != 0))
@@ -672,11 +668,7 @@ Version
672668
Date
673669
5 June 2012
674670
*********************************************************************/
675-
#ifdef ARDUINO
676-
sint8 listenSocket(SOCKET sock, uint8 backlog)
677-
#else
678671
sint8 listen(SOCKET sock, uint8 backlog)
679-
#endif
680672
{
681673
sint8 s8Ret = SOCK_ERR_INVALID_ARG;
682674

@@ -748,11 +740,7 @@ Version
748740
Date
749741
5 June 2012
750742
*********************************************************************/
751-
#ifdef ARDUINO
752-
sint8 connectSocket(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
753-
#else
754743
sint8 connect(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
755-
#endif
756744
{
757745
sint8 s8Ret = SOCK_ERR_INVALID_ARG;
758746
if((sock >= 0) && (pstrAddr != NULL) && (gastrSockets[sock].bIsUsed == 1) && (u8AddrLen != 0))
@@ -856,11 +844,7 @@ Version
856844
Date
857845
4 June 2012
858846
*********************************************************************/
859-
#ifdef ARDUINO
860-
sint16 sendtoSocket(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags, struct sockaddr *pstrDestAddr, uint8 u8AddrLen)
861-
#else
862847
sint16 sendto(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags, struct sockaddr *pstrDestAddr, uint8 u8AddrLen)
863-
#endif
864848
{
865849
#ifdef ARDUINO
866850
// Silence "unused" warning
@@ -979,11 +963,7 @@ Version
979963
Date
980964
4 June 2012
981965
*********************************************************************/
982-
#ifdef ARDUINO
983-
sint8 closeSocket(SOCKET sock)
984-
#else
985966
sint8 close(SOCKET sock)
986-
#endif
987967
{
988968
sint8 s8Ret = SOCK_ERR_INVALID_ARG;
989969
M2M_INFO("Sock to delete <%d>\n", sock);

src/utility/WiFiSocket.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ SOCKET WiFiSocketClass::create(uint16 u16Domain, uint8 u8Type, uint8 u8Flags)
7676

7777
sint8 WiFiSocketClass::bind(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
7878
{
79-
if (bindSocket(sock, pstrAddr, u8AddrLen) < 0) {
79+
if (::bind(sock, pstrAddr, u8AddrLen) < 0) {
8080
return 0;
8181
}
8282

@@ -106,7 +106,7 @@ sint8 WiFiSocketClass::bind(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8Addr
106106

107107
sint8 WiFiSocketClass::listen(SOCKET sock, uint8 backlog)
108108
{
109-
if (listenSocket(sock, backlog) < 0) {
109+
if (::listen(sock, backlog) < 0) {
110110
return 0;
111111
}
112112

@@ -133,7 +133,7 @@ sint8 WiFiSocketClass::setopt(SOCKET socket, uint8 u8Level, uint8 option_name, c
133133

134134
sint8 WiFiSocketClass::connect(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
135135
{
136-
if (connectSocket(sock, pstrAddr, u8AddrLen) < 0) {
136+
if (::connect(sock, pstrAddr, u8AddrLen) < 0) {
137137
return 0;
138138
}
139139

@@ -308,7 +308,7 @@ sint16 WiFiSocketClass::sendto(SOCKET sock, void *pvSendBuffer, uint16 u16SendLe
308308
return 0;
309309
}
310310

311-
return sendtoSocket(sock, pvSendBuffer, u16SendLength, flags, pstrDestAddr, u8AddrLen);
311+
return ::sendto(sock, pvSendBuffer, u16SendLength, flags, pstrDestAddr, u8AddrLen);
312312
}
313313

314314
sint8 WiFiSocketClass::close(SOCKET sock)
@@ -335,7 +335,7 @@ sint8 WiFiSocketClass::close(SOCKET sock)
335335
_info[sock].buffer.length = 0;
336336
_info[sock].recvMsg.s16BufferSize = 0;
337337

338-
return closeSocket(sock);
338+
return ::close(sock);
339339
}
340340

341341
int WiFiSocketClass::hasParent(SOCKET sock, SOCKET child)

0 commit comments

Comments
 (0)