summaryrefslogtreecommitdiffstats
path: root/ml/dlib/dlib/linker
diff options
context:
space:
mode:
Diffstat (limited to 'ml/dlib/dlib/linker')
-rw-r--r--ml/dlib/dlib/linker/linker_kernel_1.cpp357
-rw-r--r--ml/dlib/dlib/linker/linker_kernel_1.h141
-rw-r--r--ml/dlib/dlib/linker/linker_kernel_abstract.h141
3 files changed, 0 insertions, 639 deletions
diff --git a/ml/dlib/dlib/linker/linker_kernel_1.cpp b/ml/dlib/dlib/linker/linker_kernel_1.cpp
deleted file mode 100644
index e76009b37..000000000
--- a/ml/dlib/dlib/linker/linker_kernel_1.cpp
+++ /dev/null
@@ -1,357 +0,0 @@
-// Copyright (C) 2003 Davis E. King (davis@dlib.net)
-// License: Boost Software License See LICENSE.txt for the full license.
-#ifndef DLIB_LINKER_KERNEL_1_CPp_
-#define DLIB_LINKER_KERNEL_1_CPp_
-#include "linker_kernel_1.h"
-
-namespace dlib
-{
-
-// ----------------------------------------------------------------------------------------
-// ----------------------------------------------------------------------------------------
- // member function definitions
-// ----------------------------------------------------------------------------------------
-// ----------------------------------------------------------------------------------------
-
- linker::
- linker (
- ) :
- running(false),
- running_signaler(running_mutex),
- A(0),
- B(0),
- service_connection_running_signaler(service_connection_running_mutex)
- {
- }
-
-// ----------------------------------------------------------------------------------------
-
- linker::
- linker (
- connection& a,
- connection& b
- ) :
- running(false),
- running_signaler(running_mutex),
- A(0),
- B(0),
- service_connection_running_signaler(service_connection_running_mutex)
- {
- link(a,b);
- }
-
-// ----------------------------------------------------------------------------------------
-
- linker::
- ~linker (
- )
- {
- clear();
- }
-
-// ----------------------------------------------------------------------------------------
-
- void linker::
- clear (
- )
- {
-
- // shutdown the connections
- cons_mutex.lock();
- if (A != 0 )
- {
- A->shutdown();
- A = 0;
- }
- if (B != 0)
- {
- B->shutdown();
- B = 0;
- }
- cons_mutex.unlock();
-
-
- // wait for the other threads to signal that they have ended
- running_mutex.lock();
- while (running == true)
- {
- running_signaler.wait();
- }
- running_mutex.unlock();
-
- }
-
-// ----------------------------------------------------------------------------------------
-
- bool linker::
- is_running (
- ) const
- {
- running_mutex.lock();
- bool temp = running;
- running_mutex.unlock();
- return temp;
- }
-
-// ----------------------------------------------------------------------------------------
-
- void linker::
- link (
- connection& a,
- connection& b
- )
- {
- // make sure requires clause is not broken
- DLIB_CASSERT(
- this->is_running() == false ,
- "\tvoid linker::link"
- << "\n\tis_running() == " << this->is_running()
- << "\n\tthis: " << this
- );
-
- running_mutex.lock();
- running = true;
- running_mutex.unlock();
-
- cons_mutex.lock();
- A = &a;
- B = &b;
- cons_mutex.unlock();
-
-
-
- service_connection_running_mutex.lock();
- service_connection_running = true;
- service_connection_running_mutex.unlock();
-
- service_connection_error_mutex.lock();
- service_connection_error = false;
- service_connection_error_mutex.unlock();
-
- // if we fail to make the thread
- if (!create_new_thread(service_connection,this))
- {
- a.shutdown();
- b.shutdown();
-
- service_connection_running_mutex.lock();
- service_connection_running = false;
- service_connection_running_mutex.unlock();
-
- cons_mutex.lock();
- A = 0;
- B = 0;
- cons_mutex.unlock();
-
- running_mutex.lock();
- running = false;
- running_mutex.unlock();
-
-
-
- throw dlib::thread_error (
- ECREATE_THREAD,
- "failed to make new thread in linker::link()"
- );
- }
-
-
-
- // forward data from a to b
- char buf[200];
- int status;
- bool error = false; // becomes true if one of the connections returns an error
- while (true)
- {
- status = a.read(buf,sizeof(buf));
- // if there was an error reading from the socket
- if (status == OTHER_ERROR)
- {
- error = true;
- break;
- }
- else if (status == SHUTDOWN)
- {
- b.shutdown();
- }
-
- if (status <= 0)
- {
- // if a has closed normally
- if (status == 0)
- b.shutdown_outgoing();
- break;
- }
-
- status = b.write(buf,status);
- // if there was an error writing to the socket then break
- if (status == OTHER_ERROR)
- {
- error = true;
- break;
- }
-
- if (status <= 0)
- break;
- }
-
-
- // if there was an error then shutdown both connections
- if (error)
- {
- a.shutdown();
- b.shutdown();
- }
-
-
-
-
- // wait for the other thread to end
- service_connection_running_mutex.lock();
- while(service_connection_running)
- {
- service_connection_running_signaler.wait();
- }
- service_connection_running_mutex.unlock();
-
-
- // make sure connections are shutdown
- a.shutdown();
- b.shutdown();
-
-
- // both threads have ended so the connections are no longer needed
- cons_mutex.lock();
- A = 0;
- B = 0;
- cons_mutex.unlock();
-
-
- // if service_connection terminated due to an error then set error to true
- service_connection_error_mutex.lock();
- if (service_connection_error)
- error = true;
- service_connection_error_mutex.unlock();
-
-
- // if we are ending because of an error
- if (error)
- {
-
- // signal that the link() function is ending
- running_mutex.lock();
- running = false;
- running_signaler.broadcast();
- running_mutex.unlock();
-
- // throw the exception for this error
- throw dlib::socket_error (
- ECONNECTION,
- "a connection returned an error in linker::link()"
- );
-
- }
-
- // signal that the link() function is ending
- running_mutex.lock();
- running = false;
- running_signaler.broadcast();
- running_mutex.unlock();
- }
-
-// ----------------------------------------------------------------------------------------
-
- void linker::
- service_connection (
- void* param
- )
- {
- linker& p = *static_cast<linker*>(param);
-
- p.cons_mutex.lock();
- // if the connections are gone for whatever reason then return
- if (p.A == 0 || p.B == 0)
- {
- // signal that this function is ending
- p.service_connection_running_mutex.lock();
- p.service_connection_running = false;
- p.service_connection_running_signaler.broadcast();
- p.service_connection_running_mutex.unlock();
- return;
- }
- connection& a = *p.A;
- connection& b = *p.B;
- p.cons_mutex.unlock();
-
-
-
- // forward data from b to a
- char buf[200];
- int status;
- bool error = false;
- while (true)
- {
- status = b.read(buf,sizeof(buf));
- // if there was an error reading from the socket
- if (status == OTHER_ERROR)
- {
- error = true;
- break;
- }
- else if (status == SHUTDOWN)
- {
- a.shutdown();
- }
-
-
- if (status <= 0)
- {
- // if b has closed normally
- if (status == 0)
- a.shutdown_outgoing();
- break;
- }
-
-
- status = a.write(buf,status);
- // if there was an error writing to the socket then break
- if (status == OTHER_ERROR)
- {
- error = true;
- break;
- }
-
- if (status <= 0)
- break;
- }
-
-
- // if there was an error then shutdown both connections
- if (error)
- {
- a.shutdown();
- b.shutdown();
- }
-
-
- // if there was an error then signal that
- if (error)
- {
- p.service_connection_error_mutex.lock();
- p.service_connection_error = true;
- p.service_connection_error_mutex.unlock();
- }
-
- // signal that this function is ending
- p.service_connection_running_mutex.lock();
- p.service_connection_running = false;
- p.service_connection_running_signaler.broadcast();
- p.service_connection_running_mutex.unlock();
-
- }
-
-// ----------------------------------------------------------------------------------------
-
-}
-#endif // DLIB_LINKER_KERNEL_1_CPp_
-
diff --git a/ml/dlib/dlib/linker/linker_kernel_1.h b/ml/dlib/dlib/linker/linker_kernel_1.h
deleted file mode 100644
index b101026b2..000000000
--- a/ml/dlib/dlib/linker/linker_kernel_1.h
+++ /dev/null
@@ -1,141 +0,0 @@
-// Copyright (C) 2003 Davis E. King (davis@dlib.net)
-// License: Boost Software License See LICENSE.txt for the full license.
-#ifndef DLIB_LINKER_KERNEl_1_
-#define DLIB_LINKER_KERNEl_1_
-
-#include "linker_kernel_abstract.h"
-#include "../threads.h"
-#include "../sockets.h"
-#include "../algs.h"
-
-
-namespace dlib
-{
-
- class linker
- {
-
- /*!
- INITIAL VALUE
- running == false
- A == 0
- B == 0
- running_mutex == a mutex
- running_signaler == a signaler associated with running_mutex
- cons_mutex == a mutex
- service_connection_running == false
- service_connection_running_mutex == a mutex
- service_connection_running_signaler == a signaler associated with
- service_connection_running_mutex
-
- service_connection_error == false
- service_connection_error_mutex == a mutex
-
-
-
- CONVENTION
- running == is_running()
- running_mutex == a mutex for running
- running_signaler == a signaler for signaling when
- running becomes false and is associated with
- running_mutex
- cons_mutex == a mutex for A and B
-
- service_connection_running == true when service_connection() is
- running or is about to run else
- false
- service_connection_running_mutex == a mutex for service_connection_running
- service_connection_running_signaler == a signaler associated with
- service_connection_running_mutex
-
- if (running) then
- A == address of a from link()
- B == address of b from link()
- else
- A == 0
- B == 0
-
- service_connection_error == service_connection uses this bool
- to indicate if it terminated due to
- an error or not
- service_connection_error_mutex == a mutex for service_connection_error
-
-
- !*/
-
- public:
-
- // These two typedefs are here for backwards compatibility with previous
- // versions of dlib.
- typedef linker kernel_1a;
- typedef linker kernel_1a_c;
-
- linker(
- );
-
- linker (
- connection& a,
- connection& b
- );
-
- virtual ~linker(
- );
-
- void clear(
- );
-
- bool is_running(
- ) const;
-
- void link (
- connection& a,
- connection& b
- );
-
-
- private:
-
- static void service_connection (
- void* param
- );
- /*!
- requires
- param == pointer to a linker object
- ensures
- waits for data from b and forwards it to a and
- if (b closes normally or is shutdown()) service_connection ends and
- if (b closes normally) then a.shutdown_outgoing() is called and
- if (a or b returns an error) then a and b are shutdown()
- !*/
-
-
- // data members
- bool running;
- mutex running_mutex;
- signaler running_signaler;
- connection* A;
- connection* B;
- mutex cons_mutex;
-
- bool service_connection_running;
- mutex service_connection_running_mutex;
- signaler service_connection_running_signaler;
-
- bool service_connection_error;
- mutex service_connection_error_mutex;
-
- // restricted functions
- linker(linker&); // copy constructor
- linker& operator=(linker&); // assignment operator
- };
-
-
-
-}
-
-#ifdef NO_MAKEFILE
-#include "linker_kernel_1.cpp"
-#endif
-
-#endif // DLIB_LINKER_KERNEl_1_
-
diff --git a/ml/dlib/dlib/linker/linker_kernel_abstract.h b/ml/dlib/dlib/linker/linker_kernel_abstract.h
deleted file mode 100644
index cef0901e4..000000000
--- a/ml/dlib/dlib/linker/linker_kernel_abstract.h
+++ /dev/null
@@ -1,141 +0,0 @@
-// Copyright (C) 2003 Davis E. King (davis@dlib.net)
-// License: Boost Software License See LICENSE.txt for the full license.
-#undef DLIB_LINKER_KERNEl_ABSTRACT_
-#ifdef DLIB_LINKER_KERNEl_ABSTRACT_
-
-#include "../threads/threads_kernel_abstract.h"
-#include "../sockets/sockets_kernel_abstract.h"
-
-namespace dlib
-{
-
- class linker
- {
-
- /*!
- INITIAL VALUE
- is_running() == false
-
-
- WHAT THIS OBJECT REPRESENTS
- This object represents something that takes two connections and lets
- them talk to each other. i.e. any incoming data from one connection is
- passed unaltered to the other and vice versa.
-
- note that linker objects are not swappable.
-
- Also note that when one connection is closed shutdown_outgoing()
- is called on the other to signal that no more data will be sent
- in that direction on the connection.
- (i.e. the FIN packet is effectively also forwarded by the linker object)
-
- THREAD SAFETY
- all member functions are thread-safe.
-
- !*/
-
- public:
-
- linker(
- );
- /*!
- ensures
- - #*this is properly initialized
- throws
- - std::bad_alloc
- - dlib::thread_error
- !*/
-
- linker (
- connection& a,
- connection& b
- );
- /*!
- ensures
- - #*this is properly initialized
- - immediately invokes link(a,b);
- (i.e. using this constructor is the same as creating a linker with
- the default constructor and then immediately invoking link() on it)
- throws
- - std::bad_alloc
- - dlib::thread_error
- !*/
-
- virtual ~linker(
- );
- /*!
- ensures
- - all resources associated with *this have been released
- !*/
-
- void clear(
- );
- /*!
- ensures
- - #*this has its initial value
- - if (is_running()) then
- - the two connections being linked will be shutdown()
- throws
- - std::bad_alloc
- if this exception is thrown then the linker object is unusable
- until clear() is called and succeeds and
- if is_running() then the connections will STILL be shutdown()
- even though an exception is being thrown
- !*/
-
- bool is_running(
- ) const;
- /*!
- ensures
- - returns true if link() is running else
- - returns false if link() is not running or has released all its
- resources and is about to terminate
- throws
- - std::bad_alloc
- !*/
-
-
- void link (
- connection& a,
- connection& b
- );
- /*!
- requires
- - is_running() == false
- ensures
- - all incoming data from connection a will be forwarded to b
- - all incoming data from connection b will be forwarded to a
- - #a and #b will have been shutdown()
- - link() will block until both of the connections have ended
- or an error occurs
- throws
- - std::bad_alloc
- link() may throw this exception and if it does then the object
- will be unusable until clear() is called and succeeds and
- connections a and b will be shutdown()
- - dlib::socket_error
- link() will throw a this exception if one of the connections
- returns an error value (being shutdown is not an error).
- If this happens then the linker object will be cleared and
- have its initial value. note that if this happens then the
- connections being linked will be shutdown()
- - dlib::thread_error
- link() will throw a this exception if there is a problem
- creating new threads. Or it may throw this exception if there
- is a problem creating threading objects. If this happens
- then the linker object will be cleared and have its initial value.
- note that if this happens then the connections being linked will
- be shutdown().
- !*/
-
- private:
-
- // restricted functions
- linker(linker&); // copy constructor
- linker& operator=(linker&); // assignment operator
- };
-
-}
-
-#endif // DLIB_LINKER_KERNEl_ABSTRACT_
-