@@ -158,13 +158,12 @@ public function __construct($remote_address, $context_option = null)
158
158
self ::$ statistics ['connection_count ' ]++;
159
159
$ this ->maxSendBufferSize = self ::$ defaultMaxSendBufferSize ;
160
160
$ this ->_contextOption = $ context_option ;
161
- static ::$ connections [$ this ->id ] = $ this ;
162
161
}
163
162
164
163
/**
165
164
* Do connect.
166
165
*
167
- * @return void
166
+ * @return void
168
167
*/
169
168
public function connect ()
170
169
{
@@ -199,7 +198,7 @@ public function connect()
199
198
}
200
199
return ;
201
200
}
202
- // Add socket to global event loop waiting connection is successfully established or faild.
201
+ // Add socket to global event loop waiting connection is successfully established or faild.
203
202
Worker::$ globalEvent ->add ($ this ->_socket , EventInterface::EV_WRITE , array ($ this , 'checkConnection ' ));
204
203
// For windows.
205
204
if (DIRECTORY_SEPARATOR === '\\' ) {
@@ -228,7 +227,7 @@ public function reConnect($after = 0) {
228
227
/**
229
228
* Get remote address.
230
229
*
231
- * @return string
230
+ * @return string
232
231
*/
233
232
public function getRemoteHost ()
234
233
{
@@ -276,14 +275,8 @@ protected function emitError($code, $msg)
276
275
*/
277
276
public function checkConnection ($ socket )
278
277
{
279
- // Remove EV_EXPECT for windows.
280
- if (DIRECTORY_SEPARATOR === '\\' ) {
281
- Worker::$ globalEvent ->del ($ socket , EventInterface::EV_EXCEPT );
282
- }
283
278
// Check socket state.
284
279
if ($ address = stream_socket_get_name ($ socket , true )) {
285
- // Remove write listener.
286
- Worker::$ globalEvent ->del ($ socket , EventInterface::EV_WRITE );
287
280
// Nonblocking.
288
281
stream_set_blocking ($ socket , 0 );
289
282
// Compatible with hhvm
@@ -298,14 +291,24 @@ public function checkConnection($socket)
298
291
}
299
292
300
293
// SSL handshake.
301
- if ($ this ->transport === 'ssl ' && $ this ->doSslHandshake ($ socket )) {
302
- $ this ->_sslHandshakeCompleted = true ;
294
+ if ($ this ->transport === 'ssl ' ) {
295
+ $ this ->_sslHandshakeCompleted = $ this ->doSslHandshake ($ socket );
296
+ if (!$ this ->_sslHandshakeCompleted ){
297
+ return ;
298
+ }
299
+ }
300
+
301
+ // Remove EV_EXPECT for windows.
302
+ if (DIRECTORY_SEPARATOR === '\\' ) {
303
+ Worker::$ globalEvent ->del ($ socket , EventInterface::EV_EXCEPT );
303
304
}
305
+ // Remove write listener.
306
+ Worker::$ globalEvent ->del ($ socket , EventInterface::EV_WRITE );
304
307
305
308
// Register a listener waiting read event.
306
309
Worker::$ globalEvent ->add ($ socket , EventInterface::EV_READ , array ($ this , 'baseRead ' ));
307
310
// There are some data waiting to send.
308
- if ($ this ->_sendBuffer && $ this -> transport !== ' ssl ' ) {
311
+ if ($ this ->_sendBuffer ) {
309
312
Worker::$ globalEvent ->add ($ socket , EventInterface::EV_WRITE , array ($ this , 'baseWrite ' ));
310
313
}
311
314
$ this ->_status = self ::STATUS_ESTABLISHED ;
@@ -335,6 +338,7 @@ public function checkConnection($socket)
335
338
exit (250 );
336
339
}
337
340
}
341
+ static ::$ connections [$ this ->id ] = $ this ;
338
342
} else {
339
343
// Connection failed.
340
344
$ this ->emitError (WORKERMAN_CONNECT_FAIL , 'connect ' . $ this ->_remoteAddress . ' fail after ' . round (microtime (true ) - $ this ->_connectStartTime , 4 ) . ' seconds ' );
@@ -382,9 +386,6 @@ public function doSslHandshake($socket){
382
386
exit (250 );
383
387
}
384
388
}
385
- if ($ this ->_sendBuffer ) {
386
- Worker::$ globalEvent ->add ($ socket , EventInterface::EV_WRITE , array ($ this , 'baseWrite ' ));
387
- }
388
389
return true ;
389
390
}
390
391
}
0 commit comments