eventmachine 0.12.2 → 0.12.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +191 -0
- data/{COPYING → docs/COPYING} +0 -0
- data/docs/ChangeLog +183 -0
- data/{DEFERRABLES → docs/DEFERRABLES} +1 -1
- data/{EPOLL → docs/EPOLL} +0 -0
- data/{GNU → docs/GNU} +0 -0
- data/docs/INSTALL +15 -0
- data/{KEYBOARD → docs/KEYBOARD} +0 -0
- data/{LEGAL → docs/LEGAL} +0 -0
- data/{LIGHTWEIGHT_CONCURRENCY → docs/LIGHTWEIGHT_CONCURRENCY} +1 -1
- data/{PURE_RUBY → docs/PURE_RUBY} +1 -1
- data/{README → docs/README} +1 -1
- data/{RELEASE_NOTES → docs/RELEASE_NOTES} +1 -1
- data/{SMTP → docs/SMTP} +1 -1
- data/{SPAWNED_PROCESSES → docs/SPAWNED_PROCESSES} +1 -1
- data/{TODO → docs/TODO} +1 -1
- data/ext/binder.cpp +1 -1
- data/ext/binder.h +1 -1
- data/ext/cmain.cpp +65 -74
- data/ext/cplusplus.cpp +1 -1
- data/ext/ed.cpp +41 -25
- data/ext/ed.h +10 -3
- data/ext/em.cpp +39 -12
- data/ext/em.h +13 -1
- data/ext/emwin.cpp +1 -1
- data/ext/emwin.h +1 -1
- data/ext/epoll.cpp +1 -1
- data/ext/epoll.h +1 -1
- data/ext/eventmachine.h +1 -1
- data/ext/eventmachine_cpp.h +1 -1
- data/ext/extconf.rb +86 -139
- data/ext/fastfilereader/extconf.rb +161 -0
- data/ext/fastfilereader/mapper.cpp +202 -0
- data/ext/fastfilereader/mapper.h +59 -0
- data/ext/fastfilereader/rubymain.cpp +127 -0
- data/ext/files.cpp +1 -1
- data/ext/files.h +1 -1
- data/ext/kb.cpp +1 -1
- data/ext/page.cpp +1 -1
- data/ext/page.h +1 -1
- data/ext/pipe.cpp +14 -7
- data/ext/project.h +1 -1
- data/ext/rubymain.cpp +56 -2
- data/ext/sigs.cpp +1 -1
- data/ext/sigs.h +1 -1
- data/ext/ssl.cpp +1 -1
- data/ext/ssl.h +1 -1
- data/java/src/com/rubyeventmachine/Application.java +196 -0
- data/java/src/com/rubyeventmachine/Connection.java +74 -0
- data/java/src/com/rubyeventmachine/ConnectionFactory.java +37 -0
- data/java/src/com/rubyeventmachine/DefaultConnectionFactory.java +46 -0
- data/java/src/com/rubyeventmachine/EmReactor.java +408 -0
- data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
- data/java/src/com/rubyeventmachine/EventableChannel.java +57 -0
- data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +171 -0
- data/java/src/com/rubyeventmachine/EventableSocketChannel.java +244 -0
- data/java/src/com/rubyeventmachine/PeriodicTimer.java +38 -0
- data/java/src/com/rubyeventmachine/Timer.java +54 -0
- data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +108 -0
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +124 -0
- data/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
- data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
- data/java/src/com/rubyeventmachine/tests/TestServers.java +74 -0
- data/java/src/com/rubyeventmachine/tests/TestTimers.java +89 -0
- data/lib/em/deferrable.rb +1 -1
- data/lib/em/eventable.rb +1 -1
- data/lib/em/future.rb +1 -1
- data/lib/em/messages.rb +1 -1
- data/lib/em/processes.rb +1 -1
- data/lib/em/spawnable.rb +1 -1
- data/lib/em/streamer.rb +1 -1
- data/lib/eventmachine.rb +138 -116
- data/lib/eventmachine_version.rb +2 -2
- data/lib/evma.rb +1 -1
- data/lib/evma/callback.rb +1 -1
- data/lib/evma/container.rb +1 -1
- data/lib/evma/factory.rb +1 -1
- data/lib/evma/protocol.rb +1 -1
- data/lib/evma/reactor.rb +1 -1
- data/lib/jeventmachine.rb +7 -2
- data/lib/pr_eventmachine.rb +2 -2
- data/lib/protocols/buftok.rb +1 -1
- data/lib/protocols/header_and_content.rb +1 -1
- data/lib/protocols/httpcli2.rb +16 -6
- data/lib/protocols/httpclient.rb +7 -1
- data/lib/protocols/line_and_text.rb +6 -2
- data/lib/protocols/linetext2.rb +12 -14
- data/lib/protocols/postgres.rb +1 -1
- data/lib/protocols/saslauth.rb +1 -1
- data/lib/protocols/smtpclient.rb +1 -1
- data/lib/protocols/smtpserver.rb +36 -23
- data/lib/protocols/stomp.rb +24 -1
- data/lib/protocols/tcptest.rb +1 -1
- data/tasks/cpp.rake +77 -0
- data/tasks/project.rake +78 -0
- data/tasks/tests.rake +192 -0
- data/tests/test_attach.rb +1 -1
- data/tests/test_basic.rb +65 -12
- data/tests/test_defer.rb +13 -29
- data/tests/test_epoll.rb +16 -21
- data/tests/test_errors.rb +1 -1
- data/tests/test_eventables.rb +4 -5
- data/tests/test_exc.rb +1 -1
- data/tests/test_futures.rb +1 -1
- data/tests/test_hc.rb +185 -236
- data/tests/test_httpclient.rb +1 -1
- data/tests/test_httpclient2.rb +28 -6
- data/tests/test_kb.rb +2 -2
- data/tests/test_ltp.rb +139 -141
- data/tests/test_ltp2.rb +1 -1
- data/tests/test_next_tick.rb +1 -1
- data/tests/test_processes.rb +1 -1
- data/tests/test_pure.rb +3 -2
- data/tests/test_running.rb +1 -1
- data/tests/test_sasl.rb +1 -1
- data/tests/test_send_file.rb +56 -51
- data/tests/test_servers.rb +26 -36
- data/tests/test_smtpclient.rb +46 -44
- data/tests/test_smtpserver.rb +1 -1
- data/tests/test_spawn.rb +1 -1
- data/tests/test_ssl_args.rb +68 -0
- data/tests/test_timers.rb +15 -9
- data/tests/test_ud.rb +1 -1
- data/tests/testem.rb +30 -4
- metadata +69 -34
@@ -0,0 +1,161 @@
|
|
1
|
+
# $Id: extconf.rb 4526 2007-07-03 18:04:34Z francis $
|
2
|
+
#
|
3
|
+
#----------------------------------------------------------------------------
|
4
|
+
#
|
5
|
+
# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
6
|
+
# Gmail: garbagecat10
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of either: 1) the GNU General Public License
|
10
|
+
# as published by the Free Software Foundation; either version 2 of the
|
11
|
+
# License, or (at your option) any later version; or 2) Ruby's License.
|
12
|
+
#
|
13
|
+
# See the file COPYING for complete licensing information.
|
14
|
+
#
|
15
|
+
#---------------------------------------------------------------------------
|
16
|
+
#
|
17
|
+
# extconf.rb for Fast File Reader
|
18
|
+
# We have to munge LDSHARED because this code needs a C++ link.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'mkmf'
|
22
|
+
|
23
|
+
flags = []
|
24
|
+
|
25
|
+
case RUBY_PLATFORM.split('-',2)[1]
|
26
|
+
when 'mswin32', 'mingw32', 'bccwin32'
|
27
|
+
unless have_header('windows.h') and
|
28
|
+
have_header('winsock.h') and
|
29
|
+
have_library('kernel32') and
|
30
|
+
have_library('rpcrt4') and
|
31
|
+
have_library('gdi32')
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
|
35
|
+
flags << "-D OS_WIN32"
|
36
|
+
flags << '-D BUILD_FOR_RUBY'
|
37
|
+
flags << "-EHs"
|
38
|
+
flags << "-GR"
|
39
|
+
|
40
|
+
dir_config('ssl')
|
41
|
+
if have_library('ssleay32') and
|
42
|
+
have_library('libeay32') and
|
43
|
+
have_header('openssl/ssl.h') and
|
44
|
+
have_header('openssl/err.h')
|
45
|
+
flags << '-D WITH_SSL'
|
46
|
+
else
|
47
|
+
flags << '-D WITHOUT_SSL'
|
48
|
+
end
|
49
|
+
|
50
|
+
when /solaris/
|
51
|
+
unless have_library('pthread') and
|
52
|
+
have_library('nsl') and
|
53
|
+
have_library('socket')
|
54
|
+
exit
|
55
|
+
end
|
56
|
+
|
57
|
+
flags << '-D OS_UNIX'
|
58
|
+
flags << '-D OS_SOLARIS8'
|
59
|
+
flags << '-D BUILD_FOR_RUBY'
|
60
|
+
|
61
|
+
dir_config('ssl')
|
62
|
+
if have_library('ssl') and
|
63
|
+
have_library('crypto') and
|
64
|
+
have_header('openssl/ssl.h') and
|
65
|
+
have_header('openssl/err.h')
|
66
|
+
flags << '-D WITH_SSL'
|
67
|
+
else
|
68
|
+
flags << '-D WITHOUT_SSL'
|
69
|
+
end
|
70
|
+
|
71
|
+
# on Unix we need a g++ link, not gcc.
|
72
|
+
CONFIG['LDSHARED'] = "$(CXX) -shared"
|
73
|
+
|
74
|
+
when /darwin/
|
75
|
+
flags << '-DOS_UNIX'
|
76
|
+
flags << '-DBUILD_FOR_RUBY'
|
77
|
+
|
78
|
+
dir_config('ssl')
|
79
|
+
if have_library('ssl') and
|
80
|
+
have_library('crypto') and
|
81
|
+
have_library('C') and
|
82
|
+
have_header('openssl/ssl.h') and
|
83
|
+
have_header('openssl/err.h')
|
84
|
+
flags << '-DWITH_SSL'
|
85
|
+
else
|
86
|
+
flags << '-DWITHOUT_SSL'
|
87
|
+
end
|
88
|
+
# on Unix we need a g++ link, not gcc.
|
89
|
+
# Ff line contributed by Daniel Harple.
|
90
|
+
CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
|
91
|
+
|
92
|
+
when /linux/
|
93
|
+
unless have_library('pthread')
|
94
|
+
exit
|
95
|
+
end
|
96
|
+
|
97
|
+
flags << '-DOS_UNIX'
|
98
|
+
flags << '-DBUILD_FOR_RUBY'
|
99
|
+
|
100
|
+
# Original epoll test is inadequate because 2.4 kernels have the header
|
101
|
+
# but not the code.
|
102
|
+
#flags << '-DHAVE_EPOLL' if have_header('sys/epoll.h')
|
103
|
+
if have_header('sys/epoll.h')
|
104
|
+
File.open("hasEpollTest.c", "w") {|f|
|
105
|
+
f.puts "#include <sys/epoll.h>"
|
106
|
+
f.puts "int main() { epoll_create(1024); return 0;}"
|
107
|
+
}
|
108
|
+
(e = system( "gcc hasEpollTest.c -o hasEpollTest " )) and (e = $?.to_i)
|
109
|
+
`rm -f hasEpollTest.c hasEpollTest`
|
110
|
+
flags << '-DHAVE_EPOLL' if e == 0
|
111
|
+
end
|
112
|
+
|
113
|
+
dir_config('ssl')
|
114
|
+
if have_library('ssl') and
|
115
|
+
have_library('crypto') and
|
116
|
+
have_header('openssl/ssl.h') and
|
117
|
+
have_header('openssl/err.h')
|
118
|
+
flags << '-DWITH_SSL'
|
119
|
+
else
|
120
|
+
flags << '-DWITHOUT_SSL'
|
121
|
+
end
|
122
|
+
# on Unix we need a g++ link, not gcc.
|
123
|
+
CONFIG['LDSHARED'] = "$(CXX) -shared"
|
124
|
+
|
125
|
+
# Modify the mkmf constant LINK_SO so the generated shared object is stripped.
|
126
|
+
# You might think modifying CONFIG['LINK_SO'] would be a better way to do this,
|
127
|
+
# but it doesn't work because mkmf doesn't look at CONFIG['LINK_SO'] again after
|
128
|
+
# it initializes.
|
129
|
+
linkso = Object.send :remove_const, "LINK_SO"
|
130
|
+
LINK_SO = linkso + "; strip $@"
|
131
|
+
|
132
|
+
else
|
133
|
+
unless have_library('pthread')
|
134
|
+
exit
|
135
|
+
end
|
136
|
+
|
137
|
+
flags << '-DOS_UNIX'
|
138
|
+
flags << '-DBUILD_FOR_RUBY'
|
139
|
+
|
140
|
+
dir_config('ssl')
|
141
|
+
if have_library('ssl') and
|
142
|
+
have_library('crypto') and
|
143
|
+
have_header('openssl/ssl.h') and
|
144
|
+
have_header('openssl/err.h')
|
145
|
+
flags << '-DWITH_SSL'
|
146
|
+
else
|
147
|
+
flags << '-DWITHOUT_SSL'
|
148
|
+
end
|
149
|
+
# on Unix we need a g++ link, not gcc.
|
150
|
+
CONFIG['LDSHARED'] = "$(CXX) -shared"
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
if $CPPFLAGS
|
155
|
+
$CPPFLAGS += ' ' + flags.join(' ')
|
156
|
+
else
|
157
|
+
$CFLAGS += ' ' + flags.join(' ')
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
create_makefile "fastfilereaderext"
|
@@ -0,0 +1,202 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
|
3
|
+
$Id: mapper.cpp 4527 2007-07-04 10:21:34Z francis $
|
4
|
+
|
5
|
+
File: mapper.cpp
|
6
|
+
Date: 02Jul07
|
7
|
+
|
8
|
+
Copyright (C) 2007 by Francis Cianfrocca. All Rights Reserved.
|
9
|
+
Gmail: garbagecat10
|
10
|
+
|
11
|
+
This program is free software; you can redistribute it and/or modify
|
12
|
+
it under the terms of either: 1) the GNU General Public License
|
13
|
+
as published by the Free Software Foundation; either version 2 of the
|
14
|
+
License, or (at your option) any later version; or 2) Ruby's License.
|
15
|
+
|
16
|
+
See the file COPYING for complete licensing information.
|
17
|
+
|
18
|
+
*****************************************************************************/
|
19
|
+
|
20
|
+
|
21
|
+
//////////////////////////////////////////////////////////////////////
|
22
|
+
// UNIX implementation
|
23
|
+
//////////////////////////////////////////////////////////////////////
|
24
|
+
|
25
|
+
|
26
|
+
#ifdef OS_UNIX
|
27
|
+
|
28
|
+
#include <sys/types.h>
|
29
|
+
#include <sys/stat.h>
|
30
|
+
#include <sys/mman.h>
|
31
|
+
#include <fcntl.h>
|
32
|
+
#include <errno.h>
|
33
|
+
|
34
|
+
#include <iostream>
|
35
|
+
#include "unistd.h"
|
36
|
+
#include <string>
|
37
|
+
#include <cstring>
|
38
|
+
#include <stdexcept>
|
39
|
+
using namespace std;
|
40
|
+
|
41
|
+
#include "mapper.h"
|
42
|
+
|
43
|
+
/******************
|
44
|
+
Mapper_t::Mapper_t
|
45
|
+
******************/
|
46
|
+
|
47
|
+
Mapper_t::Mapper_t (const string &filename)
|
48
|
+
{
|
49
|
+
/* We ASSUME we can open the file.
|
50
|
+
* (More precisely, we assume someone else checked before we got here.)
|
51
|
+
*/
|
52
|
+
|
53
|
+
Fd = open (filename.c_str(), O_RDONLY);
|
54
|
+
if (Fd < 0)
|
55
|
+
throw runtime_error (strerror (errno));
|
56
|
+
|
57
|
+
struct stat st;
|
58
|
+
if (fstat (Fd, &st))
|
59
|
+
throw runtime_error (strerror (errno));
|
60
|
+
FileSize = st.st_size;
|
61
|
+
|
62
|
+
MapPoint = (const char*) mmap (0, FileSize, PROT_READ, MAP_SHARED, Fd, 0);
|
63
|
+
if (MapPoint == MAP_FAILED)
|
64
|
+
throw runtime_error (strerror (errno));
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
/*******************
|
69
|
+
Mapper_t::~Mapper_t
|
70
|
+
*******************/
|
71
|
+
|
72
|
+
Mapper_t::~Mapper_t()
|
73
|
+
{
|
74
|
+
Close();
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
/***************
|
79
|
+
Mapper_t::Close
|
80
|
+
***************/
|
81
|
+
|
82
|
+
void Mapper_t::Close()
|
83
|
+
{
|
84
|
+
// Can be called multiple times.
|
85
|
+
// Calls to GetChunk are invalid after a call to Close.
|
86
|
+
if (MapPoint) {
|
87
|
+
munmap ((void*)MapPoint, FileSize);
|
88
|
+
MapPoint = NULL;
|
89
|
+
}
|
90
|
+
if (Fd >= 0) {
|
91
|
+
close (Fd);
|
92
|
+
Fd = -1;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
/******************
|
97
|
+
Mapper_t::GetChunk
|
98
|
+
******************/
|
99
|
+
|
100
|
+
const char *Mapper_t::GetChunk (unsigned start)
|
101
|
+
{
|
102
|
+
return MapPoint + start;
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
#endif // OS_UNIX
|
108
|
+
|
109
|
+
|
110
|
+
//////////////////////////////////////////////////////////////////////
|
111
|
+
// WINDOWS implementation
|
112
|
+
//////////////////////////////////////////////////////////////////////
|
113
|
+
|
114
|
+
#ifdef OS_WIN32
|
115
|
+
|
116
|
+
#include <windows.h>
|
117
|
+
|
118
|
+
#include <iostream>
|
119
|
+
#include <string>
|
120
|
+
#include <stdexcept>
|
121
|
+
using namespace std;
|
122
|
+
|
123
|
+
#include "mapper.h"
|
124
|
+
|
125
|
+
/******************
|
126
|
+
Mapper_t::Mapper_t
|
127
|
+
******************/
|
128
|
+
|
129
|
+
Mapper_t::Mapper_t (const string &filename)
|
130
|
+
{
|
131
|
+
/* We ASSUME we can open the file.
|
132
|
+
* (More precisely, we assume someone else checked before we got here.)
|
133
|
+
*/
|
134
|
+
|
135
|
+
hFile = INVALID_HANDLE_VALUE;
|
136
|
+
hMapping = NULL;
|
137
|
+
MapPoint = NULL;
|
138
|
+
FileSize = 0;
|
139
|
+
|
140
|
+
hFile = CreateFile (filename.c_str(), GENERIC_READ|GENERIC_WRITE, FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
141
|
+
|
142
|
+
if (hFile == INVALID_HANDLE_VALUE)
|
143
|
+
throw runtime_error ("File not found");
|
144
|
+
|
145
|
+
BY_HANDLE_FILE_INFORMATION i;
|
146
|
+
if (GetFileInformationByHandle (hFile, &i))
|
147
|
+
FileSize = i.nFileSizeLow;
|
148
|
+
|
149
|
+
hMapping = CreateFileMapping (hFile, NULL, PAGE_READWRITE, 0, 0, NULL);
|
150
|
+
if (!hMapping)
|
151
|
+
throw runtime_error ("File not mapped");
|
152
|
+
|
153
|
+
MapPoint = (const char*) MapViewOfFile (hMapping, FILE_MAP_WRITE, 0, 0, 0);
|
154
|
+
if (!MapPoint)
|
155
|
+
throw runtime_error ("Mappoint not read");
|
156
|
+
}
|
157
|
+
|
158
|
+
|
159
|
+
/*******************
|
160
|
+
Mapper_t::~Mapper_t
|
161
|
+
*******************/
|
162
|
+
|
163
|
+
Mapper_t::~Mapper_t()
|
164
|
+
{
|
165
|
+
Close();
|
166
|
+
}
|
167
|
+
|
168
|
+
/***************
|
169
|
+
Mapper_t::Close
|
170
|
+
***************/
|
171
|
+
|
172
|
+
void Mapper_t::Close()
|
173
|
+
{
|
174
|
+
// Can be called multiple times.
|
175
|
+
// Calls to GetChunk are invalid after a call to Close.
|
176
|
+
if (MapPoint) {
|
177
|
+
UnmapViewOfFile (MapPoint);
|
178
|
+
MapPoint = NULL;
|
179
|
+
}
|
180
|
+
if (hMapping != NULL) {
|
181
|
+
CloseHandle (hMapping);
|
182
|
+
hMapping = NULL;
|
183
|
+
}
|
184
|
+
if (hFile != INVALID_HANDLE_VALUE) {
|
185
|
+
CloseHandle (hFile);
|
186
|
+
hMapping = INVALID_HANDLE_VALUE;
|
187
|
+
}
|
188
|
+
}
|
189
|
+
|
190
|
+
|
191
|
+
/******************
|
192
|
+
Mapper_t::GetChunk
|
193
|
+
******************/
|
194
|
+
|
195
|
+
const char *Mapper_t::GetChunk (unsigned start)
|
196
|
+
{
|
197
|
+
return MapPoint + start;
|
198
|
+
}
|
199
|
+
|
200
|
+
|
201
|
+
|
202
|
+
#endif // OS_WINDOWS
|
@@ -0,0 +1,59 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
|
3
|
+
$Id: mapper.h 4529 2007-07-04 11:32:22Z francis $
|
4
|
+
|
5
|
+
File: mapper.h
|
6
|
+
Date: 02Jul07
|
7
|
+
|
8
|
+
Copyright (C) 2007 by Francis Cianfrocca. All Rights Reserved.
|
9
|
+
Gmail: garbagecat10
|
10
|
+
|
11
|
+
This program is free software; you can redistribute it and/or modify
|
12
|
+
it under the terms of either: 1) the GNU General Public License
|
13
|
+
as published by the Free Software Foundation; either version 2 of the
|
14
|
+
License, or (at your option) any later version; or 2) Ruby's License.
|
15
|
+
|
16
|
+
See the file COPYING for complete licensing information.
|
17
|
+
|
18
|
+
*****************************************************************************/
|
19
|
+
|
20
|
+
|
21
|
+
#ifndef __Mapper__H_
|
22
|
+
#define __Mapper__H_
|
23
|
+
|
24
|
+
|
25
|
+
/**************
|
26
|
+
class Mapper_t
|
27
|
+
**************/
|
28
|
+
|
29
|
+
class Mapper_t
|
30
|
+
{
|
31
|
+
public:
|
32
|
+
Mapper_t (const string&);
|
33
|
+
virtual ~Mapper_t();
|
34
|
+
|
35
|
+
const char *GetChunk (unsigned);
|
36
|
+
void Close();
|
37
|
+
size_t GetFileSize() {return FileSize;}
|
38
|
+
|
39
|
+
private:
|
40
|
+
size_t FileSize;
|
41
|
+
|
42
|
+
#ifdef OS_UNIX
|
43
|
+
private:
|
44
|
+
int Fd;
|
45
|
+
const char *MapPoint;
|
46
|
+
#endif // OS_UNIX
|
47
|
+
|
48
|
+
#ifdef OS_WIN32
|
49
|
+
private:
|
50
|
+
HANDLE hFile;
|
51
|
+
HANDLE hMapping;
|
52
|
+
const char *MapPoint;
|
53
|
+
#endif // OS_WIN32
|
54
|
+
|
55
|
+
};
|
56
|
+
|
57
|
+
|
58
|
+
#endif // __Mapper__H_
|
59
|
+
|
@@ -0,0 +1,127 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
|
3
|
+
$Id: rubymain.cpp 4529 2007-07-04 11:32:22Z francis $
|
4
|
+
|
5
|
+
File: rubymain.cpp
|
6
|
+
Date: 02Jul07
|
7
|
+
|
8
|
+
Copyright (C) 2007 by Francis Cianfrocca. All Rights Reserved.
|
9
|
+
Gmail: garbagecat10
|
10
|
+
|
11
|
+
This program is free software; you can redistribute it and/or modify
|
12
|
+
it under the terms of either: 1) the GNU General Public License
|
13
|
+
as published by the Free Software Foundation; either version 2 of the
|
14
|
+
License, or (at your option) any later version; or 2) Ruby's License.
|
15
|
+
|
16
|
+
See the file COPYING for complete licensing information.
|
17
|
+
|
18
|
+
*****************************************************************************/
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
#include <iostream>
|
23
|
+
#include <stdexcept>
|
24
|
+
using namespace std;
|
25
|
+
|
26
|
+
#include <ruby.h>
|
27
|
+
#include "mapper.h"
|
28
|
+
|
29
|
+
static VALUE EmModule;
|
30
|
+
static VALUE FastFileReader;
|
31
|
+
static VALUE Mapper;
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
/*********
|
36
|
+
mapper_dt
|
37
|
+
*********/
|
38
|
+
|
39
|
+
static void mapper_dt (void *ptr)
|
40
|
+
{
|
41
|
+
if (ptr)
|
42
|
+
delete (Mapper_t*) ptr;
|
43
|
+
}
|
44
|
+
|
45
|
+
/**********
|
46
|
+
mapper_new
|
47
|
+
**********/
|
48
|
+
|
49
|
+
static VALUE mapper_new (VALUE self, VALUE filename)
|
50
|
+
{
|
51
|
+
Mapper_t *m = new Mapper_t (StringValuePtr (filename));
|
52
|
+
if (!m)
|
53
|
+
rb_raise (rb_eException, "No Mapper Object");
|
54
|
+
VALUE v = Data_Wrap_Struct (Mapper, 0, mapper_dt, (void*)m);
|
55
|
+
return v;
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
/****************
|
60
|
+
mapper_get_chunk
|
61
|
+
****************/
|
62
|
+
|
63
|
+
static VALUE mapper_get_chunk (VALUE self, VALUE start, VALUE length)
|
64
|
+
{
|
65
|
+
Mapper_t *m = NULL;
|
66
|
+
Data_Get_Struct (self, Mapper_t, m);
|
67
|
+
if (!m)
|
68
|
+
rb_raise (rb_eException, "No Mapper Object");
|
69
|
+
|
70
|
+
// TODO, what if some moron sends us a negative start value?
|
71
|
+
unsigned _start = NUM2INT (start);
|
72
|
+
unsigned _length = NUM2INT (length);
|
73
|
+
if ((_start + _length) > m->GetFileSize())
|
74
|
+
rb_raise (rb_eException, "Mapper Range Error");
|
75
|
+
|
76
|
+
const char *chunk = m->GetChunk (_start);
|
77
|
+
if (!chunk)
|
78
|
+
rb_raise (rb_eException, "No Mapper Chunk");
|
79
|
+
return rb_str_new (chunk, _length);
|
80
|
+
}
|
81
|
+
|
82
|
+
/************
|
83
|
+
mapper_close
|
84
|
+
************/
|
85
|
+
|
86
|
+
static VALUE mapper_close (VALUE self)
|
87
|
+
{
|
88
|
+
Mapper_t *m = NULL;
|
89
|
+
Data_Get_Struct (self, Mapper_t, m);
|
90
|
+
if (!m)
|
91
|
+
rb_raise (rb_eException, "No Mapper Object");
|
92
|
+
m->Close();
|
93
|
+
return Qnil;
|
94
|
+
}
|
95
|
+
|
96
|
+
/***********
|
97
|
+
mapper_size
|
98
|
+
***********/
|
99
|
+
|
100
|
+
static VALUE mapper_size (VALUE self)
|
101
|
+
{
|
102
|
+
Mapper_t *m = NULL;
|
103
|
+
Data_Get_Struct (self, Mapper_t, m);
|
104
|
+
if (!m)
|
105
|
+
rb_raise (rb_eException, "No Mapper Object");
|
106
|
+
return INT2NUM (m->GetFileSize());
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
/**********************
|
111
|
+
Init_fastfilereaderext
|
112
|
+
**********************/
|
113
|
+
|
114
|
+
extern "C" void Init_fastfilereaderext()
|
115
|
+
{
|
116
|
+
EmModule = rb_define_module ("EventMachine");
|
117
|
+
FastFileReader = rb_define_class_under (EmModule, "FastFileReader", rb_cObject);
|
118
|
+
Mapper = rb_define_class_under (FastFileReader, "Mapper", rb_cObject);
|
119
|
+
|
120
|
+
rb_define_module_function (Mapper, "new", (VALUE(*)(...))mapper_new, 1);
|
121
|
+
rb_define_method (Mapper, "size", (VALUE(*)(...))mapper_size, 0);
|
122
|
+
rb_define_method (Mapper, "close", (VALUE(*)(...))mapper_close, 0);
|
123
|
+
rb_define_method (Mapper, "get_chunk", (VALUE(*)(...))mapper_get_chunk, 2);
|
124
|
+
}
|
125
|
+
|
126
|
+
|
127
|
+
|