ap

Dependencies:   DnsQuery

Dependents:   WizFi310_TCP_Echo_Server_Example

Fork of NetworkSocketAPI by NetworkSocketAPI

Branch:
api-changes
Revision:
41:3ec1c97e9bbf
Parent:
39:47138420ea42
Child:
42:49893d13c432
--- a/Socket.cpp	Mon Feb 22 23:52:09 2016 -0600
+++ b/Socket.cpp	Tue Feb 23 04:01:38 2016 -0600
@@ -24,6 +24,8 @@
 {
     memset(_ip_address, 0, SOCK_IP_SIZE);
     _port = 0;
+
+    _timeout = iface->getTimeout();
 }
 
 Socket::~Socket()
@@ -75,6 +77,20 @@
     return _port;
 }
 
+void Socket::setTimeout(uint32_t timeout)
+{
+    _timeout = timeout;
+
+    if (_socket) {
+        _socket->setTimeout(timeout);
+    }
+}
+
+uint32_t Socket::getTimeout() const
+{
+    return _timeout;
+}
+
 bool Socket::isConnected()
 {
     if (!_socket) {
@@ -86,13 +102,13 @@
 
 int32_t Socket::open(const char *url, uint16_t port)
 {
-    if (_socket) {
-        int32_t err = close();
-        if (err) return err;
-    }
+    int32_t err;
+
+    err = close();
+    if (err) return err;
 
     if (url) {
-        int32_t err = setURL(url);
+        err = setURL(url);
         if (err) return err;
     }
 
@@ -107,7 +123,9 @@
     _socket = _iface->createSocket(_proto);
     if (!_socket) return -2;
 
-    int32_t err = _socket->open(_ip_address, _port);
+    _socket->setTimeout(_timeout);
+
+    err = _socket->open(_ip_address, _port);
 
     if (err) {
         _iface->destroySocket(_socket);
@@ -129,15 +147,15 @@
     return err;
 }
 
-int32_t Socket::send(const void *data, uint32_t len, uint32_t timeout_ms)
+int32_t Socket::send(const void *data, uint32_t len)
 {
     if (!_socket) return -2;
-    return _socket->send(data, len, timeout_ms);
+    return _socket->send(data, len);
 }
 
-int32_t Socket::recv(void *data, uint32_t len, uint32_t timeout_ms)
+int32_t Socket::recv(void *data, uint32_t len)
 {
     if (!_socket) return -2;
-    return _socket->recv(data, len, timeout_ms);
+    return _socket->recv(data, len);
 }