Custom and bugfix

Dependents:   HTTPClient_HelloWorld_WIZ820io NTPClient_HelloWorld_WIZ820io TinyHTTPServer_WIZ820io

Fork of WIZ820ioInterface by Norimasa Okamoto

Revision:
8:6ff41cd782f5
Parent:
5:fb15c35d1e28
--- a/Socket/TCPSocketServer.cpp	Sun Feb 02 14:20:31 2014 +0000
+++ b/Socket/TCPSocketServer.cpp	Tue Feb 04 03:20:06 2014 +0000
@@ -22,16 +22,23 @@
 
 // Server initialization
 int TCPSocketServer::bind(int port) {
+    _port = port;
+    
     if (_sock_fd < 0) {
         _sock_fd = eth->new_socket();
         if (_sock_fd < 0) {
             return -1;
         }
     }
+    
+    return bind_socket();
+}
+
+int TCPSocketServer::bind_socket() {
     // set TCP protocol
     eth->setProtocol(_sock_fd, TCP);
     // set local port
-    eth->sreg<uint16_t>(_sock_fd, Sn_PORT, port);
+    eth->sreg<uint16_t>(_sock_fd, Sn_PORT, _port);
     // connect the network
     eth->scmd(_sock_fd, OPEN);
     return 0;
@@ -53,6 +60,7 @@
     if (_sock_fd < 0) {
         return -1;
     }
+    int next_sock_fd;
     Timer t;
     t.reset();
     t.start();
@@ -61,6 +69,10 @@
             return -1;
         }
         if (eth->sreg<uint8_t>(_sock_fd, Sn_SR) == SOCK_ESTABLISHED) {
+            next_sock_fd = eth->new_socket();
+            if (next_sock_fd < 0) {
+                continue;
+            }
             break;
         }
     }
@@ -70,5 +82,10 @@
     uint16_t port = eth->sreg<uint16_t>(_sock_fd, Sn_DPORT);
     connection._sock_fd = _sock_fd;
     connection.set_address(host, port);
+    
+    _sock_fd = next_sock_fd;
+    bind_socket();
+    eth->scmd(_sock_fd, LISTEN);
+    
     return 0;
 }