ap

Dependencies:   DnsQuery

Dependents:   WizFi310_TCP_Echo_Server_Example

Fork of NetworkSocketAPI by NetworkSocketAPI

Revision:
90:0a988e4abb72
Parent:
89:b1d417383c0d
Child:
91:cad29ce6a01c
--- a/Socket.cpp	Tue Apr 19 18:20:38 2016 -0500
+++ b/Socket.cpp	Tue Apr 19 18:22:15 2016 -0500
@@ -16,12 +16,12 @@
 
 #include "Socket.h"
 
-Socket::Socket(NetworkInterface *iface, nsapi_protocol_t proto)
-    : _iface(iface)
+Socket::Socket()
+    : _iface(0)
+    , _socket(0)
     , _blocking(true)
     , _timeout(0)
 {
-    _socket = _iface->socket_create(proto);
 }
 
 Socket::~Socket()
@@ -31,6 +31,28 @@
     }
 }
 
+int Socket::open(NetworkInterface *iface, nsapi_protocol_t proto)
+{
+    _iface = iface;
+    _socket = _iface->socket_create(proto);
+}
+
+int Socket::close(bool shutdown)
+{
+    if (!_socket) {
+        return 0;
+    }
+
+    int err = _iface->socket_close(_socket, shutdown);
+    if (!err) {
+        void *socket = _socket;
+        _socket = 0;
+        _iface->socket_destroy(socket);
+    }
+
+    return err;
+}
+
 void Socket::set_blocking(bool blocking)
 {
     _blocking = blocking;
@@ -59,22 +81,6 @@
     return _iface->socket_get_option(_socket, optname, optval, optlen);
 }
 
-int Socket::close(bool shutdown)
-{
-    if (!_socket) {
-        return 0;
-    }
-
-    int err = _iface->socket_close(_socket, shutdown);
-    if (!err) {
-        void *socket = _socket;
-        _socket = 0;
-        _iface->socket_destroy(socket);
-    }
-
-    return err;
-}
-
 void Socket::thunk(void *p) 
 {
     FunctionPointer *fptr = (FunctionPointer *)p;