Commit 2afaa28c authored by Davis King's avatar Davis King

Added a clear() to the bridge and improved some comments and tests.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%404277
parent f224398e
...@@ -511,6 +511,11 @@ namespace dlib ...@@ -511,6 +511,11 @@ namespace dlib
) { reconfigure(network_parameters,pipe); } ) { reconfigure(network_parameters,pipe); }
void clear (
)
{
pimpl.reset();
}
template < typename T, typename R > template < typename T, typename R >
void reconfigure ( void reconfigure (
......
...@@ -160,6 +160,15 @@ namespace dlib ...@@ -160,6 +160,15 @@ namespace dlib
- blocks until all resources associated with this object have been destroyed. - blocks until all resources associated with this object have been destroyed.
!*/ !*/
void clear (
);
/*!
ensures
- returns this object to its default constructed state. That is, it will
be inactive, neither maintaining a connection nor attempting to acquire one.
- Any active connections or listening sockets will be closed.
!*/
bridge_status get_bridge_status ( bridge_status get_bridge_status (
) const; ) const;
/*! /*!
...@@ -171,6 +180,13 @@ namespace dlib ...@@ -171,6 +180,13 @@ namespace dlib
- if (BS.is_connected) then - if (BS.is_connected) then
- BS.foreign_ip == the IP address of the remote host we are connected to. - BS.foreign_ip == the IP address of the remote host we are connected to.
- BS.foreign_port == the port number on the remote host we are connected to. - BS.foreign_port == the port number on the remote host we are connected to.
- else if (the bridge has previously been connected to a remote host but hasn't been
reconfigured or cleared since) then
- BS.foreign_ip == the IP address of the remote host we were connected to.
- BS.foreign_port == the port number on the remote host we were connected to.
- else
- BS.foreign_ip == ""
- BS.foreign_port == 0
!*/ !*/
...@@ -196,7 +212,8 @@ namespace dlib ...@@ -196,7 +212,8 @@ namespace dlib
- if (the receive pipe can contain bridge_status objects) then - if (the receive pipe can contain bridge_status objects) then
- Whenever the bridge's status changes the updated bridge_status will be - Whenever the bridge's status changes the updated bridge_status will be
enqueued onto the receive pipe unless the change was a TCP disconnect enqueued onto the receive pipe unless the change was a TCP disconnect
resulting from a user calling reconfigure() or destructing this bridge. resulting from a user calling reconfigure(), clear(), or destructing this
bridge. The status contents are defined by get_bridge_status().
throws throws
- socket_error - socket_error
This exception is thrown if we are unable to open the listening socket. This exception is thrown if we are unable to open the listening socket.
...@@ -256,7 +273,8 @@ namespace dlib ...@@ -256,7 +273,8 @@ namespace dlib
- if (the receive pipe can contain bridge_status objects) then - if (the receive pipe can contain bridge_status objects) then
- Whenever the bridge's status changes the updated bridge_status will be - Whenever the bridge's status changes the updated bridge_status will be
enqueued onto the receive pipe unless the change was a TCP disconnect enqueued onto the receive pipe unless the change was a TCP disconnect
resulting from a user calling reconfigure() or destructing this bridge. resulting from a user calling reconfigure(), clear(), or destructing this
bridge. The status contents are defined by get_bridge_status().
!*/ !*/
template <typename T, typename R> template <typename T, typename R>
void reconfigure ( void reconfigure (
......
...@@ -110,6 +110,11 @@ namespace ...@@ -110,6 +110,11 @@ namespace
DLIB_TEST(msg.get<bridge_status>().is_connected == true); DLIB_TEST(msg.get<bridge_status>().is_connected == true);
DLIB_TEST(msg.get<bridge_status>().foreign_ip == "127.0.0.1"); DLIB_TEST(msg.get<bridge_status>().foreign_ip == "127.0.0.1");
DLIB_TEST(msg.get<bridge_status>().foreign_port == testing_port); DLIB_TEST(msg.get<bridge_status>().foreign_port == testing_port);
msg = b1.get_bridge_status();
DLIB_TEST(msg.contains<bridge_status>() == true);
DLIB_TEST(msg.get<bridge_status>().is_connected == true);
DLIB_TEST(msg.get<bridge_status>().foreign_ip == "127.0.0.1");
DLIB_TEST(msg.get<bridge_status>().foreign_port == testing_port);
bridge_status temp; bridge_status temp;
out_status.dequeue(temp); out_status.dequeue(temp);
...@@ -130,6 +135,61 @@ namespace ...@@ -130,6 +135,61 @@ namespace
} }
in.dequeue(msg);
DLIB_TEST(msg.contains<bridge_status>() == true);
DLIB_TEST(msg.get<bridge_status>().is_connected == false);
DLIB_TEST(msg.get<bridge_status>().foreign_ip == "127.0.0.1");
DLIB_TEST(msg.get<bridge_status>().foreign_port == testing_port);
msg = b1.get_bridge_status();
DLIB_TEST(msg.contains<bridge_status>() == true);
DLIB_TEST(msg.get<bridge_status>().is_connected == false);
DLIB_TEST(msg.get<bridge_status>().foreign_ip == "127.0.0.1");
DLIB_TEST(msg.get<bridge_status>().foreign_port == testing_port);
}
void do_test5_5(int pipe_size)
{
typedef type_safe_union<int, bridge_status> tsu_type;
dlib::pipe<tsu_type> out(pipe_size);
dlib::pipe<tsu_type> in(pipe_size);
dlib::pipe<bridge_status> out_status(pipe_size);
bridge b1(connect_to_ip_and_port("127.0.0.1",testing_port), receive(in));
tsu_type msg;
bridge b2(listen_on_port(testing_port), transmit(out), receive(out_status));
in.dequeue(msg);
DLIB_TEST(msg.contains<bridge_status>() == true);
DLIB_TEST(msg.get<bridge_status>().is_connected == true);
DLIB_TEST(msg.get<bridge_status>().foreign_ip == "127.0.0.1");
DLIB_TEST(msg.get<bridge_status>().foreign_port == testing_port);
bridge_status temp;
out_status.dequeue(temp);
DLIB_TEST(temp.is_connected == true);
DLIB_TEST(temp.foreign_ip == "127.0.0.1");
for (int i = 0; i < 100; ++i)
{
msg = i;
out.enqueue(msg);
msg.get<int>() = 0;
in.dequeue(msg);
DLIB_TEST(msg.contains<int>() == true);
DLIB_TEST(msg.get<int>() == i);
}
b2.clear();
msg = b2.get_bridge_status();
DLIB_TEST(msg.contains<bridge_status>() == true);
DLIB_TEST(msg.get<bridge_status>().is_connected == false);
DLIB_TEST(msg.get<bridge_status>().foreign_ip == "");
DLIB_TEST(msg.get<bridge_status>().foreign_port == 0);
in.dequeue(msg); in.dequeue(msg);
DLIB_TEST(msg.contains<bridge_status>() == true); DLIB_TEST(msg.contains<bridge_status>() == true);
DLIB_TEST(msg.get<bridge_status>().is_connected == false); DLIB_TEST(msg.get<bridge_status>().is_connected == false);
...@@ -184,6 +244,7 @@ namespace ...@@ -184,6 +244,7 @@ namespace
print_spinner(); print_spinner();
for (int i = 0; i < 5; ++i) for (int i = 0; i < 5; ++i)
do_test5(i); do_test5(i);
do_test5_5(1);
print_spinner(); print_spinner();
do_test6(); do_test6();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment