Implementation of the NetworkSocketAPI for LWIP
Dependencies: lwip-eth lwip-sys lwip
Dependents: HelloLWIPInterface HelloLWIPInterfaceNonBlocking LWIPInterfaceTests SimpleHTTPExample ... more
Diff: LWIPInterface.cpp
- Revision:
- 14:67b325c56cde
- Parent:
- 13:57d9e1721826
- Child:
- 15:0d8d1dafe064
--- a/LWIPInterface.cpp Tue Apr 05 15:29:20 2016 -0500 +++ b/LWIPInterface.cpp Tue Apr 05 23:38:36 2016 +0000 @@ -130,24 +130,26 @@ return 0; } - return (void *)fd; + return (void *)(fd+1); } void LWIPInterface::socket_destroy(void *handle) { - int fd = (int)handle; + int fd = (int)handle-1; lwip_close(fd); } int LWIPInterface::socket_set_option(void *handle, int optname, const void *optval, unsigned optlen) { - return lwip_setsockopt((int)handle, SOL_SOCKET, optname, optval, (socklen_t)optlen); + int fd = (int)handle-1; + return lwip_setsockopt(fd, SOL_SOCKET, optname, optval, (socklen_t)optlen); } int LWIPInterface::socket_get_option(void *handle, int optname, void *optval, unsigned *optlen) { - return lwip_getsockopt((int)handle, SOL_SOCKET, optname, optval, (socklen_t*)optlen); + int fd = (int)handle-1; + return lwip_getsockopt(fd, SOL_SOCKET, optname, optval, (socklen_t*)optlen); } int LWIPInterface::socket_bind(void *handle, int port) @@ -162,7 +164,7 @@ int LWIPInterface::socket_connect(void *handle, const SocketAddress &addr) { - int fd = (int)handle; + int fd = (int)handle-1; struct sockaddr_in sa; memset(&sa, 0, sizeof sa); inet_aton(addr.get_ip_address(), &sa.sin_addr); @@ -188,7 +190,7 @@ int LWIPInterface::socket_send(void *handle, const void *p, unsigned size) { - int fd = (int)handle; + int fd = (int)handle-1; uint8_t *data = (uint8_t *)p; unsigned written = 0; @@ -209,7 +211,7 @@ int LWIPInterface::socket_recv(void *handle, void *data, unsigned size) { - int fd = (int)handle; + int fd = (int)handle-1; int ret = lwip_recv(fd, data, size, MSG_DONTWAIT); if (ret > 0) { @@ -225,7 +227,7 @@ int LWIPInterface::socket_sendto(void *handle, const SocketAddress &addr, const void *p, unsigned size) { - int fd = (int)handle; + int fd = (int)handle-1; uint8_t *data = (uint8_t *)p; unsigned written = 0; @@ -253,7 +255,7 @@ int LWIPInterface::socket_recvfrom(void *handle, SocketAddress *addr, void *data, unsigned size) { - int fd = (int)handle; + int fd = (int)handle-1; struct sockaddr_in sa; socklen_t sa_len = sizeof sa; @@ -265,7 +267,7 @@ addr->set_port(ntohs(sa.sin_port)); } - if (ret > 0) { + if (ret > 0) { return ret; } else if (ret == 0) { return NSAPI_ERROR_NO_CONNECTION; @@ -278,7 +280,7 @@ int LWIPInterface::socket_close(void *handle, bool shutdown) { - int fd = (int)handle; + int fd = (int)handle-1; if (shutdown) { lwip_shutdown(fd, SHUT_RDWR); }