Skip to content

Commit 488f108

Browse files
authored
fix issue #445
fix issue #455
1 parent c528197 commit 488f108

File tree

1 file changed

+39
-24
lines changed

1 file changed

+39
-24
lines changed

Worker.php

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Worker
3333
*
3434
* @var string
3535
*/
36-
const VERSION = '3.5.21';
36+
const VERSION = '3.5.22';
3737

3838
/**
3939
* Status starting.
@@ -2166,6 +2166,7 @@ public function __construct($socket_name = '', $context_option = array())
21662166
// Context for socket.
21672167
if ($socket_name) {
21682168
$this->_socketName = $socket_name;
2169+
$this->parseSocketAddress();
21692170
if (!isset($context_option['socket']['backlog'])) {
21702171
$context_option['socket']['backlog'] = static::DEFAULT_BACKLOG;
21712172
}
@@ -2189,27 +2190,8 @@ public function listen()
21892190
Autoloader::setRootPath($this->_autoloadRootPath);
21902191

21912192
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-
}
22112193

2212-
$local_socket = static::$_builtinTransports[$this->transport] . ":" . $address;
2194+
$local_socket = $this->parseSocketAddress();
22132195

22142196
// Flag.
22152197
$flags = $this->transport === 'udp' ? STREAM_SERVER_BIND : STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;
@@ -2229,12 +2211,12 @@ public function listen()
22292211
if ($this->transport === 'ssl') {
22302212
\stream_socket_enable_crypto($this->_mainSocket, false);
22312213
} elseif ($this->transport === 'unix') {
2232-
$socketFile = \substr($address, 2);
2214+
$socket_file = \substr($local_socket, 7);
22332215
if ($this->user) {
2234-
chown($socketFile, $this->user);
2216+
chown($socket_file, $this->user);
22352217
}
22362218
if ($this->group) {
2237-
chgrp($socketFile, $this->group);
2219+
chgrp($socket_file, $this->group);
22382220
}
22392221
}
22402222

@@ -2269,6 +2251,39 @@ public function unlisten() {
22692251
}
22702252
}
22712253

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+
22722287
/**
22732288
* Pause accept new connections.
22742289
*

0 commit comments

Comments
 (0)