mbed socket API

Dependents:   EthernetInterface EthernetInterface_RSF EthernetInterface EthernetInterface ... more

Deprecated

This is an mbed 2 sockets library. For mbed 5, network sockets have been revised to better support additional network stacks and thread safety here.

Files at this revision

API Documentation at this revision

Comitter:
emilmont
Date:
Mon Jul 23 11:52:50 2012 +0000
Parent:
1:8080965f5d76
Child:
3:e6474399e057
Commit message:
tidyup

Changed in this revision

TCPSocket.cpp Show annotated file Show diff for this revision Revisions of this file
TCPSocket.h Show annotated file Show diff for this revision Revisions of this file
UDPSocket.cpp Show annotated file Show diff for this revision Revisions of this file
UDPSocket.h Show annotated file Show diff for this revision Revisions of this file
bsd_socket.h Show diff for this revision Revisions of this file
socket.h Show annotated file Show diff for this revision Revisions of this file
--- a/TCPSocket.cpp	Tue Jun 26 15:32:12 2012 +0000
+++ b/TCPSocket.cpp	Mon Jul 23 11:52:50 2012 +0000
@@ -18,8 +18,6 @@
  
 #include "TCPSocket.h"
 
-#include "bsd_socket.h"
-
 #include <cstring>
 
 using std::memset;
@@ -45,7 +43,7 @@
   std::memset(&m_remoteHost, 0, sizeof(struct sockaddr_in));
 
   //Resolve DNS address or populate hard-coded IP address
-  struct hostent *server = ::gethostbyname(host);
+  struct hostent *server = gethostbyname(host);
   if(server == NULL)
   {
     return -1; //Could not resolve address
--- a/TCPSocket.h	Tue Jun 26 15:32:12 2012 +0000
+++ b/TCPSocket.h	Mon Jul 23 11:52:50 2012 +0000
@@ -19,7 +19,7 @@
 #ifndef TCPSOCKET_H
 #define TCPSOCKET_H
 
-#include "bsd_socket.h"
+#include "Socket/socket.h"
 
 /**
 This is a C++ abstraction for TCP networking sockets.
--- a/UDPSocket.cpp	Tue Jun 26 15:32:12 2012 +0000
+++ b/UDPSocket.cpp	Mon Jul 23 11:52:50 2012 +0000
@@ -17,7 +17,6 @@
  */
 
 #include "UDPSocket.h"
-#include "bsd_socket.h"
 
 #include <cstring>
 
--- a/UDPSocket.h	Tue Jun 26 15:32:12 2012 +0000
+++ b/UDPSocket.h	Mon Jul 23 11:52:50 2012 +0000
@@ -19,6 +19,7 @@
 #ifndef UDPSOCKET_H
 #define UDPSOCKET_H
 
+#include "Socket/socket.h"
 #include <cstdint>
 
 /**
--- a/bsd_socket.h	Tue Jun 26 15:32:12 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-/* Copyright (C) 2012 mbed.org, MIT License
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
- * and associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
- * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef BSD_SOCKET_H_
-#define BSD_SOCKET_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "socket/sys/socket.h" //Must conform to <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html>
-#include "socket/netinet/in.h" //Must conform to <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html>
-#include "socket/netdb.h"      //Must conform to <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netdb.h.html>
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* BSD_SOCKET_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/socket.h	Mon Jul 23 11:52:50 2012 +0000
@@ -0,0 +1,126 @@
+#ifndef SOCKET_H_
+#define SOCKET_H_
+
+#include "lwip/sockets.h"
+
+#define OK 0                //No error
+
+#define NET_FULL 1          //>All available resources are already used
+#define NET_EMPTY 2         //>No resource
+#define NET_NOTFOUND 3      //>Element cannot be found
+#define NET_INVALID 4       //>Invalid
+#define NET_CONTEXT 5       //>Called in a wrong context (eg during an interrupt)
+#define NET_TIMEOUT 6       //>Timeout
+#define NET_UNKNOWN 7       //>Unknown error
+#define NET_OVERFLOW 8      //>Overflow
+#define NET_PROCESSING 9    //>Command is processing
+#define NET_INTERRUPTED 10  //>Current operation has been interrupted
+#define NET_MOREINFO 11     //>More info on this error can be retrieved elsewhere (eg in a parameter passed as ptr)
+#define NET_ABORT 12        //>Current operation must be aborted
+#define NET_DIFF 13         //>Items that should match are different
+#define NET_AUTH 14         //>Authentication failed
+#define NET_PROTOCOL 15     //>Protocol error
+#define NET_OOM 16          //>Out of memory
+#define NET_CONN 17         //>Connection error
+#define NET_CLOSED 18       //>Connection was closed by remote end
+#define NET_TOOSMALL 19     //>Buffer is too small
+
+inline int accept(int s, struct sockaddr *addr, socklen_t *addrlen) {
+  return lwip_accept(s, addr, addrlen);
+}
+
+inline int bind(int s, const struct sockaddr *name, socklen_t namelen) {
+  return lwip_bind(s, name, namelen);
+}
+
+inline int shutdown(int s, int how) {
+  return lwip_shutdown(s, how);
+}
+
+inline int getsockname (int s, struct sockaddr *name, socklen_t *namelen) {
+  return lwip_getsockname(s, name, namelen);
+}
+
+inline int getpeername (int s, struct sockaddr *name, socklen_t *namelen) {
+  return lwip_getpeername(s, name, namelen);
+}
+
+inline int getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen) {
+  return lwip_getsockopt(s, level, optname, optval, optlen);
+}
+
+inline int setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen) {
+  return lwip_setsockopt(s, level, optname, optval, optlen);
+}
+
+inline int connect(int s, const struct sockaddr *name, socklen_t namelen) {
+  return lwip_connect(s, name, namelen);
+}
+
+inline int listen(int s, int backlog) {
+  return lwip_listen(s, backlog);
+}
+
+inline int recv(int s, void *mem, size_t len, int flags) {
+  return lwip_recv(s, mem, len, flags);
+}
+
+inline int recvfrom(int s, void *mem, size_t len, int flags,
+      struct sockaddr *from, socklen_t *fromlen) {
+  return lwip_recvfrom(s, mem, len, flags, from, fromlen);
+}
+
+inline int send(int s, const void *dataptr, size_t size, int flags) {
+  return lwip_send(s, dataptr, size, flags);
+}
+
+inline int sendto(int s, const void *dataptr, size_t size, int flags,
+    const struct sockaddr *to, socklen_t tolen) {
+  return lwip_sendto(s, dataptr, size, flags, to, tolen);
+}
+
+inline int socket(int domain, int type, int protocol) {
+  return lwip_socket(domain, type, protocol);
+}
+
+inline int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
+                struct timeval *timeout) {
+  return lwip_select(maxfdp1, readset, writeset, exceptset, timeout);
+}
+
+inline int ioctlsocket(int s, long cmd, void *argp) {
+  return lwip_ioctl(s, cmd, argp);
+}
+
+inline int read(int s, void *mem, size_t len) {
+  return lwip_read(s, mem, len);
+}
+
+inline int write(int s, const void *dataptr, size_t size) {
+  return lwip_write(s, dataptr, size);
+}
+
+inline int close(int s) {
+  return lwip_close(s);
+}
+
+#include "lwip/netdb.h"
+
+//DNS
+inline struct hostent *gethostbyname(const char *name) {
+  return lwip_gethostbyname(name);
+}
+
+inline int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) {
+  return lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop);
+}
+
+inline void freeaddrinfo(struct addrinfo *ai) {
+  return lwip_freeaddrinfo(ai);
+}
+
+inline int getaddrinfo(const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res) {
+  return lwip_getaddrinfo(nodename, servname, hints, res);
+}
+
+#endif /* SOCKET_H_ */