Custom and bugfix
Dependents: HTTPClient_HelloWorld_WIZ820io NTPClient_HelloWorld_WIZ820io TinyHTTPServer_WIZ820io
Fork of WIZ820ioInterface by
Revision 8:6ff41cd782f5, committed 2014-02-04
- Comitter:
- ban4jp
- Date:
- Tue Feb 04 03:20:06 2014 +0000
- Parent:
- 7:c0cd6680bcb7
- Commit message:
- Fixed TCPSocketServer compatibility. (2nd connection is not accepted.)
Changed in this revision
| Socket/TCPSocketServer.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Socket/TCPSocketServer.h | Show annotated file Show diff for this revision Revisions of this file |
--- 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;
}
--- a/Socket/TCPSocketServer.h Sun Feb 02 14:20:31 2014 +0000
+++ b/Socket/TCPSocketServer.h Tue Feb 04 03:20:06 2014 +0000
@@ -47,6 +47,11 @@
\return 0 on success, -1 on failure.
*/
int accept(TCPSocketConnection& connection);
+
+ private:
+ int _port;
+
+ int bind_socket();
};
#endif
ban4jp -
