@@ -33,7 +33,7 @@ class Worker
33
33
*
34
34
* @var string
35
35
*/
36
- const VERSION = '3.5.21 ' ;
36
+ const VERSION = '3.5.22 ' ;
37
37
38
38
/**
39
39
* Status starting.
@@ -2166,6 +2166,7 @@ public function __construct($socket_name = '', $context_option = array())
2166
2166
// Context for socket.
2167
2167
if ($ socket_name ) {
2168
2168
$ this ->_socketName = $ socket_name ;
2169
+ $ this ->parseSocketAddress ();
2169
2170
if (!isset ($ context_option ['socket ' ]['backlog ' ])) {
2170
2171
$ context_option ['socket ' ]['backlog ' ] = static ::DEFAULT_BACKLOG ;
2171
2172
}
@@ -2189,27 +2190,8 @@ public function listen()
2189
2190
Autoloader::setRootPath ($ this ->_autoloadRootPath );
2190
2191
2191
2192
if (!$ this ->_mainSocket ) {
2192
- // Get the application layer communication protocol and listening address.
2193
- list ($ scheme , $ address ) = \explode (': ' , $ this ->_socketName , 2 );
2194
- // Check application layer protocol class.
2195
- if (!isset (static ::$ _builtinTransports [$ scheme ])) {
2196
- $ scheme = \ucfirst ($ scheme );
2197
- $ this ->protocol = \substr ($ scheme ,0 ,1 )==='\\' ? $ scheme : '\\Protocols \\' . $ scheme ;
2198
- if (!\class_exists ($ this ->protocol )) {
2199
- $ this ->protocol = "\\Workerman \\Protocols \\$ scheme " ;
2200
- if (!\class_exists ($ this ->protocol )) {
2201
- throw new Exception ("class \\Protocols \\$ scheme not exist " );
2202
- }
2203
- }
2204
-
2205
- if (!isset (static ::$ _builtinTransports [$ this ->transport ])) {
2206
- throw new \Exception ('Bad worker->transport ' . \var_export ($ this ->transport , true ));
2207
- }
2208
- } else {
2209
- $ this ->transport = $ scheme ;
2210
- }
2211
2193
2212
- $ local_socket = static :: $ _builtinTransports [ $ this ->transport ] . " : " . $ address ;
2194
+ $ local_socket = $ this ->parseSocketAddress () ;
2213
2195
2214
2196
// Flag.
2215
2197
$ flags = $ this ->transport === 'udp ' ? STREAM_SERVER_BIND : STREAM_SERVER_BIND | STREAM_SERVER_LISTEN ;
@@ -2229,12 +2211,12 @@ public function listen()
2229
2211
if ($ this ->transport === 'ssl ' ) {
2230
2212
\stream_socket_enable_crypto ($ this ->_mainSocket , false );
2231
2213
} elseif ($ this ->transport === 'unix ' ) {
2232
- $ socketFile = \substr ($ address , 2 );
2214
+ $ socket_file = \substr ($ local_socket , 7 );
2233
2215
if ($ this ->user ) {
2234
- chown ($ socketFile , $ this ->user );
2216
+ chown ($ socket_file , $ this ->user );
2235
2217
}
2236
2218
if ($ this ->group ) {
2237
- chgrp ($ socketFile , $ this ->group );
2219
+ chgrp ($ socket_file , $ this ->group );
2238
2220
}
2239
2221
}
2240
2222
@@ -2269,6 +2251,39 @@ public function unlisten() {
2269
2251
}
2270
2252
}
2271
2253
2254
+ /**
2255
+ * Parse local socket address.
2256
+ *
2257
+ * @throws Exception
2258
+ */
2259
+ protected function parseSocketAddress () {
2260
+ if (!$ this ->_socketName ) {
2261
+ return ;
2262
+ }
2263
+ // Get the application layer communication protocol and listening address.
2264
+ list ($ scheme , $ address ) = \explode (': ' , $ this ->_socketName , 2 );
2265
+ // Check application layer protocol class.
2266
+ if (!isset (static ::$ _builtinTransports [$ scheme ])) {
2267
+ $ scheme = \ucfirst ($ scheme );
2268
+ $ this ->protocol = \substr ($ scheme ,0 ,1 )==='\\' ? $ scheme : '\\Protocols \\' . $ scheme ;
2269
+ if (!\class_exists ($ this ->protocol )) {
2270
+ $ this ->protocol = "\\Workerman \\Protocols \\$ scheme " ;
2271
+ if (!\class_exists ($ this ->protocol )) {
2272
+ throw new Exception ("class \\Protocols \\$ scheme not exist " );
2273
+ }
2274
+ }
2275
+
2276
+ if (!isset (static ::$ _builtinTransports [$ this ->transport ])) {
2277
+ throw new \Exception ('Bad worker->transport ' . \var_export ($ this ->transport , true ));
2278
+ }
2279
+ } else {
2280
+ $ this ->transport = $ scheme ;
2281
+ }
2282
+
2283
+ $ local_socket = static ::$ _builtinTransports [$ this ->transport ] . ": " . $ address ;
2284
+ return $ local_socket ;
2285
+ }
2286
+
2272
2287
/**
2273
2288
* Pause accept new connections.
2274
2289
*
0 commit comments