--- /dev/null
+////////////////////////////////////////////////////////////////////////////////\r
+\r
+// Author: Andy Rushton\r
+// Copyright: (c) Southampton University 1999-2004\r
+// (c) Andy Rushton 2004-2009\r
+// License: BSD License, see ../docs/license.html\r
+\r
+////////////////////////////////////////////////////////////////////////////////\r
+\r
+#include "tcp_sockets.hpp"\r
+\r
+////////////////////////////////////////////////////////////////////////////////\r
+\r
+namespace stlplus\r
+{\r
+\r
+ //////////////////////////////////////////////////////////////////////////////\r
+ // TCP Connection\r
+\r
+\r
+ TCP_connection::TCP_connection(const IP_socket& socket) : IP_socket(socket)\r
+ {\r
+ }\r
+\r
+ TCP_connection::TCP_connection(void) : IP_socket(TCP)\r
+ {\r
+ }\r
+\r
+ unsigned short TCP_connection::port(void) const\r
+ {\r
+ return remote_port();\r
+ }\r
+\r
+ ////////////////////////////////////////////////////////////////////////////////\r
+ // Server\r
+\r
+ TCP_server::TCP_server(void) : IP_socket(TCP)\r
+ {\r
+ }\r
+\r
+ TCP_server::TCP_server(unsigned short port, unsigned short queue) : IP_socket(TCP)\r
+ {\r
+ initialise(port,queue);\r
+ }\r
+\r
+ bool TCP_server::initialise(unsigned short port, unsigned short queue)\r
+ {\r
+ if (!IP_socket::bind_any(port)) return false;\r
+ return IP_socket::listen(queue);\r
+ }\r
+\r
+ TCP_connection TCP_server::accept(void)\r
+ {\r
+ return TCP_connection(IP_socket::accept());\r
+ }\r
+\r
+ bool TCP_server::connection_ready(unsigned timeout)\r
+ {\r
+ return accept_ready(timeout);\r
+ }\r
+\r
+ TCP_connection TCP_server::connection(void)\r
+ {\r
+ return accept();\r
+ }\r
+\r
+ //////////////////////////////////////////////////////////////////////////////\r
+ // Client\r
+\r
+ TCP_client::TCP_client(void) : IP_socket(TCP)\r
+ {\r
+ }\r
+\r
+ TCP_client::TCP_client(const std::string& address, unsigned short port, unsigned int timeout) : IP_socket(TCP)\r
+ {\r
+ initialise(address,port,timeout);\r
+ }\r
+\r
+ TCP_client::TCP_client(unsigned long address, unsigned short port, unsigned int timeout) : IP_socket(TCP)\r
+ {\r
+ initialise(address,port,timeout);\r
+ }\r
+\r
+ bool TCP_client::initialise(unsigned long remote_address, unsigned short remote_port, unsigned int timeout)\r
+ {\r
+ if (!IP_socket::connect(remote_address, remote_port))\r
+ {\r
+ close();\r
+ return false;\r
+ }\r
+ if (timeout && !IP_socket::connected(timeout))\r
+ {\r
+ close();\r
+ return false;\r
+ }\r
+ return true;\r
+ }\r
+\r
+ bool TCP_client::initialise(const std::string& address, unsigned short remote_port, unsigned int timeout)\r
+ {\r
+ // lookup the address and convert it into an IP number\r
+ unsigned long remote_address = IP_socket::ip_lookup(address);\r
+ if (!remote_address) return false;\r
+ return initialise(remote_address, remote_port, timeout);\r
+ }\r
+\r
+ unsigned short TCP_client::port(void) const\r
+ {\r
+ return remote_port();\r
+ }\r
+\r
+ unsigned long TCP_client::address(void) const\r
+ {\r
+ return remote_address();\r
+ }\r
+\r
+ ////////////////////////////////////////////////////////////////////////////////\r
+\r
+} // end namespace stlplus\r