Commit ee24b9f8 authored by Davis King's avatar Davis King

Made close_gracefully() into a noop if called on a null pointer.

parent e88aab79
...@@ -304,6 +304,9 @@ namespace dlib ...@@ -304,6 +304,9 @@ namespace dlib
unsigned long timeout unsigned long timeout
) )
{ {
if (!con)
return;
if(con->shutdown_outgoing()) if(con->shutdown_outgoing())
{ {
// there was an error so just close it now and return // there was an error so just close it now and return
......
...@@ -200,17 +200,19 @@ namespace dlib ...@@ -200,17 +200,19 @@ namespace dlib
); );
/*! /*!
requires requires
- con == a valid pointer to a connection object - con == a valid pointer to a connection object or 0
ensures ensures
- performs a graceful close of the given connection and if it takes longer than - This function does nothing if con == 0, otherwise it performs the following:
timeout milliseconds to complete then forces the connection closed. - performs a graceful close of the given connection and if it takes longer
- Specifically, a graceful close means that the outgoing part of con is than timeout milliseconds to complete then forces the connection closed.
closed (a FIN is sent) and then we wait for the other end to to close their - Specifically, a graceful close means that the outgoing part of con is
end of the connection. This way any data still on its way to the other closed (a FIN is sent) and then we wait for the other end to to close
end of the connection will be received properly. their end of the connection. This way any data still on its way to
- this function will block until the graceful close is completed or we timeout. the other end of the connection will be received properly.
- calls "delete con;". Thus con is no longer a valid pointer after this function - This function will block until the graceful close is completed or we
has finished. timeout.
- calls "delete con;". Thus con is no longer a valid pointer after this
function has finished.
throws throws
- std::bad_alloc or dlib::thread_error - std::bad_alloc or dlib::thread_error
If either of these exceptions are thrown con will still be closed via If either of these exceptions are thrown con will still be closed via
...@@ -225,17 +227,20 @@ namespace dlib ...@@ -225,17 +227,20 @@ namespace dlib
); );
/*! /*!
requires requires
- con == a valid pointer to a connection object - con == a valid pointer to a connection object or con.get() == 0
ensures ensures
- performs a graceful close of the given connection and if it takes longer than - This function does nothing if con.get() == 0, otherwise it performs the
timeout milliseconds to complete then forces the connection closed. following:
- Specifically, a graceful close means that the outgoing part of con is - performs a graceful close of the given connection and if it takes longer
closed (a FIN is sent) and then we wait for the other end to to close their than timeout milliseconds to complete then forces the connection closed.
end of the connection. This way any data still on its way to the other - Specifically, a graceful close means that the outgoing part of con is
end of the connection will be received properly. closed (a FIN is sent) and then we wait for the other end to to close
- this function will block until the graceful close is completed or we timeout. their end of the connection. This way any data still on its way to
- #con.get() == 0. Thus con is no longer a valid pointer after this function the other end of the connection will be received properly.
has finished. - This function will block until the graceful close is completed or we
timeout.
- #con.get() == 0. Thus con is no longer a valid pointer after this
function has finished.
throws throws
- std::bad_alloc or dlib::thread_error - std::bad_alloc or dlib::thread_error
If either of these exceptions are thrown con will still be closed and If either of these exceptions are thrown con will still be closed and
......
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