]>
Dogcows Code - chaz/yoink/blob - tcp_sockets.cpp
b15f6382f4fc2bc63ded58e2746b33b81ba07281
1 ////////////////////////////////////////////////////////////////////////////////
3 // Author: Andy Rushton
4 // Copyright: (c) Southampton University 1999-2004
5 // (c) Andy Rushton 2004-2009
6 // License: BSD License, see ../docs/license.html
8 ////////////////////////////////////////////////////////////////////////////////
10 #include "tcp_sockets.hpp"
12 ////////////////////////////////////////////////////////////////////////////////
17 //////////////////////////////////////////////////////////////////////////////
21 TCP_connection::TCP_connection(const IP_socket
& socket
) : IP_socket(socket
)
25 TCP_connection::TCP_connection(void) : IP_socket(TCP
)
29 unsigned short TCP_connection::port(void) const
34 ////////////////////////////////////////////////////////////////////////////////
37 TCP_server::TCP_server(void) : IP_socket(TCP
)
41 TCP_server::TCP_server(unsigned short port
, unsigned short queue
) : IP_socket(TCP
)
43 initialise(port
,queue
);
46 bool TCP_server::initialise(unsigned short port
, unsigned short queue
)
48 if (!IP_socket::bind_any(port
)) return false;
49 return IP_socket::listen(queue
);
52 TCP_connection
TCP_server::accept(void)
54 return TCP_connection(IP_socket::accept());
57 bool TCP_server::connection_ready(unsigned timeout
)
59 return accept_ready(timeout
);
62 TCP_connection
TCP_server::connection(void)
67 //////////////////////////////////////////////////////////////////////////////
70 TCP_client::TCP_client(void) : IP_socket(TCP
)
74 TCP_client::TCP_client(const std::string
& address
, unsigned short port
, unsigned int timeout
) : IP_socket(TCP
)
76 initialise(address
,port
,timeout
);
79 TCP_client::TCP_client(unsigned long address
, unsigned short port
, unsigned int timeout
) : IP_socket(TCP
)
81 initialise(address
,port
,timeout
);
84 bool TCP_client::initialise(unsigned long remote_address
, unsigned short remote_port
, unsigned int timeout
)
86 if (!IP_socket::connect(remote_address
, remote_port
))
91 if (timeout
&& !IP_socket::connected(timeout
))
99 bool TCP_client::initialise(const std::string
& address
, unsigned short remote_port
, unsigned int timeout
)
101 // lookup the address and convert it into an IP number
102 unsigned long remote_address
= IP_socket::ip_lookup(address
);
103 if (!remote_address
) return false;
104 return initialise(remote_address
, remote_port
, timeout
);
107 unsigned short TCP_client::port(void) const
109 return remote_port();
112 unsigned long TCP_client::address(void) const
114 return remote_address();
117 ////////////////////////////////////////////////////////////////////////////////
119 } // end namespace stlplus
This page took 0.038562 seconds and 3 git commands to generate.