eventmachine 0.12.10-x86-mswin32-60 → 1.0.0.beta.2-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +1 -0
- data/README +80 -81
- data/Rakefile +7 -370
- data/docs/COPYING +60 -60
- data/docs/ChangeLog +211 -211
- data/docs/DEFERRABLES +246 -133
- data/docs/EPOLL +141 -141
- data/docs/GNU +281 -281
- data/docs/INSTALL +13 -13
- data/docs/KEYBOARD +42 -38
- data/docs/LEGAL +25 -25
- data/docs/LIGHTWEIGHT_CONCURRENCY +130 -70
- data/docs/PURE_RUBY +75 -75
- data/docs/RELEASE_NOTES +94 -94
- data/docs/SMTP +4 -2
- data/docs/SPAWNED_PROCESSES +148 -89
- data/docs/TODO +8 -8
- data/eventmachine.gemspec +19 -26
- data/examples/ex_channel.rb +42 -42
- data/examples/ex_queue.rb +2 -2
- data/examples/ex_tick_loop_array.rb +15 -0
- data/examples/ex_tick_loop_counter.rb +32 -0
- data/examples/helper.rb +1 -1
- data/ext/binder.cpp +0 -1
- data/ext/cmain.cpp +36 -25
- data/ext/ed.cpp +104 -113
- data/ext/ed.h +24 -30
- data/ext/em.cpp +349 -283
- data/ext/em.h +25 -29
- data/ext/eventmachine.h +5 -4
- data/ext/extconf.rb +58 -49
- data/ext/fastfilereader/extconf.rb +5 -3
- data/ext/fastfilereader/mapper.cpp +214 -214
- data/ext/fastfilereader/mapper.h +59 -59
- data/ext/fastfilereader/rubymain.cpp +127 -127
- data/ext/kb.cpp +1 -3
- data/ext/page.cpp +107 -107
- data/ext/page.h +51 -51
- data/ext/pipe.cpp +9 -11
- data/ext/project.h +12 -8
- data/ext/rubymain.cpp +138 -104
- data/java/.classpath +8 -8
- data/java/.project +17 -17
- data/java/src/com/rubyeventmachine/EmReactor.java +1 -0
- data/java/src/com/rubyeventmachine/EmReactorException.java +40 -40
- data/lib/em/buftok.rb +138 -138
- data/lib/em/callback.rb +25 -25
- data/lib/em/channel.rb +1 -1
- data/lib/em/connection.rb +6 -1
- data/lib/em/deferrable.rb +16 -2
- data/lib/em/file_watch.rb +53 -53
- data/lib/em/future.rb +61 -61
- data/lib/em/iterator.rb +270 -0
- data/lib/em/messages.rb +66 -66
- data/lib/em/process_watch.rb +43 -43
- data/lib/em/protocols.rb +1 -1
- data/lib/em/protocols/header_and_content.rb +138 -138
- data/lib/em/protocols/httpclient.rb +267 -262
- data/lib/em/protocols/line_protocol.rb +28 -0
- data/lib/em/protocols/memcache.rb +322 -322
- data/lib/em/protocols/postgres3.rb +247 -247
- data/lib/em/protocols/saslauth.rb +175 -175
- data/lib/em/protocols/smtpserver.rb +640 -547
- data/lib/em/protocols/stomp.rb +200 -200
- data/lib/em/protocols/tcptest.rb +52 -52
- data/lib/{pr_eventmachine.rb → em/pure_ruby.rb} +1013 -1022
- data/lib/em/queue.rb +1 -0
- data/lib/em/spawnable.rb +85 -85
- data/lib/em/streamer.rb +130 -130
- data/lib/em/tick_loop.rb +85 -0
- data/lib/em/timers.rb +2 -1
- data/lib/em/version.rb +1 -1
- data/lib/eventmachine.rb +40 -84
- data/lib/jeventmachine.rb +2 -1
- data/lib/rubyeventmachine.rb +2 -0
- data/setup.rb +1585 -1585
- data/tasks/doc.rake +30 -0
- data/tasks/package.rake +85 -0
- data/tasks/test.rake +6 -0
- data/tests/client.crt +31 -31
- data/tests/client.key +51 -51
- data/tests/test_attach.rb +13 -3
- data/tests/test_basic.rb +60 -95
- data/tests/test_channel.rb +3 -2
- data/tests/test_defer.rb +49 -47
- data/tests/test_deferrable.rb +35 -0
- data/tests/test_error_handler.rb +35 -35
- data/tests/test_errors.rb +82 -82
- data/tests/test_exc.rb +55 -55
- data/tests/test_file_watch.rb +49 -49
- data/tests/test_futures.rb +198 -198
- data/tests/test_handler_check.rb +36 -36
- data/tests/test_hc.rb +190 -218
- data/tests/test_httpclient.rb +227 -218
- data/tests/test_httpclient2.rb +3 -2
- data/tests/test_inactivity_timeout.rb +3 -3
- data/tests/test_kb.rb +60 -60
- data/tests/test_ltp.rb +13 -5
- data/tests/test_ltp2.rb +317 -317
- data/tests/test_next_tick.rb +1 -1
- data/tests/test_object_protocol.rb +36 -36
- data/tests/test_pending_connect_timeout.rb +2 -2
- data/tests/test_process_watch.rb +50 -48
- data/tests/test_proxy_connection.rb +52 -0
- data/tests/test_pure.rb +134 -125
- data/tests/test_queue.rb +44 -44
- data/tests/test_running.rb +42 -42
- data/tests/test_sasl.rb +72 -72
- data/tests/test_send_file.rb +251 -242
- data/tests/test_servers.rb +76 -76
- data/tests/test_smtpclient.rb +83 -83
- data/tests/test_smtpserver.rb +85 -85
- data/tests/test_spawn.rb +322 -322
- data/tests/test_ssl_methods.rb +49 -49
- data/tests/test_ssl_verify.rb +82 -82
- data/tests/test_tick_loop.rb +59 -0
- data/tests/test_timers.rb +13 -15
- data/tests/test_ud.rb +36 -36
- data/tests/testem.rb +31 -31
- metadata +66 -51
- data/ext/cplusplus.cpp +0 -202
- data/ext/emwin.cpp +0 -300
- data/ext/emwin.h +0 -94
- data/ext/epoll.cpp +0 -26
- data/ext/epoll.h +0 -25
- data/ext/eventmachine_cpp.h +0 -96
- data/ext/files.cpp +0 -94
- data/ext/files.h +0 -65
- data/ext/sigs.cpp +0 -89
- data/ext/sigs.h +0 -32
- data/java/src/com/rubyeventmachine/application/Application.java +0 -194
- data/java/src/com/rubyeventmachine/application/Connection.java +0 -74
- data/java/src/com/rubyeventmachine/application/ConnectionFactory.java +0 -37
- data/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +0 -46
- data/java/src/com/rubyeventmachine/application/PeriodicTimer.java +0 -38
- data/java/src/com/rubyeventmachine/application/Timer.java +0 -54
- data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +0 -109
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +0 -148
- data/java/src/com/rubyeventmachine/tests/EMTest.java +0 -80
- data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +0 -53
- data/java/src/com/rubyeventmachine/tests/TestServers.java +0 -75
- data/java/src/com/rubyeventmachine/tests/TestTimers.java +0 -90
- data/lib/evma.rb +0 -32
- data/lib/evma/callback.rb +0 -32
- data/lib/evma/container.rb +0 -75
- data/lib/evma/factory.rb +0 -77
- data/lib/evma/protocol.rb +0 -87
- data/lib/evma/reactor.rb +0 -48
- data/web/whatis +0 -7
data/eventmachine.gemspec
CHANGED
@@ -1,13 +1,24 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/em/version', __FILE__)
|
2
3
|
|
3
4
|
Gem::Specification.new do |s|
|
4
|
-
s.
|
5
|
-
s.version = "0.12.10"
|
5
|
+
s.date = "2010-11-13"
|
6
6
|
|
7
|
-
s.
|
8
|
-
s.
|
9
|
-
s.
|
10
|
-
s.
|
7
|
+
s.name = 'eventmachine'
|
8
|
+
s.version = EventMachine::VERSION
|
9
|
+
s.homepage = 'http://rubyeventmachine.com'
|
10
|
+
s.rubyforge_project = 'eventmachine'
|
11
|
+
|
12
|
+
s.authors = ["Francis Cianfrocca", "Aman Gupta"]
|
13
|
+
s.email = ["garbagecat10@gmail.com", "aman@tmm1.net"]
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.extensions = ["ext/extconf.rb", "ext/fastfilereader/extconf.rb"]
|
17
|
+
|
18
|
+
s.add_development_dependency 'rake-compiler'
|
19
|
+
|
20
|
+
s.summary = 'Ruby/EventMachine library'
|
21
|
+
s.description = "EventMachine implements a fast, single-threaded engine for arbitrary network
|
11
22
|
communications. It's extremely easy to use in Ruby. EventMachine wraps all
|
12
23
|
interactions with IP sockets, allowing programs to concentrate on the
|
13
24
|
implementation of network protocols. It can be used to create both network
|
@@ -16,25 +27,7 @@ to specify the IP address and port, and provide a Module that implements the
|
|
16
27
|
communications protocol. Implementations of several standard network protocols
|
17
28
|
are provided with the package, primarily to serve as examples. The real goal
|
18
29
|
of EventMachine is to enable programs to easily interface with other programs
|
19
|
-
using TCP/IP, especially if custom protocols are required.
|
20
|
-
}
|
21
|
-
s.email = %q{garbagecat10@gmail.com}
|
22
|
-
s.extensions = ["ext/extconf.rb", "ext/fastfilereader/extconf.rb"]
|
23
|
-
s.files = [".gitignore", "README", "Rakefile", "docs/COPYING", "docs/ChangeLog", "docs/DEFERRABLES", "docs/EPOLL", "docs/GNU", "docs/INSTALL", "docs/KEYBOARD", "docs/LEGAL", "docs/LIGHTWEIGHT_CONCURRENCY", "docs/PURE_RUBY", "docs/RELEASE_NOTES", "docs/SMTP", "docs/SPAWNED_PROCESSES", "docs/TODO", "eventmachine.gemspec", "examples/ex_channel.rb", "examples/ex_queue.rb", "examples/helper.rb", "ext/binder.cpp", "ext/binder.h", "ext/cmain.cpp", "ext/cplusplus.cpp", "ext/ed.cpp", "ext/ed.h", "ext/em.cpp", "ext/em.h", "ext/emwin.cpp", "ext/emwin.h", "ext/epoll.cpp", "ext/epoll.h", "ext/eventmachine.h", "ext/eventmachine_cpp.h", "ext/extconf.rb", "ext/fastfilereader/extconf.rb", "ext/fastfilereader/mapper.cpp", "ext/fastfilereader/mapper.h", "ext/fastfilereader/rubymain.cpp", "ext/files.cpp", "ext/files.h", "ext/kb.cpp", "ext/page.cpp", "ext/page.h", "ext/pipe.cpp", "ext/project.h", "ext/rubymain.cpp", "ext/sigs.cpp", "ext/sigs.h", "ext/ssl.cpp", "ext/ssl.h", "java/.classpath", "java/.project", "java/src/com/rubyeventmachine/EmReactor.java", "java/src/com/rubyeventmachine/EmReactorException.java", "java/src/com/rubyeventmachine/EventableChannel.java", "java/src/com/rubyeventmachine/EventableDatagramChannel.java", "java/src/com/rubyeventmachine/EventableSocketChannel.java", "java/src/com/rubyeventmachine/application/Application.java", "java/src/com/rubyeventmachine/application/Connection.java", "java/src/com/rubyeventmachine/application/ConnectionFactory.java", "java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java", "java/src/com/rubyeventmachine/application/PeriodicTimer.java", "java/src/com/rubyeventmachine/application/Timer.java", "java/src/com/rubyeventmachine/tests/ApplicationTest.java", "java/src/com/rubyeventmachine/tests/ConnectTest.java", "java/src/com/rubyeventmachine/tests/EMTest.java", "java/src/com/rubyeventmachine/tests/TestDatagrams.java", "java/src/com/rubyeventmachine/tests/TestServers.java", "java/src/com/rubyeventmachine/tests/TestTimers.java", "lib/em/buftok.rb", "lib/em/callback.rb", "lib/em/channel.rb", "lib/em/connection.rb", "lib/em/deferrable.rb", "lib/em/file_watch.rb", "lib/em/future.rb", "lib/em/messages.rb", "lib/em/process_watch.rb", "lib/em/processes.rb", "lib/em/protocols.rb", "lib/em/protocols/header_and_content.rb", "lib/em/protocols/httpclient.rb", "lib/em/protocols/httpclient2.rb", "lib/em/protocols/line_and_text.rb", "lib/em/protocols/linetext2.rb", "lib/em/protocols/memcache.rb", "lib/em/protocols/object_protocol.rb", "lib/em/protocols/postgres3.rb", "lib/em/protocols/saslauth.rb", "lib/em/protocols/smtpclient.rb", "lib/em/protocols/smtpserver.rb", "lib/em/protocols/socks4.rb", "lib/em/protocols/stomp.rb", "lib/em/protocols/tcptest.rb", "lib/em/queue.rb", "lib/em/spawnable.rb", "lib/em/streamer.rb", "lib/em/timers.rb", "lib/em/version.rb", "lib/eventmachine.rb", "lib/evma.rb", "lib/evma/callback.rb", "lib/evma/container.rb", "lib/evma/factory.rb", "lib/evma/protocol.rb", "lib/evma/reactor.rb", "lib/jeventmachine.rb", "lib/pr_eventmachine.rb", "setup.rb", "tasks/cpp.rake_example", "tests/client.crt", "tests/client.key", "tests/test_attach.rb", "tests/test_basic.rb", "tests/test_channel.rb", "tests/test_connection_count.rb", "tests/test_defer.rb", "tests/test_epoll.rb", "tests/test_error_handler.rb", "tests/test_errors.rb", "tests/test_exc.rb", "tests/test_file_watch.rb", "tests/test_futures.rb", "tests/test_get_sock_opt.rb", "tests/test_handler_check.rb", "tests/test_hc.rb", "tests/test_httpclient.rb", "tests/test_httpclient2.rb", "tests/test_inactivity_timeout.rb", "tests/test_kb.rb", "tests/test_ltp.rb", "tests/test_ltp2.rb", "tests/test_next_tick.rb", "tests/test_object_protocol.rb", "tests/test_pause.rb", "tests/test_pending_connect_timeout.rb", "tests/test_process_watch.rb", "tests/test_processes.rb", "tests/test_proxy_connection.rb", "tests/test_pure.rb", "tests/test_queue.rb", "tests/test_running.rb", "tests/test_sasl.rb", "tests/test_send_file.rb", "tests/test_servers.rb", "tests/test_smtpclient.rb", "tests/test_smtpserver.rb", "tests/test_spawn.rb", "tests/test_ssl_args.rb", "tests/test_ssl_methods.rb", "tests/test_ssl_verify.rb", "tests/test_timers.rb", "tests/test_ud.rb", "tests/testem.rb", "web/whatis"]
|
24
|
-
s.homepage = %q{http://rubyeventmachine.com}
|
25
|
-
s.rdoc_options = ["--title", "EventMachine", "--main", "README", "--line-numbers", "-x", "lib/em/version", "-x", "lib/emva", "-x", "lib/evma/", "-x", "lib/pr_eventmachine", "-x", "lib/jeventmachine"]
|
26
|
-
s.require_paths = ["lib"]
|
27
|
-
s.rubyforge_project = %q{eventmachine}
|
28
|
-
s.rubygems_version = %q{1.3.5}
|
29
|
-
s.summary = %q{Ruby/EventMachine library}
|
30
|
-
|
31
|
-
if s.respond_to? :specification_version then
|
32
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
33
|
-
s.specification_version = 3
|
30
|
+
using TCP/IP, especially if custom protocols are required."
|
34
31
|
|
35
|
-
|
36
|
-
else
|
37
|
-
end
|
38
|
-
else
|
39
|
-
end
|
32
|
+
s.rdoc_options = ["--title", "EventMachine", "--main", "README", "-x", "lib/em/version", "-x", "lib/jeventmachine"]
|
40
33
|
end
|
data/examples/ex_channel.rb
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
EM.run do
|
4
|
-
|
5
|
-
# Create a channel to push data to, this could be stocks...
|
6
|
-
RandChannel = EM::Channel.new
|
7
|
-
|
8
|
-
# The server simply subscribes client connections to the channel on connect,
|
9
|
-
# and unsubscribes them on disconnect.
|
10
|
-
class Server < EM::Connection
|
11
|
-
def self.start(host = '127.0.0.1', port = 8000)
|
12
|
-
EM.start_server(host, port, self)
|
13
|
-
end
|
14
|
-
|
15
|
-
def post_init
|
16
|
-
@sid = RandChannel.subscribe { |m| send_data "#{m.inspect}\n" }
|
17
|
-
end
|
18
|
-
|
19
|
-
def unbind
|
20
|
-
RandChannel.unsubscribe @sid
|
21
|
-
end
|
22
|
-
end
|
23
|
-
Server.start
|
24
|
-
|
25
|
-
# Two client connections, that just print what they receive.
|
26
|
-
2.times do
|
27
|
-
EM.connect('127.0.0.1', 8000) do |c|
|
28
|
-
c.extend EM::P::LineText2
|
29
|
-
def c.receive_line(line)
|
30
|
-
puts "Subscriber: #{signature} got #{line}"
|
31
|
-
end
|
32
|
-
EM.add_timer(2) { c.close_connection }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# This part of the example is more fake, but imagine sleep was in fact a
|
37
|
-
# long running calculation to achieve the value.
|
38
|
-
40.times do
|
39
|
-
EM.defer lambda { v = sleep(rand * 2); RandChannel << [Time.now, v] }
|
40
|
-
end
|
41
|
-
|
42
|
-
EM.add_timer(5) { EM.stop }
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
EM.run do
|
4
|
+
|
5
|
+
# Create a channel to push data to, this could be stocks...
|
6
|
+
RandChannel = EM::Channel.new
|
7
|
+
|
8
|
+
# The server simply subscribes client connections to the channel on connect,
|
9
|
+
# and unsubscribes them on disconnect.
|
10
|
+
class Server < EM::Connection
|
11
|
+
def self.start(host = '127.0.0.1', port = 8000)
|
12
|
+
EM.start_server(host, port, self)
|
13
|
+
end
|
14
|
+
|
15
|
+
def post_init
|
16
|
+
@sid = RandChannel.subscribe { |m| send_data "#{m.inspect}\n" }
|
17
|
+
end
|
18
|
+
|
19
|
+
def unbind
|
20
|
+
RandChannel.unsubscribe @sid
|
21
|
+
end
|
22
|
+
end
|
23
|
+
Server.start
|
24
|
+
|
25
|
+
# Two client connections, that just print what they receive.
|
26
|
+
2.times do
|
27
|
+
EM.connect('127.0.0.1', 8000) do |c|
|
28
|
+
c.extend EM::P::LineText2
|
29
|
+
def c.receive_line(line)
|
30
|
+
puts "Subscriber: #{signature} got #{line}"
|
31
|
+
end
|
32
|
+
EM.add_timer(2) { c.close_connection }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# This part of the example is more fake, but imagine sleep was in fact a
|
37
|
+
# long running calculation to achieve the value.
|
38
|
+
40.times do
|
39
|
+
EM.defer lambda { v = sleep(rand * 2); RandChannel << [Time.now, v] }
|
40
|
+
end
|
41
|
+
|
42
|
+
EM.add_timer(5) { EM.stop }
|
43
43
|
end
|
data/examples/ex_queue.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TickCounter
|
4
|
+
attr_reader :start_time, :count
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
reset
|
8
|
+
@tick_loop = EM.tick_loop(method(:tick))
|
9
|
+
end
|
10
|
+
|
11
|
+
def reset
|
12
|
+
@count = 0
|
13
|
+
@start_time = EM.current_time
|
14
|
+
end
|
15
|
+
|
16
|
+
def tick
|
17
|
+
@count += 1
|
18
|
+
end
|
19
|
+
|
20
|
+
def rate
|
21
|
+
@count / (EM.current_time - @start_time)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
period = 5
|
26
|
+
EM.run do
|
27
|
+
counter = TickCounter.new
|
28
|
+
EM.add_periodic_timer(period) do
|
29
|
+
puts "Ticks per second: #{counter.rate} (mean of last #{period}s)"
|
30
|
+
counter.reset
|
31
|
+
end
|
32
|
+
end
|
data/examples/helper.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
1
|
+
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
2
2
|
require 'eventmachine'
|
data/ext/binder.cpp
CHANGED
data/ext/cmain.cpp
CHANGED
@@ -25,6 +25,7 @@ See the file COPYING for complete licensing information.
|
|
25
25
|
*/
|
26
26
|
#if defined(BUILD_FOR_RUBY) && defined(OS_WIN32)
|
27
27
|
#undef stat
|
28
|
+
#undef fstat
|
28
29
|
#endif
|
29
30
|
|
30
31
|
static EventMachine_t *EventMachine;
|
@@ -49,11 +50,8 @@ extern "C" void ensure_eventmachine (const char *caller = "unknown caller")
|
|
49
50
|
evma_initialize_library
|
50
51
|
***********************/
|
51
52
|
|
52
|
-
extern "C" void evma_initialize_library (
|
53
|
+
extern "C" void evma_initialize_library (EMCallback cb)
|
53
54
|
{
|
54
|
-
// Probably a bad idea to mess with the signal mask of a process
|
55
|
-
// we're just being linked into.
|
56
|
-
//InstallSignalHandlers();
|
57
55
|
if (EventMachine)
|
58
56
|
#ifdef BUILD_FOR_RUBY
|
59
57
|
rb_raise(rb_eRuntimeError, "eventmachine already initialized: evma_initialize_library");
|
@@ -148,6 +146,7 @@ extern "C" int evma_detach_fd (const unsigned long binding)
|
|
148
146
|
#else
|
149
147
|
throw std::runtime_error ("invalid binding to detach");
|
150
148
|
#endif
|
149
|
+
return -1;
|
151
150
|
}
|
152
151
|
|
153
152
|
/************************
|
@@ -166,6 +165,7 @@ extern "C" int evma_get_file_descriptor (const unsigned long binding)
|
|
166
165
|
#else
|
167
166
|
throw std::runtime_error ("invalid binding to get_fd");
|
168
167
|
#endif
|
168
|
+
return -1;
|
169
169
|
}
|
170
170
|
|
171
171
|
/***********************
|
@@ -340,7 +340,10 @@ evma_send_data_to_connection
|
|
340
340
|
extern "C" int evma_send_data_to_connection (const unsigned long binding, const char *data, int data_length)
|
341
341
|
{
|
342
342
|
ensure_eventmachine("evma_send_data_to_connection");
|
343
|
-
|
343
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
344
|
+
if (ed)
|
345
|
+
return ed->SendOutboundData(data, data_length);
|
346
|
+
return -1;
|
344
347
|
}
|
345
348
|
|
346
349
|
/******************
|
@@ -350,7 +353,10 @@ evma_send_datagram
|
|
350
353
|
extern "C" int evma_send_datagram (const unsigned long binding, const char *data, int data_length, const char *address, int port)
|
351
354
|
{
|
352
355
|
ensure_eventmachine("evma_send_datagram");
|
353
|
-
|
356
|
+
DatagramDescriptor *dd = dynamic_cast <DatagramDescriptor*> (Bindable_t::GetObject (binding));
|
357
|
+
if (dd)
|
358
|
+
return dd->SendOutboundDatagram(data, data_length, address, port);
|
359
|
+
return -1;
|
354
360
|
}
|
355
361
|
|
356
362
|
|
@@ -361,7 +367,9 @@ evma_close_connection
|
|
361
367
|
extern "C" void evma_close_connection (const unsigned long binding, int after_writing)
|
362
368
|
{
|
363
369
|
ensure_eventmachine("evma_close_connection");
|
364
|
-
|
370
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
371
|
+
if (ed)
|
372
|
+
ed->ScheduleClose (after_writing ? true : false);
|
365
373
|
}
|
366
374
|
|
367
375
|
/***********************************
|
@@ -371,7 +379,10 @@ evma_report_connection_error_status
|
|
371
379
|
extern "C" int evma_report_connection_error_status (const unsigned long binding)
|
372
380
|
{
|
373
381
|
ensure_eventmachine("evma_report_connection_error_status");
|
374
|
-
|
382
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
383
|
+
if (ed)
|
384
|
+
return ed->ReportErrorStatus();
|
385
|
+
return -1;
|
375
386
|
}
|
376
387
|
|
377
388
|
/********************
|
@@ -539,17 +550,6 @@ extern "C" void evma_signal_loopbreak()
|
|
539
550
|
|
540
551
|
|
541
552
|
|
542
|
-
/****************
|
543
|
-
evma__write_file
|
544
|
-
****************/
|
545
|
-
|
546
|
-
extern "C" const unsigned long evma__write_file (const char *filename)
|
547
|
-
{
|
548
|
-
ensure_eventmachine("evma__write_file");
|
549
|
-
return EventMachine->_OpenFileForWriting (filename);
|
550
|
-
}
|
551
|
-
|
552
|
-
|
553
553
|
/********************************
|
554
554
|
evma_get_comm_inactivity_timeout
|
555
555
|
********************************/
|
@@ -559,7 +559,7 @@ extern "C" float evma_get_comm_inactivity_timeout (const unsigned long binding)
|
|
559
559
|
ensure_eventmachine("evma_get_comm_inactivity_timeout");
|
560
560
|
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
561
561
|
if (ed) {
|
562
|
-
return ed->GetCommInactivityTimeout();
|
562
|
+
return ((float)ed->GetCommInactivityTimeout() / 1000);
|
563
563
|
}
|
564
564
|
else
|
565
565
|
return 0.0; //Perhaps this should be an exception. Access to an unknown binding.
|
@@ -574,7 +574,7 @@ extern "C" int evma_set_comm_inactivity_timeout (const unsigned long binding, fl
|
|
574
574
|
ensure_eventmachine("evma_set_comm_inactivity_timeout");
|
575
575
|
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
576
576
|
if (ed) {
|
577
|
-
return ed->SetCommInactivityTimeout (value);
|
577
|
+
return ed->SetCommInactivityTimeout ((uint64_t)(value * 1000));
|
578
578
|
}
|
579
579
|
else
|
580
580
|
return 0; //Perhaps this should be an exception. Access to an unknown binding.
|
@@ -590,7 +590,7 @@ extern "C" float evma_get_pending_connect_timeout (const unsigned long binding)
|
|
590
590
|
ensure_eventmachine("evma_get_pending_connect_timeout");
|
591
591
|
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
592
592
|
if (ed) {
|
593
|
-
return ed->GetPendingConnectTimeout();
|
593
|
+
return ((float)ed->GetPendingConnectTimeout() / 1000);
|
594
594
|
}
|
595
595
|
else
|
596
596
|
return 0.0;
|
@@ -606,7 +606,7 @@ extern "C" int evma_set_pending_connect_timeout (const unsigned long binding, fl
|
|
606
606
|
ensure_eventmachine("evma_set_pending_connect_timeout");
|
607
607
|
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
608
608
|
if (ed) {
|
609
|
-
return ed->SetPendingConnectTimeout (value);
|
609
|
+
return ed->SetPendingConnectTimeout ((uint64_t)(value * 1000));
|
610
610
|
}
|
611
611
|
else
|
612
612
|
return 0;
|
@@ -783,12 +783,12 @@ extern "C" int evma_send_file_data_to_connection (const unsigned long binding, c
|
|
783
783
|
evma_start_proxy
|
784
784
|
*****************/
|
785
785
|
|
786
|
-
extern "C" void evma_start_proxy (const unsigned long from, const unsigned long to, const unsigned long bufsize)
|
786
|
+
extern "C" void evma_start_proxy (const unsigned long from, const unsigned long to, const unsigned long bufsize, const unsigned long length)
|
787
787
|
{
|
788
788
|
ensure_eventmachine("evma_start_proxy");
|
789
789
|
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (from));
|
790
790
|
if (ed)
|
791
|
-
ed->StartProxy(to, bufsize);
|
791
|
+
ed->StartProxy(to, bufsize, length);
|
792
792
|
}
|
793
793
|
|
794
794
|
|
@@ -825,3 +825,14 @@ extern "C" int evma_set_heartbeat_interval(float interval)
|
|
825
825
|
ensure_eventmachine("evma_set_heartbeat_interval");
|
826
826
|
return EventMachine->SetHeartbeatInterval(interval);
|
827
827
|
}
|
828
|
+
|
829
|
+
|
830
|
+
/**************************
|
831
|
+
evma_get_current_loop_time
|
832
|
+
***************************/
|
833
|
+
|
834
|
+
extern "C" uint64_t evma_get_current_loop_time()
|
835
|
+
{
|
836
|
+
ensure_eventmachine("evma_get_current_loop_time");
|
837
|
+
return EventMachine->GetCurrentLoopTime();
|
838
|
+
}
|
data/ext/ed.cpp
CHANGED
@@ -61,7 +61,8 @@ EventableDescriptor::EventableDescriptor (int sd, EventMachine_t *em):
|
|
61
61
|
ProxiedFrom(NULL),
|
62
62
|
MaxOutboundBufSize(0),
|
63
63
|
MyEventMachine (em),
|
64
|
-
PendingConnectTimeout(20000000)
|
64
|
+
PendingConnectTimeout(20000000),
|
65
|
+
InactivityTimeout (0)
|
65
66
|
{
|
66
67
|
/* There are three ways to close a socket, all of which should
|
67
68
|
* automatically signal to the event machine that this object
|
@@ -88,12 +89,13 @@ EventableDescriptor::EventableDescriptor (int sd, EventMachine_t *em):
|
|
88
89
|
throw std::runtime_error ("bad eventable descriptor");
|
89
90
|
if (MyEventMachine == NULL)
|
90
91
|
throw std::runtime_error ("bad em in eventable descriptor");
|
91
|
-
CreatedAt =
|
92
|
+
CreatedAt = MyEventMachine->GetCurrentLoopTime();
|
92
93
|
|
93
94
|
#ifdef HAVE_EPOLL
|
94
95
|
EpollEvent.events = 0;
|
95
96
|
EpollEvent.data.ptr = this;
|
96
97
|
#endif
|
98
|
+
LastActivity = MyEventMachine->GetCurrentLoopTime();
|
97
99
|
}
|
98
100
|
|
99
101
|
|
@@ -103,6 +105,8 @@ EventableDescriptor::~EventableDescriptor
|
|
103
105
|
|
104
106
|
EventableDescriptor::~EventableDescriptor()
|
105
107
|
{
|
108
|
+
if (NextHeartbeat)
|
109
|
+
MyEventMachine->ClearHeartbeat(NextHeartbeat);
|
106
110
|
if (EventCallback && bCallbackUnbind)
|
107
111
|
(*EventCallback)(GetBinding(), EM_CONNECTION_UNBOUND, NULL, UnbindReasonCode);
|
108
112
|
if (ProxiedFrom) {
|
@@ -118,7 +122,7 @@ EventableDescriptor::~EventableDescriptor()
|
|
118
122
|
EventableDescriptor::SetEventCallback
|
119
123
|
*************************************/
|
120
124
|
|
121
|
-
void EventableDescriptor::SetEventCallback (
|
125
|
+
void EventableDescriptor::SetEventCallback (EMCallback cb)
|
122
126
|
{
|
123
127
|
EventCallback = cb;
|
124
128
|
}
|
@@ -133,7 +137,7 @@ void EventableDescriptor::Close()
|
|
133
137
|
// Close the socket right now. Intended for emergencies.
|
134
138
|
if (MySocket != INVALID_SOCKET) {
|
135
139
|
shutdown (MySocket, 1);
|
136
|
-
|
140
|
+
close (MySocket);
|
137
141
|
MySocket = INVALID_SOCKET;
|
138
142
|
}
|
139
143
|
}
|
@@ -187,12 +191,13 @@ bool EventableDescriptor::IsCloseScheduled()
|
|
187
191
|
EventableDescriptor::StartProxy
|
188
192
|
*******************************/
|
189
193
|
|
190
|
-
void EventableDescriptor::StartProxy(const unsigned long to, const unsigned long bufsize)
|
194
|
+
void EventableDescriptor::StartProxy(const unsigned long to, const unsigned long bufsize, const unsigned long length)
|
191
195
|
{
|
192
196
|
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (to));
|
193
197
|
if (ed) {
|
194
198
|
StopProxy();
|
195
199
|
ProxyTarget = ed;
|
200
|
+
BytesToProxy = length;
|
196
201
|
ed->SetProxiedFrom(this, bufsize);
|
197
202
|
return;
|
198
203
|
}
|
@@ -219,6 +224,9 @@ EventableDescriptor::SetProxiedFrom
|
|
219
224
|
|
220
225
|
void EventableDescriptor::SetProxiedFrom(EventableDescriptor *from, const unsigned long bufsize)
|
221
226
|
{
|
227
|
+
if (from != NULL && ProxiedFrom != NULL)
|
228
|
+
throw std::runtime_error ("Tried to proxy to a busy target");
|
229
|
+
|
222
230
|
ProxiedFrom = from;
|
223
231
|
MaxOutboundBufSize = bufsize;
|
224
232
|
}
|
@@ -232,10 +240,24 @@ void EventableDescriptor::_GenericInboundDispatch(const char *buf, int size)
|
|
232
240
|
{
|
233
241
|
assert(EventCallback);
|
234
242
|
|
235
|
-
if (ProxyTarget)
|
236
|
-
|
237
|
-
|
243
|
+
if (ProxyTarget) {
|
244
|
+
if (BytesToProxy > 0) {
|
245
|
+
unsigned long proxied = min(BytesToProxy, (unsigned long) size);
|
246
|
+
ProxyTarget->SendOutboundData(buf, proxied);
|
247
|
+
BytesToProxy -= proxied;
|
248
|
+
if (BytesToProxy == 0) {
|
249
|
+
StopProxy();
|
250
|
+
(*EventCallback)(GetBinding(), EM_PROXY_COMPLETED, NULL, 0);
|
251
|
+
if (proxied < size) {
|
252
|
+
(*EventCallback)(GetBinding(), EM_CONNECTION_READ, buf + proxied, size - proxied);
|
253
|
+
}
|
254
|
+
}
|
255
|
+
} else {
|
256
|
+
ProxyTarget->SendOutboundData(buf, size);
|
257
|
+
}
|
258
|
+
} else {
|
238
259
|
(*EventCallback)(GetBinding(), EM_CONNECTION_READ, buf, size);
|
260
|
+
}
|
239
261
|
}
|
240
262
|
|
241
263
|
|
@@ -243,9 +265,9 @@ void EventableDescriptor::_GenericInboundDispatch(const char *buf, int size)
|
|
243
265
|
EventableDescriptor::GetPendingConnectTimeout
|
244
266
|
*********************************************/
|
245
267
|
|
246
|
-
|
268
|
+
uint64_t EventableDescriptor::GetPendingConnectTimeout()
|
247
269
|
{
|
248
|
-
return
|
270
|
+
return PendingConnectTimeout / 1000;
|
249
271
|
}
|
250
272
|
|
251
273
|
|
@@ -253,16 +275,43 @@ float EventableDescriptor::GetPendingConnectTimeout()
|
|
253
275
|
EventableDescriptor::SetPendingConnectTimeout
|
254
276
|
*********************************************/
|
255
277
|
|
256
|
-
int EventableDescriptor::SetPendingConnectTimeout (
|
278
|
+
int EventableDescriptor::SetPendingConnectTimeout (uint64_t value)
|
257
279
|
{
|
258
280
|
if (value > 0) {
|
259
|
-
PendingConnectTimeout =
|
281
|
+
PendingConnectTimeout = value * 1000;
|
282
|
+
MyEventMachine->QueueHeartbeat(this);
|
260
283
|
return 1;
|
261
284
|
}
|
262
285
|
return 0;
|
263
286
|
}
|
264
287
|
|
265
288
|
|
289
|
+
/*************************************
|
290
|
+
EventableDescriptor::GetNextHeartbeat
|
291
|
+
*************************************/
|
292
|
+
|
293
|
+
uint64_t EventableDescriptor::GetNextHeartbeat()
|
294
|
+
{
|
295
|
+
if (NextHeartbeat)
|
296
|
+
MyEventMachine->ClearHeartbeat(NextHeartbeat);
|
297
|
+
|
298
|
+
NextHeartbeat = 0;
|
299
|
+
|
300
|
+
if (!ShouldDelete()) {
|
301
|
+
uint64_t time_til_next = GetCommInactivityTimeout() * 1000;
|
302
|
+
if (IsConnectPending()) {
|
303
|
+
if (time_til_next == 0 || PendingConnectTimeout < time_til_next)
|
304
|
+
time_til_next = PendingConnectTimeout;
|
305
|
+
}
|
306
|
+
if (time_til_next == 0)
|
307
|
+
return 0;
|
308
|
+
NextHeartbeat = time_til_next + MyEventMachine->GetRealTime();
|
309
|
+
}
|
310
|
+
|
311
|
+
return NextHeartbeat;
|
312
|
+
}
|
313
|
+
|
314
|
+
|
266
315
|
/******************************************
|
267
316
|
ConnectionDescriptor::ConnectionDescriptor
|
268
317
|
******************************************/
|
@@ -286,9 +335,7 @@ ConnectionDescriptor::ConnectionDescriptor (int sd, EventMachine_t *em):
|
|
286
335
|
#ifdef HAVE_KQUEUE
|
287
336
|
bGotExtraKqueueEvent(false),
|
288
337
|
#endif
|
289
|
-
bIsServer (false)
|
290
|
-
LastIo (gCurrentLoopTime),
|
291
|
-
InactivityTimeout (0)
|
338
|
+
bIsServer (false)
|
292
339
|
{
|
293
340
|
// 22Jan09: Moved ArmKqueueWriter into SetConnectPending() to fix assertion failure in _WriteOutboundData()
|
294
341
|
// 5May09: Moved EPOLLOUT into SetConnectPending() so it doesn't happen for attached read pipes
|
@@ -312,57 +359,6 @@ ConnectionDescriptor::~ConnectionDescriptor()
|
|
312
359
|
}
|
313
360
|
|
314
361
|
|
315
|
-
/**************************************************
|
316
|
-
STATIC: ConnectionDescriptor::SendDataToConnection
|
317
|
-
**************************************************/
|
318
|
-
|
319
|
-
int ConnectionDescriptor::SendDataToConnection (const unsigned long binding, const char *data, int data_length)
|
320
|
-
{
|
321
|
-
// TODO: This is something of a hack, or at least it's a static method of the wrong class.
|
322
|
-
// TODO: Poor polymorphism here. We should be calling one virtual method
|
323
|
-
// instead of hacking out the runtime information of the target object.
|
324
|
-
ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject (binding));
|
325
|
-
if (cd)
|
326
|
-
return cd->SendOutboundData (data, data_length);
|
327
|
-
DatagramDescriptor *ds = dynamic_cast <DatagramDescriptor*> (Bindable_t::GetObject (binding));
|
328
|
-
if (ds)
|
329
|
-
return ds->SendOutboundData (data, data_length);
|
330
|
-
#ifdef OS_UNIX
|
331
|
-
PipeDescriptor *ps = dynamic_cast <PipeDescriptor*> (Bindable_t::GetObject (binding));
|
332
|
-
if (ps)
|
333
|
-
return ps->SendOutboundData (data, data_length);
|
334
|
-
#endif
|
335
|
-
return -1;
|
336
|
-
}
|
337
|
-
|
338
|
-
|
339
|
-
/*********************************************
|
340
|
-
STATIC: ConnectionDescriptor::CloseConnection
|
341
|
-
*********************************************/
|
342
|
-
|
343
|
-
void ConnectionDescriptor::CloseConnection (const unsigned long binding, bool after_writing)
|
344
|
-
{
|
345
|
-
// TODO: This is something of a hack, or at least it's a static method of the wrong class.
|
346
|
-
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
347
|
-
if (ed)
|
348
|
-
ed->ScheduleClose (after_writing);
|
349
|
-
}
|
350
|
-
|
351
|
-
/***********************************************
|
352
|
-
STATIC: ConnectionDescriptor::ReportErrorStatus
|
353
|
-
***********************************************/
|
354
|
-
|
355
|
-
int ConnectionDescriptor::ReportErrorStatus (const unsigned long binding)
|
356
|
-
{
|
357
|
-
// TODO: This is something of a hack, or at least it's a static method of the wrong class.
|
358
|
-
// TODO: Poor polymorphism here. We should be calling one virtual method
|
359
|
-
// instead of hacking out the runtime information of the target object.
|
360
|
-
ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject (binding));
|
361
|
-
if (cd)
|
362
|
-
return cd->_ReportErrorStatus();
|
363
|
-
return -1;
|
364
|
-
}
|
365
|
-
|
366
362
|
/***********************************
|
367
363
|
ConnectionDescriptor::_UpdateEvents
|
368
364
|
************************************/
|
@@ -500,7 +496,7 @@ int ConnectionDescriptor::SendOutboundData (const char *data, int length)
|
|
500
496
|
if (bWatchOnly)
|
501
497
|
throw std::runtime_error ("cannot send data on a 'watch only' connection");
|
502
498
|
|
503
|
-
if (ProxiedFrom && MaxOutboundBufSize && GetOutboundDataSize() + length > MaxOutboundBufSize)
|
499
|
+
if (ProxiedFrom && MaxOutboundBufSize && (unsigned int)(GetOutboundDataSize() + length) > MaxOutboundBufSize)
|
504
500
|
ProxiedFrom->Pause();
|
505
501
|
|
506
502
|
#ifdef WITH_SSL
|
@@ -541,7 +537,11 @@ int ConnectionDescriptor::_SendRawOutboundData (const char *data, int length)
|
|
541
537
|
// (Well, not so bad, small pages are coalesced in ::Write)
|
542
538
|
|
543
539
|
if (IsCloseScheduled())
|
544
|
-
|
540
|
+
return 0;
|
541
|
+
|
542
|
+
// 25Mar10: Ignore 0 length packets as they are not meaningful in TCP (as opposed to UDP)
|
543
|
+
// and can cause the assert(nbytes>0) to fail when OutboundPages has a bunch of 0 length pages.
|
544
|
+
if (length == 0)
|
545
545
|
return 0;
|
546
546
|
|
547
547
|
if (!data && (length > 0))
|
@@ -688,7 +688,7 @@ void ConnectionDescriptor::Read()
|
|
688
688
|
return;
|
689
689
|
}
|
690
690
|
|
691
|
-
|
691
|
+
LastActivity = MyEventMachine->GetCurrentLoopTime();
|
692
692
|
|
693
693
|
int total_bytes_read = 0;
|
694
694
|
char readbuffer [16 * 1024 + 1];
|
@@ -894,7 +894,7 @@ void ConnectionDescriptor::_WriteOutboundData()
|
|
894
894
|
return;
|
895
895
|
}
|
896
896
|
|
897
|
-
|
897
|
+
LastActivity = MyEventMachine->GetCurrentLoopTime();
|
898
898
|
size_t nbytes = 0;
|
899
899
|
|
900
900
|
#ifdef HAVE_WRITEV
|
@@ -902,11 +902,19 @@ void ConnectionDescriptor::_WriteOutboundData()
|
|
902
902
|
// Max of 16 outbound pages at a time
|
903
903
|
if (iovcnt > 16) iovcnt = 16;
|
904
904
|
|
905
|
+
#ifdef CC_SUNWspro
|
906
|
+
struct iovec iov[16];
|
907
|
+
#else
|
905
908
|
struct iovec iov[ iovcnt ];
|
909
|
+
#endif
|
906
910
|
|
907
911
|
for(int i = 0; i < iovcnt; i++){
|
908
912
|
OutboundPage *op = &(OutboundPages[i]);
|
913
|
+
#ifdef CC_SUNWspro
|
914
|
+
iov[i].iov_base = (char *)(op->Buffer + op->Offset);
|
915
|
+
#else
|
909
916
|
iov[i].iov_base = (void *)(op->Buffer + op->Offset);
|
917
|
+
#endif
|
910
918
|
iov[i].iov_len = op->Length - op->Offset;
|
911
919
|
|
912
920
|
nbytes += iov[i].iov_len;
|
@@ -953,7 +961,7 @@ void ConnectionDescriptor::_WriteOutboundData()
|
|
953
961
|
assert (bytes_written >= 0);
|
954
962
|
OutboundDataSize -= bytes_written;
|
955
963
|
|
956
|
-
if (ProxiedFrom && MaxOutboundBufSize && GetOutboundDataSize() < MaxOutboundBufSize && ProxiedFrom->IsPaused())
|
964
|
+
if (ProxiedFrom && MaxOutboundBufSize && (unsigned int)GetOutboundDataSize() < MaxOutboundBufSize && ProxiedFrom->IsPaused())
|
957
965
|
ProxiedFrom->Resume();
|
958
966
|
|
959
967
|
#ifdef HAVE_WRITEV
|
@@ -1005,11 +1013,11 @@ void ConnectionDescriptor::_WriteOutboundData()
|
|
1005
1013
|
}
|
1006
1014
|
|
1007
1015
|
|
1008
|
-
|
1009
|
-
ConnectionDescriptor::
|
1010
|
-
|
1016
|
+
/***************************************
|
1017
|
+
ConnectionDescriptor::ReportErrorStatus
|
1018
|
+
***************************************/
|
1011
1019
|
|
1012
|
-
int ConnectionDescriptor::
|
1020
|
+
int ConnectionDescriptor::ReportErrorStatus()
|
1013
1021
|
{
|
1014
1022
|
int error;
|
1015
1023
|
socklen_t len;
|
@@ -1190,12 +1198,12 @@ void ConnectionDescriptor::Heartbeat()
|
|
1190
1198
|
*/
|
1191
1199
|
|
1192
1200
|
if (bConnectPending) {
|
1193
|
-
if ((
|
1201
|
+
if ((MyEventMachine->GetCurrentLoopTime() - CreatedAt) >= PendingConnectTimeout)
|
1194
1202
|
ScheduleClose (false);
|
1195
1203
|
//bCloseNow = true;
|
1196
1204
|
}
|
1197
1205
|
else {
|
1198
|
-
if (InactivityTimeout && ((
|
1206
|
+
if (InactivityTimeout && ((MyEventMachine->GetCurrentLoopTime() - LastActivity) >= InactivityTimeout))
|
1199
1207
|
ScheduleClose (false);
|
1200
1208
|
//bCloseNow = true;
|
1201
1209
|
}
|
@@ -1328,7 +1336,7 @@ void AcceptorDescriptor::Read()
|
|
1328
1336
|
//int val = fcntl (sd, F_GETFL, 0);
|
1329
1337
|
//if (fcntl (sd, F_SETFL, val | O_NONBLOCK) == -1) {
|
1330
1338
|
shutdown (sd, 1);
|
1331
|
-
|
1339
|
+
close (sd);
|
1332
1340
|
continue;
|
1333
1341
|
}
|
1334
1342
|
|
@@ -1405,9 +1413,7 @@ DatagramDescriptor::DatagramDescriptor
|
|
1405
1413
|
|
1406
1414
|
DatagramDescriptor::DatagramDescriptor (int sd, EventMachine_t *parent_em):
|
1407
1415
|
EventableDescriptor (sd, parent_em),
|
1408
|
-
OutboundDataSize (0)
|
1409
|
-
LastIo (gCurrentLoopTime),
|
1410
|
-
InactivityTimeout (0)
|
1416
|
+
OutboundDataSize (0)
|
1411
1417
|
{
|
1412
1418
|
memset (&ReturnAddress, 0, sizeof(ReturnAddress));
|
1413
1419
|
|
@@ -1461,7 +1467,7 @@ void DatagramDescriptor::Heartbeat()
|
|
1461
1467
|
{
|
1462
1468
|
// Close it if its inactivity timer has expired.
|
1463
1469
|
|
1464
|
-
if (InactivityTimeout && ((
|
1470
|
+
if (InactivityTimeout && ((MyEventMachine->GetCurrentLoopTime() - LastActivity) >= InactivityTimeout))
|
1465
1471
|
ScheduleClose (false);
|
1466
1472
|
//bCloseNow = true;
|
1467
1473
|
}
|
@@ -1475,7 +1481,7 @@ void DatagramDescriptor::Read()
|
|
1475
1481
|
{
|
1476
1482
|
int sd = GetSocket();
|
1477
1483
|
assert (sd != INVALID_SOCKET);
|
1478
|
-
|
1484
|
+
LastActivity = MyEventMachine->GetCurrentLoopTime();
|
1479
1485
|
|
1480
1486
|
// This is an extremely large read buffer.
|
1481
1487
|
// In many cases you wouldn't expect to get any more than 4K.
|
@@ -1552,7 +1558,7 @@ void DatagramDescriptor::Write()
|
|
1552
1558
|
|
1553
1559
|
int sd = GetSocket();
|
1554
1560
|
assert (sd != INVALID_SOCKET);
|
1555
|
-
|
1561
|
+
LastActivity = MyEventMachine->GetCurrentLoopTime();
|
1556
1562
|
|
1557
1563
|
assert (OutboundPages.size() > 0);
|
1558
1564
|
|
@@ -1618,11 +1624,11 @@ DatagramDescriptor::SendOutboundData
|
|
1618
1624
|
|
1619
1625
|
int DatagramDescriptor::SendOutboundData (const char *data, int length)
|
1620
1626
|
{
|
1621
|
-
// This is an exact clone of ConnectionDescriptor::
|
1622
|
-
// That means it
|
1627
|
+
// This is almost an exact clone of ConnectionDescriptor::_SendRawOutboundData.
|
1628
|
+
// That means most of it could be factored to a common ancestor. Note that
|
1629
|
+
// empty datagrams are meaningful, which isn't the case for TCP streams.
|
1623
1630
|
|
1624
1631
|
if (IsCloseScheduled())
|
1625
|
-
//if (bCloseNow || bCloseAfterWriting)
|
1626
1632
|
return 0;
|
1627
1633
|
|
1628
1634
|
if (!data && (length > 0))
|
@@ -1706,20 +1712,6 @@ int DatagramDescriptor::SendOutboundDatagram (const char *data, int length, cons
|
|
1706
1712
|
}
|
1707
1713
|
|
1708
1714
|
|
1709
|
-
/****************************************
|
1710
|
-
STATIC: DatagramDescriptor::SendDatagram
|
1711
|
-
****************************************/
|
1712
|
-
|
1713
|
-
int DatagramDescriptor::SendDatagram (const unsigned long binding, const char *data, int length, const char *address, int port)
|
1714
|
-
{
|
1715
|
-
DatagramDescriptor *dd = dynamic_cast <DatagramDescriptor*> (Bindable_t::GetObject (binding));
|
1716
|
-
if (dd)
|
1717
|
-
return dd->SendOutboundDatagram (data, length, address, port);
|
1718
|
-
else
|
1719
|
-
return -1;
|
1720
|
-
}
|
1721
|
-
|
1722
|
-
|
1723
1715
|
/*********************************
|
1724
1716
|
ConnectionDescriptor::GetPeername
|
1725
1717
|
*********************************/
|
@@ -1757,9 +1749,9 @@ bool ConnectionDescriptor::GetSockname (struct sockaddr *s)
|
|
1757
1749
|
ConnectionDescriptor::GetCommInactivityTimeout
|
1758
1750
|
**********************************************/
|
1759
1751
|
|
1760
|
-
|
1752
|
+
uint64_t ConnectionDescriptor::GetCommInactivityTimeout()
|
1761
1753
|
{
|
1762
|
-
return
|
1754
|
+
return InactivityTimeout / 1000;
|
1763
1755
|
}
|
1764
1756
|
|
1765
1757
|
|
@@ -1767,13 +1759,11 @@ float ConnectionDescriptor::GetCommInactivityTimeout()
|
|
1767
1759
|
ConnectionDescriptor::SetCommInactivityTimeout
|
1768
1760
|
**********************************************/
|
1769
1761
|
|
1770
|
-
int ConnectionDescriptor::SetCommInactivityTimeout (
|
1762
|
+
int ConnectionDescriptor::SetCommInactivityTimeout (uint64_t value)
|
1771
1763
|
{
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
}
|
1776
|
-
return 0;
|
1764
|
+
InactivityTimeout = value * 1000;
|
1765
|
+
MyEventMachine->QueueHeartbeat(this);
|
1766
|
+
return 1;
|
1777
1767
|
}
|
1778
1768
|
|
1779
1769
|
/*******************************
|
@@ -1813,19 +1803,20 @@ bool DatagramDescriptor::GetSockname (struct sockaddr *s)
|
|
1813
1803
|
DatagramDescriptor::GetCommInactivityTimeout
|
1814
1804
|
********************************************/
|
1815
1805
|
|
1816
|
-
|
1806
|
+
uint64_t DatagramDescriptor::GetCommInactivityTimeout()
|
1817
1807
|
{
|
1818
|
-
return
|
1808
|
+
return InactivityTimeout / 1000;
|
1819
1809
|
}
|
1820
1810
|
|
1821
1811
|
/********************************************
|
1822
1812
|
DatagramDescriptor::SetCommInactivityTimeout
|
1823
1813
|
********************************************/
|
1824
1814
|
|
1825
|
-
int DatagramDescriptor::SetCommInactivityTimeout (
|
1815
|
+
int DatagramDescriptor::SetCommInactivityTimeout (uint64_t value)
|
1826
1816
|
{
|
1827
1817
|
if (value > 0) {
|
1828
|
-
InactivityTimeout =
|
1818
|
+
InactivityTimeout = value * 1000;
|
1819
|
+
MyEventMachine->QueueHeartbeat(this);
|
1829
1820
|
return 1;
|
1830
1821
|
}
|
1831
1822
|
return 0;
|