File tree 2 files changed +21
-7
lines changed
2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -139,7 +139,7 @@ public function connect()
139
139
140
140
$ options = stream_context_get_options ($ context );
141
141
if (isset ($ options ['ssl ' ]['crypto_method ' ])) {
142
- $ this ->enable_crypto ();
142
+ $ this ->enableCrypto ();
143
143
}
144
144
145
145
$ this ->heartbeat = $ this ->initial_heartbeat ;
@@ -432,16 +432,31 @@ protected function extract_error_code($message)
432
432
return 0 ;
433
433
}
434
434
435
- private function enable_crypto (): void
435
+ /**
436
+ * @throws AMQPIOException
437
+ */
438
+ private function enableCrypto (): void
436
439
{
437
440
$ timeout_at = time () + ($ this ->read_timeout + $ this ->write_timeout ) * 2 ; // 2 round-trips during handshake
438
441
439
- do {
440
- $ enabled = stream_socket_enable_crypto ($ this ->sock , true );
441
- } while ($ enabled !== true && time () < $ timeout_at );
442
+ try {
443
+ $ this ->setErrorHandler ();
444
+ do {
445
+ $ enabled = stream_socket_enable_crypto ($ this ->sock , true );
446
+ if ($ enabled === true ) {
447
+ return ;
448
+ }
449
+ $ this ->throwOnError ();
450
+ usleep (1e3 );
451
+ } while ($ enabled === 0 && time () < $ timeout_at );
452
+ } catch (\ErrorException $ exception ) {
453
+ throw new AMQPIOException ($ exception ->getMessage (), $ exception ->getCode (), $ exception );
454
+ } finally {
455
+ $ this ->restoreErrorHandler ();
456
+ }
442
457
443
458
if ($ enabled !== true ) {
444
- throw new AMQPIOException ('Can not enable crypto ' );
459
+ throw new AMQPIOException ('Could not enable socket crypto ' );
445
460
}
446
461
}
447
462
}
Original file line number Diff line number Diff line change @@ -50,7 +50,6 @@ public function external_auth_with_user_credentials()
50
50
public function secure_with_incorrect_crypto_method ()
51
51
{
52
52
$ this ->expectException (AMQPIOException::class);
53
- $ this ->expectExceptionMessage ('Can not enable crypto ' );
54
53
55
54
$ cert_dir = realpath (__DIR__ . "/../../certs " );
56
55
$ config = new AMQPConnectionConfig ();
You can’t perform that action at this time.
0 commit comments