eventmachine 1.0.9.1 → 1.2.0.dev.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.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/ext/cmain.cpp +77 -5
- data/ext/ed.cpp +100 -39
- data/ext/ed.h +27 -13
- data/ext/em.cpp +105 -163
- data/ext/em.h +10 -7
- data/ext/eventmachine.h +13 -1
- data/ext/extconf.rb +22 -13
- data/ext/fastfilereader/rubymain.cpp +6 -6
- data/ext/project.h +9 -4
- data/ext/rubymain.cpp +155 -36
- data/ext/ssl.cpp +157 -13
- data/ext/ssl.h +7 -2
- data/lib/em/channel.rb +5 -0
- data/lib/em/completion.rb +2 -2
- data/lib/em/connection.rb +61 -3
- data/lib/em/iterator.rb +26 -5
- data/lib/em/pool.rb +1 -1
- data/lib/em/protocols/line_and_text.rb +1 -1
- data/lib/em/pure_ruby.rb +6 -1
- data/lib/em/queue.rb +16 -7
- data/lib/em/resolver.rb +46 -23
- data/lib/em/threaded_resource.rb +2 -2
- data/lib/em/version.rb +1 -1
- data/lib/eventmachine.rb +59 -42
- data/rakelib/package.rake +23 -1
- data/tests/dhparam.pem +13 -0
- data/tests/em_test_helper.rb +79 -0
- data/tests/test_basic.rb +17 -26
- data/tests/test_channel.rb +14 -1
- data/tests/test_connection_write.rb +2 -2
- data/tests/test_defer.rb +17 -0
- data/tests/test_epoll.rb +1 -1
- data/tests/test_fork.rb +75 -0
- data/tests/test_ipv4.rb +125 -0
- data/tests/test_ipv6.rb +131 -0
- data/tests/test_iterator.rb +18 -0
- data/tests/test_many_fds.rb +1 -1
- data/tests/test_queue.rb +14 -0
- data/tests/test_resolver.rb +23 -0
- data/tests/test_set_sock_opt.rb +2 -0
- data/tests/test_ssl_dhparam.rb +83 -0
- data/tests/test_ssl_ecdh_curve.rb +79 -0
- data/tests/test_ssl_extensions.rb +49 -0
- data/tests/test_ssl_methods.rb +19 -0
- data/tests/test_ssl_protocols.rb +246 -0
- data/tests/test_ssl_verify.rb +44 -0
- data/tests/test_system.rb +4 -0
- data/tests/test_unbind_reason.rb +5 -1
- metadata +116 -49
- data/.gitignore +0 -21
- data/.travis.yml +0 -22
- data/.yardopts +0 -7
- data/Gemfile +0 -2
- data/Rakefile +0 -20
- data/eventmachine.gemspec +0 -38
- data/rakelib/cpp.rake_example +0 -77
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a994ca9df20011c3235aa182177c104b2addf877
|
4
|
+
data.tar.gz: 4ed4c114fea5873f2df925b8f107be1e8dc9fc71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b563fae2d491799348769d7e8ce2f7a189600220ba60a0e4356fd1f2a73c97d24643724737cd1bb9e625e5db902233e5b1994c9c84750ec37742bffe142b15c2
|
7
|
+
data.tar.gz: 1d79e3826c263467b34bc5b448d5170c48ae06b3121eff3f90913ee9dd3606364ed10adbd2a3b5170f141272db681daf9d9000976f900c85ee9006e07834380c
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# About EventMachine [](https://codeclimate.com/github/eventmachine/eventmachine)
|
2
2
|
|
3
3
|
|
4
4
|
## What is EventMachine ##
|
@@ -18,7 +18,7 @@ This unique combination makes EventMachine a premier choice for designers of cri
|
|
18
18
|
applications, including Web servers and proxies, email and IM production systems, authentication/authorization
|
19
19
|
processors, and many more.
|
20
20
|
|
21
|
-
EventMachine has been around since the early 2000s and is a mature and battle
|
21
|
+
EventMachine has been around since the early 2000s and is a mature and battle-tested library.
|
22
22
|
|
23
23
|
|
24
24
|
## What EventMachine is good for? ##
|
data/ext/cmain.cpp
CHANGED
@@ -433,6 +433,15 @@ extern "C" void evma_stop_machine()
|
|
433
433
|
EventMachine->ScheduleHalt();
|
434
434
|
}
|
435
435
|
|
436
|
+
/*****************
|
437
|
+
evma_stopping
|
438
|
+
*****************/
|
439
|
+
|
440
|
+
extern "C" bool evma_stopping()
|
441
|
+
{
|
442
|
+
ensure_eventmachine("evma_stopping");
|
443
|
+
return EventMachine->Stopping();
|
444
|
+
}
|
436
445
|
|
437
446
|
/**************
|
438
447
|
evma_start_tls
|
@@ -450,12 +459,12 @@ extern "C" void evma_start_tls (const uintptr_t binding)
|
|
450
459
|
evma_set_tls_parms
|
451
460
|
******************/
|
452
461
|
|
453
|
-
extern "C" void evma_set_tls_parms (const uintptr_t binding, const char *privatekey_filename, const char *certchain_filename, int verify_peer)
|
462
|
+
extern "C" void evma_set_tls_parms (const uintptr_t binding, const char *privatekey_filename, const char *certchain_filename, int verify_peer, int fail_if_no_peer_cert, const char *sni_hostname, const char *cipherlist, const char *ecdh_curve, const char *dhparam, int ssl_version)
|
454
463
|
{
|
455
464
|
ensure_eventmachine("evma_set_tls_parms");
|
456
465
|
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
457
466
|
if (ed)
|
458
|
-
ed->SetTlsParms (privatekey_filename, certchain_filename, (verify_peer == 1 ? true : false));
|
467
|
+
ed->SetTlsParms (privatekey_filename, certchain_filename, (verify_peer == 1 ? true : false), (fail_if_no_peer_cert == 1 ? true : false), sni_hostname, cipherlist, ecdh_curve, dhparam, ssl_version);
|
459
468
|
}
|
460
469
|
|
461
470
|
/******************
|
@@ -473,6 +482,66 @@ extern "C" X509 *evma_get_peer_cert (const uintptr_t binding)
|
|
473
482
|
}
|
474
483
|
#endif
|
475
484
|
|
485
|
+
/******************
|
486
|
+
evma_get_cipher_bits
|
487
|
+
******************/
|
488
|
+
|
489
|
+
#ifdef WITH_SSL
|
490
|
+
extern "C" int evma_get_cipher_bits (const uintptr_t binding)
|
491
|
+
{
|
492
|
+
ensure_eventmachine("evma_get_cipher_bits");
|
493
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
494
|
+
if (ed)
|
495
|
+
return ed->GetCipherBits();
|
496
|
+
return -1;
|
497
|
+
}
|
498
|
+
#endif
|
499
|
+
|
500
|
+
/******************
|
501
|
+
evma_get_cipher_name
|
502
|
+
******************/
|
503
|
+
|
504
|
+
#ifdef WITH_SSL
|
505
|
+
extern "C" const char *evma_get_cipher_name (const uintptr_t binding)
|
506
|
+
{
|
507
|
+
ensure_eventmachine("evma_get_cipher_name");
|
508
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
509
|
+
if (ed)
|
510
|
+
return ed->GetCipherName();
|
511
|
+
return NULL;
|
512
|
+
}
|
513
|
+
#endif
|
514
|
+
|
515
|
+
/******************
|
516
|
+
evma_get_cipher_protocol
|
517
|
+
******************/
|
518
|
+
|
519
|
+
#ifdef WITH_SSL
|
520
|
+
extern "C" const char *evma_get_cipher_protocol (const uintptr_t binding)
|
521
|
+
{
|
522
|
+
ensure_eventmachine("evma_get_cipher_protocol");
|
523
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
524
|
+
if (ed)
|
525
|
+
return ed->GetCipherProtocol();
|
526
|
+
return NULL;
|
527
|
+
}
|
528
|
+
#endif
|
529
|
+
|
530
|
+
/******************
|
531
|
+
evma_get_sni_hostname
|
532
|
+
******************/
|
533
|
+
|
534
|
+
#ifdef WITH_SSL
|
535
|
+
extern "C" const char *evma_get_sni_hostname (const uintptr_t binding)
|
536
|
+
{
|
537
|
+
ensure_eventmachine("evma_get_sni_hostname");
|
538
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
539
|
+
if (ed)
|
540
|
+
return ed->GetSNIHostname();
|
541
|
+
return NULL;
|
542
|
+
}
|
543
|
+
#endif
|
544
|
+
|
476
545
|
/********************
|
477
546
|
evma_accept_ssl_peer
|
478
547
|
********************/
|
@@ -521,10 +590,10 @@ extern "C" int evma_get_sockname (const uintptr_t binding, struct sockaddr *sa,
|
|
521
590
|
evma_get_subprocess_pid
|
522
591
|
***********************/
|
523
592
|
|
593
|
+
#ifdef OS_UNIX
|
524
594
|
extern "C" int evma_get_subprocess_pid (const uintptr_t binding, pid_t *pid)
|
525
595
|
{
|
526
596
|
ensure_eventmachine("evma_get_subprocess_pid");
|
527
|
-
#ifdef OS_UNIX
|
528
597
|
PipeDescriptor *pd = dynamic_cast <PipeDescriptor*> (Bindable_t::GetObject (binding));
|
529
598
|
if (pd) {
|
530
599
|
return pd->GetSubprocessPid (pid) ? 1 : 0;
|
@@ -535,10 +604,13 @@ extern "C" int evma_get_subprocess_pid (const uintptr_t binding, pid_t *pid)
|
|
535
604
|
}
|
536
605
|
else
|
537
606
|
return 0;
|
538
|
-
|
607
|
+
}
|
608
|
+
#else
|
609
|
+
extern "C" int evma_get_subprocess_pid (const uintptr_t binding UNUSED, pid_t *pid UNUSED)
|
610
|
+
{
|
539
611
|
return 0;
|
540
|
-
#endif
|
541
612
|
}
|
613
|
+
#endif
|
542
614
|
|
543
615
|
/**************************
|
544
616
|
evma_get_subprocess_status
|
data/ext/ed.cpp
CHANGED
@@ -49,24 +49,26 @@ bool SetSocketNonblocking (SOCKET sd)
|
|
49
49
|
SetFdCloexec
|
50
50
|
************/
|
51
51
|
|
52
|
+
#ifdef OS_UNIX
|
52
53
|
bool SetFdCloexec (int fd)
|
53
54
|
{
|
54
|
-
#ifdef OS_UNIX
|
55
55
|
int flags = fcntl(fd, F_GETFD, 0);
|
56
56
|
assert (flags >= 0);
|
57
57
|
flags |= FD_CLOEXEC;
|
58
58
|
return (fcntl(fd, F_SETFD, FD_CLOEXEC) == 0) ? true : false;
|
59
|
-
|
60
|
-
|
59
|
+
}
|
60
|
+
#else
|
61
|
+
bool SetFdCloexec (int fd UNUSED)
|
62
|
+
{
|
61
63
|
return true;
|
62
|
-
#endif
|
63
64
|
}
|
65
|
+
#endif
|
64
66
|
|
65
67
|
/****************************************
|
66
68
|
EventableDescriptor::EventableDescriptor
|
67
69
|
****************************************/
|
68
70
|
|
69
|
-
EventableDescriptor::EventableDescriptor (
|
71
|
+
EventableDescriptor::EventableDescriptor (SOCKET sd, EventMachine_t *em):
|
70
72
|
bCloseNow (false),
|
71
73
|
bCloseAfterWriting (false),
|
72
74
|
MySocket (sd),
|
@@ -387,7 +389,7 @@ uint64_t EventableDescriptor::GetNextHeartbeat()
|
|
387
389
|
ConnectionDescriptor::ConnectionDescriptor
|
388
390
|
******************************************/
|
389
391
|
|
390
|
-
ConnectionDescriptor::ConnectionDescriptor (
|
392
|
+
ConnectionDescriptor::ConnectionDescriptor (SOCKET sd, EventMachine_t *em):
|
391
393
|
EventableDescriptor (sd, em),
|
392
394
|
bConnectPending (false),
|
393
395
|
bNotifyReadable (false),
|
@@ -442,6 +444,9 @@ void ConnectionDescriptor::_UpdateEvents(bool read, bool write)
|
|
442
444
|
if (MySocket == INVALID_SOCKET)
|
443
445
|
return;
|
444
446
|
|
447
|
+
if (!read && !write)
|
448
|
+
return;
|
449
|
+
|
445
450
|
#ifdef HAVE_EPOLL
|
446
451
|
unsigned int old = EpollEvent.events;
|
447
452
|
|
@@ -768,7 +773,7 @@ void ConnectionDescriptor::Read()
|
|
768
773
|
* come here more than once after being closed. (FCianfrocca)
|
769
774
|
*/
|
770
775
|
|
771
|
-
|
776
|
+
SOCKET sd = GetSocket();
|
772
777
|
//assert (sd != INVALID_SOCKET); (original, removed 22Aug06)
|
773
778
|
if (sd == INVALID_SOCKET) {
|
774
779
|
assert (!bReadAttemptedAfterClose);
|
@@ -1010,7 +1015,7 @@ void ConnectionDescriptor::_WriteOutboundData()
|
|
1010
1015
|
* doing it to address some reports of crashing under heavy loads.
|
1011
1016
|
*/
|
1012
1017
|
|
1013
|
-
|
1018
|
+
SOCKET sd = GetSocket();
|
1014
1019
|
//assert (sd != INVALID_SOCKET);
|
1015
1020
|
if (sd == INVALID_SOCKET) {
|
1016
1021
|
assert (!bWriteAttemptedAfterClose);
|
@@ -1180,7 +1185,7 @@ void ConnectionDescriptor::StartTls()
|
|
1180
1185
|
if (SslBox)
|
1181
1186
|
throw std::runtime_error ("SSL/TLS already running on connection");
|
1182
1187
|
|
1183
|
-
SslBox = new SslBox_t (bIsServer, PrivateKeyFilename, CertChainFilename, bSslVerifyPeer, GetBinding());
|
1188
|
+
SslBox = new SslBox_t (bIsServer, PrivateKeyFilename, CertChainFilename, bSslVerifyPeer, bSslFailIfNoPeerCert, SniHostName, CipherList, EcdhCurve, DhParam, Protocols, GetBinding());
|
1184
1189
|
_DispatchCiphertext();
|
1185
1190
|
|
1186
1191
|
}
|
@@ -1197,7 +1202,7 @@ ConnectionDescriptor::SetTlsParms
|
|
1197
1202
|
*********************************/
|
1198
1203
|
|
1199
1204
|
#ifdef WITH_SSL
|
1200
|
-
void ConnectionDescriptor::SetTlsParms (const char *privkey_filename, const char *certchain_filename, bool verify_peer)
|
1205
|
+
void ConnectionDescriptor::SetTlsParms (const char *privkey_filename, const char *certchain_filename, bool verify_peer, bool fail_if_no_peer_cert, const char *sni_hostname, const char *cipherlist, const char *ecdh_curve, const char *dhparam, int protocols)
|
1201
1206
|
{
|
1202
1207
|
if (SslBox)
|
1203
1208
|
throw std::runtime_error ("call SetTlsParms before calling StartTls");
|
@@ -1205,10 +1210,22 @@ void ConnectionDescriptor::SetTlsParms (const char *privkey_filename, const char
|
|
1205
1210
|
PrivateKeyFilename = privkey_filename;
|
1206
1211
|
if (certchain_filename && *certchain_filename)
|
1207
1212
|
CertChainFilename = certchain_filename;
|
1208
|
-
bSslVerifyPeer
|
1213
|
+
bSslVerifyPeer = verify_peer;
|
1214
|
+
bSslFailIfNoPeerCert = fail_if_no_peer_cert;
|
1215
|
+
|
1216
|
+
if (sni_hostname && *sni_hostname)
|
1217
|
+
SniHostName = sni_hostname;
|
1218
|
+
if (cipherlist && *cipherlist)
|
1219
|
+
CipherList = cipherlist;
|
1220
|
+
if (ecdh_curve && *ecdh_curve)
|
1221
|
+
EcdhCurve = ecdh_curve;
|
1222
|
+
if (dhparam && *dhparam)
|
1223
|
+
DhParam = dhparam;
|
1224
|
+
|
1225
|
+
Protocols = protocols;
|
1209
1226
|
}
|
1210
1227
|
#else
|
1211
|
-
void ConnectionDescriptor::SetTlsParms (const char *privkey_filename UNUSED, const char *certchain_filename UNUSED, bool verify_peer UNUSED)
|
1228
|
+
void ConnectionDescriptor::SetTlsParms (const char *privkey_filename UNUSED, const char *certchain_filename UNUSED, bool verify_peer UNUSED, bool fail_if_no_peer_cert UNUSED, const char *sni_hostname UNUSED, const char *cipherlist UNUSED, const char *ecdh_curve UNUSED, const char *dhparam UNUSED, int protocols UNUSED)
|
1212
1229
|
{
|
1213
1230
|
throw std::runtime_error ("Encryption not available on this event-machine");
|
1214
1231
|
}
|
@@ -1229,6 +1246,62 @@ X509 *ConnectionDescriptor::GetPeerCert()
|
|
1229
1246
|
#endif
|
1230
1247
|
|
1231
1248
|
|
1249
|
+
/*********************************
|
1250
|
+
ConnectionDescriptor::GetCipherBits
|
1251
|
+
*********************************/
|
1252
|
+
|
1253
|
+
#ifdef WITH_SSL
|
1254
|
+
int ConnectionDescriptor::GetCipherBits()
|
1255
|
+
{
|
1256
|
+
if (!SslBox)
|
1257
|
+
throw std::runtime_error ("SSL/TLS not running on this connection");
|
1258
|
+
return SslBox->GetCipherBits();
|
1259
|
+
}
|
1260
|
+
#endif
|
1261
|
+
|
1262
|
+
|
1263
|
+
/*********************************
|
1264
|
+
ConnectionDescriptor::GetCipherName
|
1265
|
+
*********************************/
|
1266
|
+
|
1267
|
+
#ifdef WITH_SSL
|
1268
|
+
const char *ConnectionDescriptor::GetCipherName()
|
1269
|
+
{
|
1270
|
+
if (!SslBox)
|
1271
|
+
throw std::runtime_error ("SSL/TLS not running on this connection");
|
1272
|
+
return SslBox->GetCipherName();
|
1273
|
+
}
|
1274
|
+
#endif
|
1275
|
+
|
1276
|
+
|
1277
|
+
/*********************************
|
1278
|
+
ConnectionDescriptor::GetCipherProtocol
|
1279
|
+
*********************************/
|
1280
|
+
|
1281
|
+
#ifdef WITH_SSL
|
1282
|
+
const char *ConnectionDescriptor::GetCipherProtocol()
|
1283
|
+
{
|
1284
|
+
if (!SslBox)
|
1285
|
+
throw std::runtime_error ("SSL/TLS not running on this connection");
|
1286
|
+
return SslBox->GetCipherProtocol();
|
1287
|
+
}
|
1288
|
+
#endif
|
1289
|
+
|
1290
|
+
|
1291
|
+
/*********************************
|
1292
|
+
ConnectionDescriptor::GetSNIHostname
|
1293
|
+
*********************************/
|
1294
|
+
|
1295
|
+
#ifdef WITH_SSL
|
1296
|
+
const char *ConnectionDescriptor::GetSNIHostname()
|
1297
|
+
{
|
1298
|
+
if (!SslBox)
|
1299
|
+
throw std::runtime_error ("SSL/TLS not running on this connection");
|
1300
|
+
return SslBox->GetSNIHostname();
|
1301
|
+
}
|
1302
|
+
#endif
|
1303
|
+
|
1304
|
+
|
1232
1305
|
/***********************************
|
1233
1306
|
ConnectionDescriptor::VerifySslPeer
|
1234
1307
|
***********************************/
|
@@ -1356,7 +1429,7 @@ void ConnectionDescriptor::Heartbeat()
|
|
1356
1429
|
LoopbreakDescriptor::LoopbreakDescriptor
|
1357
1430
|
****************************************/
|
1358
1431
|
|
1359
|
-
LoopbreakDescriptor::LoopbreakDescriptor (
|
1432
|
+
LoopbreakDescriptor::LoopbreakDescriptor (SOCKET sd, EventMachine_t *parent_em):
|
1360
1433
|
EventableDescriptor (sd, parent_em)
|
1361
1434
|
{
|
1362
1435
|
/* This is really bad and ugly. Change someday if possible.
|
@@ -1403,7 +1476,7 @@ void LoopbreakDescriptor::Write()
|
|
1403
1476
|
AcceptorDescriptor::AcceptorDescriptor
|
1404
1477
|
**************************************/
|
1405
1478
|
|
1406
|
-
AcceptorDescriptor::AcceptorDescriptor (
|
1479
|
+
AcceptorDescriptor::AcceptorDescriptor (SOCKET sd, EventMachine_t *parent_em):
|
1407
1480
|
EventableDescriptor (sd, parent_em)
|
1408
1481
|
{
|
1409
1482
|
#ifdef HAVE_EPOLL
|
@@ -1463,15 +1536,15 @@ void AcceptorDescriptor::Read()
|
|
1463
1536
|
int accept_count = EventMachine_t::GetSimultaneousAcceptCount();
|
1464
1537
|
|
1465
1538
|
for (int i=0; i < accept_count; i++) {
|
1466
|
-
#if defined(
|
1467
|
-
|
1539
|
+
#if defined(HAVE_CONST_SOCK_CLOEXEC) && defined(HAVE_ACCEPT4)
|
1540
|
+
SOCKET sd = accept4 (GetSocket(), (struct sockaddr*)&pin, &addrlen, SOCK_CLOEXEC);
|
1468
1541
|
if (sd == INVALID_SOCKET) {
|
1469
1542
|
// We may be running in a kernel where
|
1470
1543
|
// SOCK_CLOEXEC is not supported - fall back:
|
1471
1544
|
sd = accept (GetSocket(), (struct sockaddr*)&pin, &addrlen);
|
1472
1545
|
}
|
1473
1546
|
#else
|
1474
|
-
|
1547
|
+
SOCKET sd = accept (GetSocket(), (struct sockaddr*)&pin, &addrlen);
|
1475
1548
|
#endif
|
1476
1549
|
if (sd == INVALID_SOCKET) {
|
1477
1550
|
// This breaks the loop when we've accepted everything on the kernel queue,
|
@@ -1567,7 +1640,7 @@ bool AcceptorDescriptor::GetSockname (struct sockaddr *s, socklen_t *len)
|
|
1567
1640
|
DatagramDescriptor::DatagramDescriptor
|
1568
1641
|
**************************************/
|
1569
1642
|
|
1570
|
-
DatagramDescriptor::DatagramDescriptor (
|
1643
|
+
DatagramDescriptor::DatagramDescriptor (SOCKET sd, EventMachine_t *parent_em):
|
1571
1644
|
EventableDescriptor (sd, parent_em),
|
1572
1645
|
OutboundDataSize (0)
|
1573
1646
|
{
|
@@ -1635,7 +1708,7 @@ DatagramDescriptor::Read
|
|
1635
1708
|
|
1636
1709
|
void DatagramDescriptor::Read()
|
1637
1710
|
{
|
1638
|
-
|
1711
|
+
SOCKET sd = GetSocket();
|
1639
1712
|
assert (sd != INVALID_SOCKET);
|
1640
1713
|
LastActivity = MyEventMachine->GetCurrentLoopTime();
|
1641
1714
|
|
@@ -1712,7 +1785,7 @@ void DatagramDescriptor::Write()
|
|
1712
1785
|
* TODO, we are currently suppressing the EMSGSIZE error!!!
|
1713
1786
|
*/
|
1714
1787
|
|
1715
|
-
|
1788
|
+
SOCKET sd = GetSocket();
|
1716
1789
|
assert (sd != INVALID_SOCKET);
|
1717
1790
|
LastActivity = MyEventMachine->GetCurrentLoopTime();
|
1718
1791
|
|
@@ -1725,7 +1798,8 @@ void DatagramDescriptor::Write()
|
|
1725
1798
|
OutboundPage *op = &(OutboundPages[0]);
|
1726
1799
|
|
1727
1800
|
// The nasty cast to (char*) is needed because Windows is brain-dead.
|
1728
|
-
int s = sendto (sd, (char*)op->Buffer, op->Length, 0, (struct sockaddr*)&(op->From),
|
1801
|
+
int s = sendto (sd, (char*)op->Buffer, op->Length, 0, (struct sockaddr*)&(op->From),
|
1802
|
+
(op->From.sin6_family == AF_INET6 ? sizeof (struct sockaddr_in6) : sizeof (struct sockaddr_in)));
|
1729
1803
|
#ifdef OS_WIN32
|
1730
1804
|
int e = WSAGetLastError();
|
1731
1805
|
#else
|
@@ -1837,23 +1911,10 @@ int DatagramDescriptor::SendOutboundDatagram (const char *data, unsigned long le
|
|
1837
1911
|
if (!address || !*address || !port)
|
1838
1912
|
return 0;
|
1839
1913
|
|
1840
|
-
|
1841
|
-
|
1842
|
-
|
1843
|
-
|
1844
|
-
if (HostAddr == INADDR_NONE) {
|
1845
|
-
// The nasty cast to (char*) is because Windows is brain-dead.
|
1846
|
-
hostent *hp = gethostbyname ((char*)address);
|
1847
|
-
if (!hp)
|
1848
|
-
return 0;
|
1849
|
-
HostAddr = ((in_addr*)(hp->h_addr))->s_addr;
|
1850
|
-
}
|
1851
|
-
|
1852
|
-
memset (&pin, 0, sizeof(pin));
|
1853
|
-
pin.sin_family = AF_INET;
|
1854
|
-
pin.sin_addr.s_addr = HostAddr;
|
1855
|
-
pin.sin_port = htons (port);
|
1856
|
-
|
1914
|
+
struct sockaddr_in6 addr_here;
|
1915
|
+
size_t addr_here_len = sizeof addr_here;
|
1916
|
+
if (!EventMachine_t::name2address (address, port, (struct sockaddr *)&addr_here, &addr_here_len))
|
1917
|
+
return -1;
|
1857
1918
|
|
1858
1919
|
if (!data && (length > 0))
|
1859
1920
|
throw std::runtime_error ("bad outbound data");
|
@@ -1862,7 +1923,7 @@ int DatagramDescriptor::SendOutboundDatagram (const char *data, unsigned long le
|
|
1862
1923
|
throw std::runtime_error ("no allocation for outbound data");
|
1863
1924
|
memcpy (buffer, data, length);
|
1864
1925
|
buffer [length] = 0;
|
1865
|
-
OutboundPages.push_back (OutboundPage (buffer, length,
|
1926
|
+
OutboundPages.push_back (OutboundPage (buffer, length, addr_here));
|
1866
1927
|
OutboundDataSize += length;
|
1867
1928
|
|
1868
1929
|
#ifdef HAVE_EPOLL
|
data/ext/ed.h
CHANGED
@@ -36,10 +36,10 @@ class EventableDescriptor
|
|
36
36
|
class EventableDescriptor: public Bindable_t
|
37
37
|
{
|
38
38
|
public:
|
39
|
-
EventableDescriptor (
|
39
|
+
EventableDescriptor (SOCKET, EventMachine_t*);
|
40
40
|
virtual ~EventableDescriptor();
|
41
41
|
|
42
|
-
|
42
|
+
SOCKET GetSocket() {return MySocket;}
|
43
43
|
void SetSocketInvalid() { MySocket = INVALID_SOCKET; }
|
44
44
|
void Close();
|
45
45
|
|
@@ -69,10 +69,14 @@ class EventableDescriptor: public Bindable_t
|
|
69
69
|
virtual bool GetSubprocessPid (pid_t*) {return false;}
|
70
70
|
|
71
71
|
virtual void StartTls() {}
|
72
|
-
virtual void SetTlsParms (const char *, const char *, bool) {}
|
72
|
+
virtual void SetTlsParms (const char *, const char *, bool, bool, const char *, const char *, const char *, const char *, int) {}
|
73
73
|
|
74
74
|
#ifdef WITH_SSL
|
75
75
|
virtual X509 *GetPeerCert() {return NULL;}
|
76
|
+
virtual int GetCipherBits() {return -1;}
|
77
|
+
virtual const char *GetCipherName() {return NULL;}
|
78
|
+
virtual const char *GetCipherProtocol() {return NULL;}
|
79
|
+
virtual const char *GetSNIHostname() {return NULL;}
|
76
80
|
#endif
|
77
81
|
|
78
82
|
virtual uint64_t GetCommInactivityTimeout() {return 0;}
|
@@ -108,7 +112,7 @@ class EventableDescriptor: public Bindable_t
|
|
108
112
|
bool bCloseAfterWriting;
|
109
113
|
|
110
114
|
protected:
|
111
|
-
|
115
|
+
SOCKET MySocket;
|
112
116
|
bool bAttached;
|
113
117
|
bool bWatchOnly;
|
114
118
|
|
@@ -151,7 +155,7 @@ class LoopbreakDescriptor
|
|
151
155
|
class LoopbreakDescriptor: public EventableDescriptor
|
152
156
|
{
|
153
157
|
public:
|
154
|
-
LoopbreakDescriptor (
|
158
|
+
LoopbreakDescriptor (SOCKET, EventMachine_t*);
|
155
159
|
virtual ~LoopbreakDescriptor() {}
|
156
160
|
|
157
161
|
virtual void Read();
|
@@ -170,7 +174,7 @@ class ConnectionDescriptor
|
|
170
174
|
class ConnectionDescriptor: public EventableDescriptor
|
171
175
|
{
|
172
176
|
public:
|
173
|
-
ConnectionDescriptor (
|
177
|
+
ConnectionDescriptor (SOCKET, EventMachine_t*);
|
174
178
|
virtual ~ConnectionDescriptor();
|
175
179
|
|
176
180
|
int SendOutboundData (const char*, unsigned long);
|
@@ -201,10 +205,14 @@ class ConnectionDescriptor: public EventableDescriptor
|
|
201
205
|
virtual int GetOutboundDataSize() {return OutboundDataSize;}
|
202
206
|
|
203
207
|
virtual void StartTls();
|
204
|
-
virtual void SetTlsParms (const char
|
208
|
+
virtual void SetTlsParms (const char *, const char *, bool, bool, const char *, const char *, const char *, const char *, int);
|
205
209
|
|
206
210
|
#ifdef WITH_SSL
|
207
211
|
virtual X509 *GetPeerCert();
|
212
|
+
virtual int GetCipherBits();
|
213
|
+
virtual const char *GetCipherName();
|
214
|
+
virtual const char *GetCipherProtocol();
|
215
|
+
virtual const char *GetSNIHostname();
|
208
216
|
virtual bool VerifySslPeer(const char*);
|
209
217
|
virtual void AcceptSslPeer();
|
210
218
|
#endif
|
@@ -245,8 +253,14 @@ class ConnectionDescriptor: public EventableDescriptor
|
|
245
253
|
SslBox_t *SslBox;
|
246
254
|
std::string CertChainFilename;
|
247
255
|
std::string PrivateKeyFilename;
|
256
|
+
std::string CipherList;
|
257
|
+
std::string EcdhCurve;
|
258
|
+
std::string DhParam;
|
259
|
+
int Protocols;
|
248
260
|
bool bHandshakeSignaled;
|
249
261
|
bool bSslVerifyPeer;
|
262
|
+
bool bSslFailIfNoPeerCert;
|
263
|
+
std::string SniHostName;
|
250
264
|
bool bSslPeerAccepted;
|
251
265
|
#endif
|
252
266
|
|
@@ -275,7 +289,7 @@ class DatagramDescriptor
|
|
275
289
|
class DatagramDescriptor: public EventableDescriptor
|
276
290
|
{
|
277
291
|
public:
|
278
|
-
DatagramDescriptor (
|
292
|
+
DatagramDescriptor (SOCKET, EventMachine_t*);
|
279
293
|
virtual ~DatagramDescriptor();
|
280
294
|
|
281
295
|
virtual void Read();
|
@@ -299,18 +313,18 @@ class DatagramDescriptor: public EventableDescriptor
|
|
299
313
|
|
300
314
|
protected:
|
301
315
|
struct OutboundPage {
|
302
|
-
OutboundPage (const char *b, int l, struct
|
316
|
+
OutboundPage (const char *b, int l, struct sockaddr_in6 f, int o=0): Buffer(b), Length(l), Offset(o), From(f) {}
|
303
317
|
void Free() {if (Buffer) free (const_cast<char*>(Buffer)); }
|
304
318
|
const char *Buffer;
|
305
319
|
int Length;
|
306
320
|
int Offset;
|
307
|
-
struct
|
321
|
+
struct sockaddr_in6 From;
|
308
322
|
};
|
309
323
|
|
310
324
|
deque<OutboundPage> OutboundPages;
|
311
325
|
int OutboundDataSize;
|
312
326
|
|
313
|
-
struct
|
327
|
+
struct sockaddr_in6 ReturnAddress;
|
314
328
|
};
|
315
329
|
|
316
330
|
|
@@ -321,7 +335,7 @@ class AcceptorDescriptor
|
|
321
335
|
class AcceptorDescriptor: public EventableDescriptor
|
322
336
|
{
|
323
337
|
public:
|
324
|
-
AcceptorDescriptor (
|
338
|
+
AcceptorDescriptor (SOCKET, EventMachine_t*);
|
325
339
|
virtual ~AcceptorDescriptor();
|
326
340
|
|
327
341
|
virtual void Read();
|
@@ -344,7 +358,7 @@ class PipeDescriptor
|
|
344
358
|
class PipeDescriptor: public EventableDescriptor
|
345
359
|
{
|
346
360
|
public:
|
347
|
-
PipeDescriptor (
|
361
|
+
PipeDescriptor (SOCKET, pid_t, EventMachine_t*);
|
348
362
|
virtual ~PipeDescriptor();
|
349
363
|
|
350
364
|
virtual void Read();
|