NetworkSocketAPI

Dependencies:   DnsQuery

Dependents:   HelloWizFi250Interface

Fork of NetworkSocketAPI by NetworkSocketAPI

Revision:
81:1600369a29dd
Parent:
80:9c6673c93082
Child:
87:94e2cf3a06be
--- a/NetworkInterface.h	Tue Apr 05 12:02:56 2016 -0500
+++ b/NetworkInterface.h	Tue Apr 05 12:52:07 2016 -0500
@@ -17,6 +17,9 @@
 #ifndef NETWORK_INTERFACE_H
 #define NETWORK_INTERFACE_H
 
+#ifndef MBED_OPERATORS
+#define MBED_OPERATORS
+#endif
 #include "FunctionPointer.h"
 #include "SocketAddress.h"
 
@@ -135,31 +138,35 @@
     */
     virtual int socket_listen(void *handle, int backlog) = 0;
 
-    /** Accept a new connection.
-    \param handle   Socket handle
-    \param socket   A TCPSocket instance that will handle the incoming connection.
-    \return         0 on success, negative on failure.
-    */
-    virtual int socket_accept(void *handle, void **connection) = 0;
-    
     /** Connects this TCP socket to the server
     \param handle   Socket handle
     \param address  SocketAddress to connect to
     \return         0 on success, negative on failure
     */
     virtual int socket_connect(void *handle, const SocketAddress &address) = 0;
-
+    
     /** Check if the socket is connected
     \param handle   Socket handle
     \return         true if connected, false otherwise
     */
     virtual bool socket_is_connected(void *handle) = 0;
 
+    /** Accept a new connection.
+    \param handle   Socket handle
+    \param socket   A TCPSocket instance that will handle the incoming connection.
+    \return         0 on success, negative on failure.
+    \note This call is not-blocking, if this call would block, must
+          immediately return NSAPI_ERROR_WOULD_WAIT
+    */
+    virtual int socket_accept(void *handle, void **connection) = 0;
+
     /** Send data to the remote host
     \param handle   Socket handle
     \param data     The buffer to send to the host
     \param size     The length of the buffer to send
     \return         Number of written bytes on success, negative on failure
+    \note This call is not-blocking, if this call would block, must
+          immediately return NSAPI_ERROR_WOULD_WAIT
     */
     virtual int socket_send(void *handle, const void *data, unsigned size) = 0;
 
@@ -168,6 +175,8 @@
     \param data     The buffer in which to store the data received from the host
     \param size     The maximum length of the buffer
     \return         Number of received bytes on success, negative on failure
+    \note This call is not-blocking, if this call would block, must
+          immediately return NSAPI_ERROR_WOULD_WAIT
     */
     virtual int socket_recv(void *handle, void *data, unsigned size) = 0;
 
@@ -177,6 +186,8 @@
     \param data     The packet to be sent
     \param size     The length of the packet to be sent
     \return the number of written bytes on success, negative on failure
+    \note This call is not-blocking, if this call would block, must
+          immediately return NSAPI_ERROR_WOULD_WAIT
     */
     virtual int socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned size) = 0;
 
@@ -188,6 +199,8 @@
                     excess bytes are discarded
     \param size     The length of the buffer
     \return the number of received bytes on success, negative on failure
+    \note This call is not-blocking, if this call would block, must
+          immediately return NSAPI_ERROR_WOULD_WAIT
     */
     virtual int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size) = 0;
 
@@ -201,22 +214,25 @@
     \param handle   Socket handle
     \param callback Function to call when accept will succeed, may be called in
                     interrupt context.
+    \param id       Argument to pass to callback
     */
-    virtual void socket_attach_accept(void *handle, mbed::FuncPtr<void()> callback) = 0;
+    virtual void socket_attach_accept(void *handle, void (*callback)(void *), void *id) = 0;
 
     /** Register a callback on when send is ready
     \param handle   Socket handle
-    \param callback Function to call when send will succeed, may be called in
+    \param callback Function to call when accept will succeed, may be called in
                     interrupt context.
+    \param id       Argument to pass to callback
     */
-    virtual void socket_attach_send(void *handle, mbed::FuncPtr<void()> callback) = 0;
+    virtual void socket_attach_send(void *handle, void (*callback)(void *), void *id) = 0;
 
     /** Register a callback on when recv is ready
     \param handle   Socket handle
-    \param callback Function to call when recv will succeed, may be called in
+    \param callback Function to call when accept will succeed, may be called in
                     interrupt context.
+    \param id       Argument to pass to callback
     */
-    virtual void socket_attach_recv(void *handle, mbed::FuncPtr<void()> callback) = 0;
+    virtual void socket_attach_recv(void *handle, void (*callback)(void *), void *id) = 0;
 };
 
 #endif