From 1db9177583cfc52fd6713dca1b69160f8ddfacc8 Mon Sep 17 00:00:00 2001 From: David Maloney Date: Fri, 2 Dec 2011 13:35:43 -0500 Subject: [PATCH] Revert "Merge pull request #22 from scriptjunkie/multithread" This reverts commit 4f76f3bbb83ffe4de74a849ad9f68707e3568e16, reversing changes made to e72dad4e8189e3b731eaa4dd9d72f3d10d91c7fc. --- lib/msf/core/rpc/v10/service.rb | 3 +-- lib/rex/io/stream_server.rb | 33 ++++++++------------------------- lib/rex/proto/http/server.rb | 8 +++----- lib/rex/socket.rb | 3 --- lib/rex/socket/parameters.rb | 23 +---------------------- 5 files changed, 13 insertions(+), 57 deletions(-) diff --git a/lib/msf/core/rpc/v10/service.rb b/lib/msf/core/rpc/v10/service.rb index f3f1914b8b..83e29f2641 100644 --- a/lib/msf/core/rpc/v10/service.rb +++ b/lib/msf/core/rpc/v10/service.rb @@ -63,8 +63,7 @@ class Service self.options[:ssl], self.options[:context], self.options[:comm], - self.options[:cert], - true + self.options[:cert] ) self.service.add_resource(self.uri, { diff --git a/lib/rex/io/stream_server.rb b/lib/rex/io/stream_server.rb index 3c27521991..e32082dea1 100644 --- a/lib/rex/io/stream_server.rb +++ b/lib/rex/io/stream_server.rb @@ -68,13 +68,9 @@ module StreamServer self.listener_thread = Rex::ThreadFactory.spawn("StreamServerListener", false) { monitor_listener } - if self.threaded - self.clients_thread = [] - else - self.clients_thread = Rex::ThreadFactory.spawn("StreamServerClientMonitor", false) { - monitor_clients - } - end + self.clients_thread = Rex::ThreadFactory.spawn("StreamServerClientMonitor", false) { + monitor_clients + } end # @@ -82,7 +78,7 @@ module StreamServer # def stop self.listener_thread.kill - self.clients_thread.kill unless self.threaded + self.clients_thread.kill self.clients.each { |cli| close_client(cli) @@ -95,7 +91,6 @@ module StreamServer # def close_client(client) if (client) - clients_thread.delete_at(clients.index(client)) if self.threaded clients.delete(client) begin @@ -135,7 +130,7 @@ module StreamServer attr_accessor :on_client_close_proc attr_accessor :clients # :nodoc: - attr_accessor :listener_thread, :clients_thread, :threaded # :nodoc: + attr_accessor :listener_thread, :clients_thread # :nodoc: attr_accessor :client_waiter protected @@ -161,12 +156,6 @@ protected # Initialize the connection processing on_client_connect(cli) - if self.threaded # Start thread - self.clients_thread << Rex::ThreadFactory.spawn("StreamServerClientMonitor#{cli.to_s}", false, cli) { - monitor_clients(cli) - } - end - # Notify the client monitor self.client_waiter.push(cli) @@ -186,20 +175,16 @@ protected # This method monitors client connections for data and calls the # +on_client_data+ routine when new data arrives. # - def monitor_clients(cli = nil) + def monitor_clients begin # Wait for a notify if our client list is empty - if (not self.threaded and clients.length == 0) + if (clients.length == 0) self.client_waiter.pop next end - if self.threaded - sd = Rex::ThreadSafe.select([cli]) - else - sd = Rex::ThreadSafe.select(clients, nil, nil, nil) - end + sd = Rex::ThreadSafe.select(clients, nil, nil, nil) sd[0].each { |cfd| begin @@ -218,8 +203,6 @@ protected } rescue ::Rex::StreamClosedError => e - # Remove thread from the list if threaded - clients_thread.delete_at(clients.index(client)) if self.threaded # Remove the closed stream from the list clients.delete(e.stream) rescue ::Interrupt diff --git a/lib/rex/proto/http/server.rb b/lib/rex/proto/http/server.rb index 8f4e8f6ccb..077c15c707 100644 --- a/lib/rex/proto/http/server.rb +++ b/lib/rex/proto/http/server.rb @@ -99,14 +99,13 @@ class Server # Initializes an HTTP server as listening on the provided port and # hostname. # - def initialize(port = 80, listen_host = '0.0.0.0', ssl = false, context = {}, comm = nil, ssl_cert = nil, threaded = false) + def initialize(port = 80, listen_host = '0.0.0.0', ssl = false, context = {}, comm = nil, ssl_cert = nil) self.listen_host = listen_host self.listen_port = port self.ssl = ssl self.context = context self.comm = comm self.ssl_cert = ssl_cert - self.threaded = threaded self.listener = nil self.resources = {} @@ -138,8 +137,7 @@ class Server 'Context' => self.context, 'SSL' => self.ssl, 'SSLCert' => self.ssl_cert, - 'Comm' => self.comm, - 'Threaded' => self.threaded + 'Comm' => self.comm ) # Register callbacks @@ -262,7 +260,7 @@ class Server end attr_accessor :listen_port, :listen_host, :server_name, :context, :ssl, :comm, :ssl_cert - attr_accessor :listener, :resources, :threaded + attr_accessor :listener, :resources protected diff --git a/lib/rex/socket.rb b/lib/rex/socket.rb index bb0d4ed29a..1ed7ee2ff0 100644 --- a/lib/rex/socket.rb +++ b/lib/rex/socket.rb @@ -673,9 +673,6 @@ module Socket self.localport = params.localport self.context = params.context || {} self.ipv = params.v6 ? 6 : 4 - if (self.respond_to?('threaded')) - self.threaded = params.threaded? - end end end diff --git a/lib/rex/socket/parameters.rb b/lib/rex/socket/parameters.rb index add5d682bd..96b60073a1 100644 --- a/lib/rex/socket/parameters.rb +++ b/lib/rex/socket/parameters.rb @@ -97,11 +97,6 @@ class Rex::Socket::Parameters # # The number of seconds before a connection should time out # - # Threaded - # - # Whether the server is to spin off a new thread for each client. - # - def initialize(hash) if (hash['PeerHost']) @@ -143,13 +138,7 @@ class Rex::Socket::Parameters else self.ssl = false end - - if (hash['Threaded'] and hash['Threaded'].to_s =~ /^(t|y|1)/i) - self.threaded = true - else - self.threaded = false - end - + if (hash['SSLVersion'] and hash['SSLVersion'].to_s =~ /^(SSL2|SSL3|TLS1)$/i) self.ssl_version = hash['SSLVersion'] end @@ -284,12 +273,6 @@ class Rex::Socket::Parameters return v6 end - # - # Returns true if Multithreading has been enabled - # - def threaded? - return threaded - end ## # @@ -361,10 +344,6 @@ class Rex::Socket::Parameters # Whether we should use IPv6 # attr_accessor :v6 - # - # Whether we should be multithreaded - # - attr_accessor :threaded attr_accessor :proxies