Code Duplication    Length = 4-5 lines in 4 locations

PHPDaemon/BoundSocket/TCP.php 1 location

@@ 65-69 (lines=5) @@
62
            return true;
63
        }
64
        $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
65
        if (!$sock) {
66
            $errno = socket_last_error();
67
            Daemon::$process->log(get_class($this->pool) . ': Couldn\'t create TCP-socket (' . $errno . ' - ' . socket_strerror($errno) . ').');
68
            return false;
69
        }
70
        if ($this->reuse) {
71
            if (!socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, 1)) {
72
                $errno = socket_last_error();

PHPDaemon/BoundSocket/UNIX.php 2 locations

@@ 79-83 (lines=5) @@
76
            return true;
77
        }
78
        $sock = socket_create(AF_UNIX, SOCK_STREAM, 0);
79
        if (!$sock) {
80
            $errno = socket_last_error();
81
            Daemon::$process->log(get_class($this) . ': Couldn\'t create UNIX-socket (' . $errno . ' - ' . socket_strerror($errno) . ').');
82
            return false;
83
        }
84
85
        // SO_REUSEADDR is meaningless in AF_UNIX context
86
        if (!@socket_bind($sock, $this->path)) {
@@ 96-99 (lines=4) @@
93
        }
94
        socket_set_nonblock($sock);
95
        $this->onBound();
96
        if (!socket_listen($sock, SOMAXCONN)) {
97
            $errno = socket_last_error();
98
            Daemon::$process->log(get_class($this) . ': Couldn\'t listen UNIX-socket \'' . $this->path . '\' (' . $errno . ' - ' . socket_strerror($errno) . ')');
99
        }
100
        $this->setFd($sock);
101
        return true;
102
    }

PHPDaemon/BoundSocket/UDP.php 1 location

@@ 104-108 (lines=5) @@
101
    public function bindSocket()
102
    {
103
        $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
104
        if (!$sock) {
105
            $errno = socket_last_error();
106
            Daemon::$process->log(get_class($this) . ': Couldn\'t create UDP-socket (' . $errno . ' - ' . socket_strerror($errno) . ').');
107
            return false;
108
        }
109
        if (!isset($this->port)) {
110
            if (isset($this->defaultPort)) {
111
                $this->port = $this->defaultPort;