root/version_0/lib/jeventmachine.rb

Revision 458, 2.6 kB (checked in by blackhedd, 1 year ago)

some datagram support

  • Property svn:keywords set to Id
Line 
1 # $Id$
2 #
3 # Author:: Francis Cianfrocca (gmail: blackhedd)
4 # Homepage::  http://rubyeventmachine.com
5 # Date:: 8 Apr 2006
6 #
7 # See EventMachine and EventMachine::Connection for documentation and
8 # usage examples.
9 #
10 #----------------------------------------------------------------------------
11 #
12 # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13 # Gmail: blackhedd
14 #
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of either: 1) the GNU General Public License
17 # as published by the Free Software Foundation; either version 2 of the
18 # License, or (at your option) any later version; or 2) Ruby's License.
19 #
20 # See the file COPYING for complete licensing information.
21 #
22 #---------------------------------------------------------------------------
23 #
24 #
25
26
27 # This module provides "glue" for the Java version of the EventMachine reactor core.
28 # For C++ EventMachines, the analogous functionality is found in ext/rubymain.cpp,
29 # which is a garden-variety Ruby-extension glue module.
30
31
32 require 'em_reactor'
33
34 module EventMachine
35         # TODO: These event numbers are defined in way too many places.
36         # DRY them up.
37         TimerFired = 100
38         ConnectionData = 101
39         ConnectionUnbound = 102
40         ConnectionAccepted = 103
41         ConnectionCompleted = 104
42         LoopbreakSignalled = 105
43
44         class EM < com.rubyeventmachine.EmReactor
45                 def eventCallback a1, a2, a3
46                         s = String.from_java_bytes(a3.array[a3.position...a3.limit])
47                         EventMachine::event_callback a1, a2, s
48                 end
49         end
50         def self.initialize_event_machine
51                 @em = EM.new
52         end
53         def self.release_machine
54                 @em = nil
55         end
56         def self.add_oneshot_timer interval
57                 @em.installOneshotTimer interval
58         end
59         def self.run_machine
60                 @em.run
61         end
62         def self.stop
63                 @em.stop
64         end
65         def self.start_tcp_server server, port
66                 @em.startTcpServer server, port
67         end
68         def self.stop_tcp_server sig
69                 @em.stopTcpServer sig
70         end
71         def self.send_data sig, data, length
72                 @em.sendData sig, data, length
73         end
74         def self.send_datagram sig, data, length, address, port
75                 @em.sendDatagram sig, data, length, address, port
76         end
77         def self.connect_server server, port
78                 @em.connectTcpServer server, port
79         end
80         def self.close_connection sig, after_writing
81                 @em.closeConnection sig, after_writing
82         end
83         def self.start_tls sig
84                 @em.startTls sig
85         end
86         def self.signal_loopbreak
87                 @em.signalLoopbreak
88         end
89         def self.set_timer_quantum q
90                 @em.setTimerQuantum q
91         end
92         def self.epoll
93                 # Epoll is a no-op for Java.
94                 # The latest Java versions run epoll when possible in NIO.
95         end
96         def self.set_rlimit_nofile n_descriptors
97                 # Currently a no-op for Java.
98         end
99         def self.open_udp_socket server, port
100                 @em.openUdpSocket server, port
101         end
102         def self.library_type
103                 :java
104         end
105 end
106
Note: See TracBrowser for help on using the browser.