eventmachine 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +44 -265
- data/GNU +281 -0
- data/LEGAL +25 -0
- data/README +5 -3
- data/RELEASE_NOTES +7 -2
- data/ext/binder.cpp +8 -15
- data/ext/binder.h +8 -15
- data/ext/cmain.cpp +29 -15
- data/ext/ed.cpp +36 -43
- data/ext/ed.h +8 -15
- data/ext/em.cpp +116 -21
- data/ext/em.h +11 -16
- data/ext/emwin.cpp +9 -16
- data/ext/emwin.h +9 -16
- data/ext/eventmachine.h +9 -14
- data/ext/extconf.rb +9 -17
- data/ext/files.cpp +7 -14
- data/ext/files.h +7 -14
- data/ext/page.cpp +8 -15
- data/ext/page.h +8 -15
- data/ext/project.h +15 -15
- data/ext/rubymain.cpp +37 -16
- data/ext/sigs.cpp +8 -15
- data/ext/sigs.h +8 -15
- data/ext/ssl.cpp +8 -15
- data/ext/ssl.h +8 -15
- data/lib/em/deferrable.rb +40 -27
- data/lib/em/eventable.rb +12 -23
- data/lib/em/future.rb +62 -0
- data/lib/eventmachine.rb +156 -66
- data/lib/eventmachine_version.rb +12 -23
- data/lib/evma.rb +15 -18
- data/lib/evma/callback.rb +16 -19
- data/lib/evma/container.rb +17 -19
- data/lib/evma/factory.rb +16 -19
- data/lib/evma/protocol.rb +17 -19
- data/lib/evma/reactor.rb +17 -19
- data/lib/pr_eventmachine.rb +12 -23
- data/lib/protocols/buftok.rb +121 -0
- data/lib/protocols/header_and_content.rb +12 -23
- data/lib/protocols/httpclient.rb +44 -31
- data/lib/protocols/line_and_text.rb +97 -118
- data/lib/protocols/tcptest.rb +12 -22
- data/tests/test_basic.rb +14 -24
- data/tests/test_eventables.rb +14 -24
- data/tests/test_exc.rb +57 -0
- data/tests/test_futures.rb +136 -0
- data/tests/test_hc.rb +14 -24
- data/tests/test_httpclient.rb +106 -25
- data/tests/test_ltp.rb +14 -23
- data/tests/test_timers.rb +109 -0
- data/tests/test_ud.rb +14 -24
- metadata +11 -2
data/LEGAL
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
LEGAL NOTICE INFORMATION
|
2
|
+
------------------------
|
3
|
+
|
4
|
+
EventMachine is Copyright (C) 2006-07 by Francis Cianfrocca.
|
5
|
+
|
6
|
+
EventMachine is copyrighted software owned by Francis Cianfrocca
|
7
|
+
(blackhedd ... gmail.com). You may redistribute and/or modify this
|
8
|
+
software as long as you comply with either the terms of the GPL
|
9
|
+
(see the file GPL), or Ruby's license (see the file COPYING).
|
10
|
+
|
11
|
+
Your use of all the files in this distribution is controlled by these
|
12
|
+
license terms, except for those files specifically mentioned below:
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
setup.rb
|
17
|
+
This file is Copyright (C) 2000-2005 by Minero Aoki
|
18
|
+
You can distribute/modify this file under the terms of
|
19
|
+
the GNU LGPL, Lesser General Public License version 2.1.
|
20
|
+
|
21
|
+
|
22
|
+
lib/protocols/buftok.rb
|
23
|
+
This file is Copyright (C) 2007 by Tony Arcieri. This file is
|
24
|
+
covered by the terms of Ruby's License (see the file COPYING).
|
25
|
+
|
data/README
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
$Id: README
|
1
|
+
$Id: README 317 2007-05-22 21:55:43Z blackhedd $
|
2
2
|
|
3
3
|
= RUBY/EventMachine
|
4
4
|
|
5
5
|
Homepage:: http://rubyeventmachine.com
|
6
|
-
Copyright:: (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
6
|
+
Copyright:: (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
7
7
|
Email:: gmail address: garbagecat10
|
8
8
|
|
9
|
-
|
9
|
+
EventMachine is copyrighted free software made available under the terms
|
10
|
+
of either the GPL or Ruby's License. See the file COPYING for full licensing
|
11
|
+
information.
|
10
12
|
See EventMachine and EventMachine::Connection for documentation and
|
11
13
|
usage examples.
|
12
14
|
|
data/RELEASE_NOTES
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
-
$Id: RELEASE_NOTES
|
1
|
+
$Id: RELEASE_NOTES 286 2006-11-28 03:18:18Z blackhedd $
|
2
2
|
|
3
3
|
RUBY/EventMachine RELEASE NOTES
|
4
4
|
|
5
5
|
--------------------------------------------------
|
6
|
-
Version: 0.7.
|
6
|
+
Version: 0.7.1, released xxNov06
|
7
|
+
Added protocol handlers for line-oriented protocols.
|
8
|
+
Various bug fixes.
|
9
|
+
|
10
|
+
--------------------------------------------------
|
11
|
+
Version: 0.7.0, released 20Nov06
|
7
12
|
Added a fix in em.cpp/ConnectToServer to fix a fatal exception that
|
8
13
|
occurred in FreeBSD when connecting successfully to a remote server.
|
9
14
|
|
data/ext/binder.cpp
CHANGED
@@ -1,26 +1,19 @@
|
|
1
1
|
/*****************************************************************************
|
2
2
|
|
3
|
-
$Id: binder.cpp
|
3
|
+
$Id: binder.cpp 318 2007-05-22 22:06:24Z blackhedd $
|
4
4
|
|
5
5
|
File: binder.cpp
|
6
6
|
Date: 07Apr06
|
7
7
|
|
8
|
-
Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
9
|
-
Gmail:
|
8
|
+
Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
9
|
+
Gmail: blackhedd
|
10
10
|
|
11
11
|
This program is free software; you can redistribute it and/or modify
|
12
|
-
it under the terms of the GNU General Public License
|
13
|
-
the Free Software Foundation; either version 2 of the
|
14
|
-
(at your option) any later version.
|
15
|
-
|
16
|
-
|
17
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
-
GNU General Public License for more details.
|
20
|
-
|
21
|
-
You should have received a copy of the GNU General Public License
|
22
|
-
along with this program; if not, write to the Free Software
|
23
|
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
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.
|
24
17
|
|
25
18
|
*****************************************************************************/
|
26
19
|
|
data/ext/binder.h
CHANGED
@@ -1,26 +1,19 @@
|
|
1
1
|
/*****************************************************************************
|
2
2
|
|
3
|
-
$Id: binder.h
|
3
|
+
$Id: binder.h 318 2007-05-22 22:06:24Z blackhedd $
|
4
4
|
|
5
5
|
File: binder.h
|
6
6
|
Date: 07Apr06
|
7
7
|
|
8
|
-
Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
9
|
-
Gmail:
|
8
|
+
Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
9
|
+
Gmail: blackhedd
|
10
10
|
|
11
11
|
This program is free software; you can redistribute it and/or modify
|
12
|
-
it under the terms of the GNU General Public License
|
13
|
-
the Free Software Foundation; either version 2 of the
|
14
|
-
(at your option) any later version.
|
15
|
-
|
16
|
-
|
17
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
-
GNU General Public License for more details.
|
20
|
-
|
21
|
-
You should have received a copy of the GNU General Public License
|
22
|
-
along with this program; if not, write to the Free Software
|
23
|
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
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.
|
24
17
|
|
25
18
|
*****************************************************************************/
|
26
19
|
|
data/ext/cmain.cpp
CHANGED
@@ -1,26 +1,19 @@
|
|
1
1
|
/*****************************************************************************
|
2
2
|
|
3
|
-
$Id: cmain.cpp
|
3
|
+
$Id: cmain.cpp 318 2007-05-22 22:06:24Z blackhedd $
|
4
4
|
|
5
|
-
File:
|
5
|
+
File: cmain.cpp
|
6
6
|
Date: 06Apr06
|
7
7
|
|
8
|
-
Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
9
|
-
Gmail:
|
8
|
+
Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
9
|
+
Gmail: blackhedd
|
10
10
|
|
11
11
|
This program is free software; you can redistribute it and/or modify
|
12
|
-
it under the terms of the GNU General Public License
|
13
|
-
the Free Software Foundation; either version 2 of the
|
14
|
-
(at your option) any later version.
|
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
15
|
|
16
|
-
|
17
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
-
GNU General Public License for more details.
|
20
|
-
|
21
|
-
You should have received a copy of the GNU General Public License
|
22
|
-
along with this program; if not, write to the Free Software
|
23
|
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
See the file COPYING for complete licensing information.
|
24
17
|
|
25
18
|
*****************************************************************************/
|
26
19
|
|
@@ -93,6 +86,17 @@ extern "C" const char *evma_connect_to_server (const char *server, int port)
|
|
93
86
|
return EventMachine->ConnectToServer (server, port);
|
94
87
|
}
|
95
88
|
|
89
|
+
/***************************
|
90
|
+
evma_connect_to_unix_server
|
91
|
+
***************************/
|
92
|
+
|
93
|
+
extern "C" const char *evma_connect_to_unix_server (const char *server)
|
94
|
+
{
|
95
|
+
if (!EventMachine)
|
96
|
+
throw std::runtime_error ("not initialized");
|
97
|
+
return EventMachine->ConnectToUnixServer (server);
|
98
|
+
}
|
99
|
+
|
96
100
|
|
97
101
|
/**********************
|
98
102
|
evma_create_tcp_server
|
@@ -276,3 +280,13 @@ extern "C" void evma_set_timer_quantum (int interval)
|
|
276
280
|
EventMachine->SetTimerQuantum (interval);
|
277
281
|
}
|
278
282
|
|
283
|
+
/******************
|
284
|
+
evma_setuid_string
|
285
|
+
******************/
|
286
|
+
|
287
|
+
extern "C" void evma_setuid_string (const char *username)
|
288
|
+
{
|
289
|
+
// We do NOT need to be running an EM instance because this method is static.
|
290
|
+
EventMachine_t::SetuidString (username);
|
291
|
+
}
|
292
|
+
|
data/ext/ed.cpp
CHANGED
@@ -1,26 +1,19 @@
|
|
1
1
|
/*****************************************************************************
|
2
2
|
|
3
|
-
$Id: ed.cpp
|
3
|
+
$Id: ed.cpp 318 2007-05-22 22:06:24Z blackhedd $
|
4
4
|
|
5
5
|
File: ed.cpp
|
6
6
|
Date: 06Apr06
|
7
7
|
|
8
|
-
Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
9
|
-
Gmail:
|
8
|
+
Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
9
|
+
Gmail: blackhedd
|
10
10
|
|
11
11
|
This program is free software; you can redistribute it and/or modify
|
12
|
-
it under the terms of the GNU General Public License
|
13
|
-
the Free Software Foundation; either version 2 of the
|
14
|
-
(at your option) any later version.
|
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
15
|
|
16
|
-
|
17
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
-
GNU General Public License for more details.
|
20
|
-
|
21
|
-
You should have received a copy of the GNU General Public License
|
22
|
-
along with this program; if not, write to the Free Software
|
23
|
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
See the file COPYING for complete licensing information.
|
24
17
|
|
25
18
|
*****************************************************************************/
|
26
19
|
|
@@ -51,37 +44,37 @@ EventableDescriptor::EventableDescriptor
|
|
51
44
|
****************************************/
|
52
45
|
|
53
46
|
EventableDescriptor::EventableDescriptor (int sd):
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
47
|
+
EventCallback (NULL),
|
48
|
+
LastRead (0),
|
49
|
+
LastWritten (0),
|
50
|
+
MySocket (sd),
|
51
|
+
bCloseNow (false),
|
52
|
+
bCloseAfterWriting (false)
|
60
53
|
{
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
54
|
+
/* There are three ways to close a socket, all of which should
|
55
|
+
* automatically signal to the event machine that this object
|
56
|
+
* should be removed from the polling scheduler.
|
57
|
+
* First is a hard close, intended for bad errors or possible
|
58
|
+
* security violations. It immediately closes the connection
|
59
|
+
* and puts this object into an error state.
|
60
|
+
* Second is to set bCloseNow, which will cause the event machine
|
61
|
+
* to delete this object (and thus close the connection in our
|
62
|
+
* destructor) the next chance it gets. bCloseNow also inhibits
|
63
|
+
* the writing of new data on the socket (but not necessarily
|
64
|
+
* the reading of new data).
|
65
|
+
* The third way is to set bCloseAfterWriting, which inhibits
|
66
|
+
* the writing of new data and converts to bCloseNow as soon
|
67
|
+
* as everything in the outbound queue has been written.
|
68
|
+
* bCloseAfterWriting is really for use only by protocol handlers
|
69
|
+
* (for example, HTTP writes an HTML page and then closes the
|
70
|
+
* connection). All of the error states we generate internally
|
71
|
+
* cause an immediate close to be scheduled, which may have the
|
72
|
+
* effect of discarding outbound data.
|
73
|
+
*/
|
81
74
|
|
82
|
-
|
83
|
-
|
84
|
-
|
75
|
+
if (sd == INVALID_SOCKET)
|
76
|
+
throw std::runtime_error ("bad eventable descriptor");
|
77
|
+
CreatedAt = gCurrentLoopTime;
|
85
78
|
}
|
86
79
|
|
87
80
|
|
data/ext/ed.h
CHANGED
@@ -1,26 +1,19 @@
|
|
1
1
|
/*****************************************************************************
|
2
2
|
|
3
|
-
$Id: ed.h
|
3
|
+
$Id: ed.h 318 2007-05-22 22:06:24Z blackhedd $
|
4
4
|
|
5
5
|
File: ed.h
|
6
6
|
Date: 06Apr06
|
7
7
|
|
8
|
-
Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
9
|
-
Gmail:
|
8
|
+
Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
9
|
+
Gmail: blackhedd
|
10
10
|
|
11
11
|
This program is free software; you can redistribute it and/or modify
|
12
|
-
it under the terms of the GNU General Public License
|
13
|
-
the Free Software Foundation; either version 2 of the
|
14
|
-
(at your option) any later version.
|
15
|
-
|
16
|
-
|
17
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
-
GNU General Public License for more details.
|
20
|
-
|
21
|
-
You should have received a copy of the GNU General Public License
|
22
|
-
along with this program; if not, write to the Free Software
|
23
|
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
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.
|
24
17
|
|
25
18
|
*****************************************************************************/
|
26
19
|
|
data/ext/em.cpp
CHANGED
@@ -1,26 +1,19 @@
|
|
1
1
|
/*****************************************************************************
|
2
2
|
|
3
|
-
$Id: em.cpp
|
3
|
+
$Id: em.cpp 318 2007-05-22 22:06:24Z blackhedd $
|
4
4
|
|
5
|
-
File:
|
5
|
+
File: em.cpp
|
6
6
|
Date: 06Apr06
|
7
7
|
|
8
|
-
Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
9
|
-
Gmail:
|
8
|
+
Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
9
|
+
Gmail: blackhedd
|
10
10
|
|
11
11
|
This program is free software; you can redistribute it and/or modify
|
12
|
-
it under the terms of the GNU General Public License
|
13
|
-
the Free Software Foundation; either version 2 of the
|
14
|
-
(at your option) any later version.
|
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
15
|
|
16
|
-
|
17
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
-
GNU General Public License for more details.
|
20
|
-
|
21
|
-
You should have received a copy of the GNU General Public License
|
22
|
-
along with this program; if not, write to the Free Software
|
23
|
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
See the file COPYING for complete licensing information.
|
24
17
|
|
25
18
|
*****************************************************************************/
|
26
19
|
|
@@ -125,6 +118,35 @@ void EventMachine_t::SetTimerQuantum (int interval)
|
|
125
118
|
}
|
126
119
|
|
127
120
|
|
121
|
+
/*************************************
|
122
|
+
(STATIC) EventMachine_t::SetuidString
|
123
|
+
*************************************/
|
124
|
+
|
125
|
+
void EventMachine_t::SetuidString (const char *username)
|
126
|
+
{
|
127
|
+
/* This method takes a caller-supplied username and tries to setuid
|
128
|
+
* to that user. There is no meaningful implementation (and no error)
|
129
|
+
* on Windows. On Unix, a failure to setuid the caller-supplied string
|
130
|
+
* causes a fatal abort, because presumably the program is calling us
|
131
|
+
* in order to fulfill a security requirement. If we fail silently,
|
132
|
+
* the user may continue to run with too much privilege.
|
133
|
+
*/
|
134
|
+
|
135
|
+
#ifdef OS_UNIX
|
136
|
+
if (!username || !*username)
|
137
|
+
throw std::runtime_error ("setuid_string failed: no username specified");
|
138
|
+
|
139
|
+
struct passwd *p = getpwnam (username);
|
140
|
+
if (!p)
|
141
|
+
throw std::runtime_error ("setuid_string failed: unknown username");
|
142
|
+
|
143
|
+
if (setuid (p->pw_uid) != 0)
|
144
|
+
throw std::runtime_error ("setuid_string failed: no setuid");
|
145
|
+
|
146
|
+
// Success.
|
147
|
+
#endif
|
148
|
+
}
|
149
|
+
|
128
150
|
|
129
151
|
/*********************************
|
130
152
|
EventMachine_t::SignalLoopBreaker
|
@@ -234,7 +256,7 @@ bool EventMachine_t::_RunOnce()
|
|
234
256
|
// if we know we're running on a 2.6 kernel.
|
235
257
|
// epoll will be effective if we provide it as an alternative,
|
236
258
|
// however it has the same problem interoperating with Ruby
|
237
|
-
// threads that
|
259
|
+
// threads that select does.
|
238
260
|
|
239
261
|
//cerr << "X";
|
240
262
|
|
@@ -617,6 +639,79 @@ const char *EventMachine_t::ConnectToServer (const char *server, int port)
|
|
617
639
|
return out;
|
618
640
|
}
|
619
641
|
|
642
|
+
/***********************************
|
643
|
+
EventMachine_t::ConnectToUnixServer
|
644
|
+
***********************************/
|
645
|
+
|
646
|
+
const char *EventMachine_t::ConnectToUnixServer (const char *server)
|
647
|
+
{
|
648
|
+
/* Connect to a Unix-domain server, which by definition is running
|
649
|
+
* on the same host.
|
650
|
+
* There is no meaningful implementation on Windows.
|
651
|
+
* There's no need to do a nonblocking connect, since the connection
|
652
|
+
* is always local and can always be fulfilled immediately.
|
653
|
+
*/
|
654
|
+
|
655
|
+
#ifdef OS_WIN32
|
656
|
+
throw std::runtime_error ("unix-domain connection unavailable on this platform");
|
657
|
+
return NULL;
|
658
|
+
#endif
|
659
|
+
|
660
|
+
// The whole rest of this function is only compiled on Unix systems.
|
661
|
+
#ifdef OS_UNIX
|
662
|
+
|
663
|
+
const char *out = NULL;
|
664
|
+
|
665
|
+
if (!server || !*server)
|
666
|
+
return NULL;
|
667
|
+
|
668
|
+
sockaddr_un pun;
|
669
|
+
memset (&pun, 0, sizeof(pun));
|
670
|
+
pun.sun_family = AF_LOCAL;
|
671
|
+
|
672
|
+
// You ordinarily expect the server name field to be at least 1024 bytes long,
|
673
|
+
// but on Linux it can be MUCH shorter.
|
674
|
+
if (strlen(server) >= sizeof(pun.sun_path))
|
675
|
+
throw std::runtime_error ("unix-domain server name is too long");
|
676
|
+
|
677
|
+
|
678
|
+
strcpy (pun.sun_path, server);
|
679
|
+
|
680
|
+
int fd = socket (AF_LOCAL, SOCK_STREAM, 0);
|
681
|
+
if (fd == INVALID_SOCKET)
|
682
|
+
return NULL;
|
683
|
+
|
684
|
+
// From here on, ALL error returns must close the socket.
|
685
|
+
// NOTE: At this point, the socket is still a blocking socket.
|
686
|
+
if (connect (fd, (struct sockaddr*)&pun, sizeof(pun)) != 0) {
|
687
|
+
closesocket (fd);
|
688
|
+
return NULL;
|
689
|
+
}
|
690
|
+
|
691
|
+
// Set the newly-connected socket nonblocking.
|
692
|
+
if (!SetSocketNonblocking (fd)) {
|
693
|
+
closesocket (fd);
|
694
|
+
return NULL;
|
695
|
+
}
|
696
|
+
|
697
|
+
// Set up a connection descriptor and add it to the event-machine.
|
698
|
+
// Observe, even though we know the connection status is connect-success,
|
699
|
+
// we still set the "pending" flag, so some needed initializations take
|
700
|
+
// place.
|
701
|
+
ConnectionDescriptor *cd = new ConnectionDescriptor (fd);
|
702
|
+
if (!cd)
|
703
|
+
throw std::runtime_error ("no connection allocated");
|
704
|
+
cd->SetConnectPending (true);
|
705
|
+
Add (cd);
|
706
|
+
out = cd->GetBinding().c_str();
|
707
|
+
|
708
|
+
if (out == NULL)
|
709
|
+
closesocket (fd);
|
710
|
+
|
711
|
+
return out;
|
712
|
+
#endif
|
713
|
+
}
|
714
|
+
|
620
715
|
|
621
716
|
/*******************************
|
622
717
|
EventMachine_t::CreateTcpServer
|
@@ -859,7 +954,7 @@ const char *EventMachine_t::CreateUnixDomainServer (const char *filename)
|
|
859
954
|
#ifdef OS_UNIX
|
860
955
|
const char *output_binding = NULL;
|
861
956
|
|
862
|
-
struct sockaddr_un
|
957
|
+
struct sockaddr_un s_sun;
|
863
958
|
|
864
959
|
int sd_accept = socket (AF_LOCAL, SOCK_STREAM, 0);
|
865
960
|
if (sd_accept == INVALID_SOCKET) {
|
@@ -870,9 +965,9 @@ const char *EventMachine_t::CreateUnixDomainServer (const char *filename)
|
|
870
965
|
goto fail;
|
871
966
|
unlink (filename);
|
872
967
|
|
873
|
-
bzero (&
|
874
|
-
|
875
|
-
strncpy (
|
968
|
+
bzero (&s_sun, sizeof(s_sun));
|
969
|
+
s_sun.sun_family = AF_LOCAL;
|
970
|
+
strncpy (s_sun.sun_path, filename, sizeof(s_sun.sun_path)-1);
|
876
971
|
|
877
972
|
// don't bother with reuseaddr for a local socket.
|
878
973
|
|
@@ -885,7 +980,7 @@ const char *EventMachine_t::CreateUnixDomainServer (const char *filename)
|
|
885
980
|
#endif
|
886
981
|
}
|
887
982
|
|
888
|
-
if (bind (sd_accept, (struct sockaddr*)&
|
983
|
+
if (bind (sd_accept, (struct sockaddr*)&s_sun, sizeof(s_sun))) {
|
889
984
|
//__warning ("binding failed");
|
890
985
|
goto fail;
|
891
986
|
}
|