@@ 89-117 (lines=29) @@ | ||
86 | * {@inheritdoc} |
|
87 | * @see \Generics\Streams\Stream::ready() |
|
88 | */ |
|
89 | public function ready(): bool |
|
90 | { |
|
91 | if (! is_resource($this->handle)) { |
|
92 | return false; |
|
93 | } |
|
94 | ||
95 | $read = array( |
|
96 | $this->handle |
|
97 | ); |
|
98 | $write = null; |
|
99 | $except = null; |
|
100 | ||
101 | $num = @socket_select($read, $write, $except, 0); |
|
102 | ||
103 | if ($num === false) { |
|
104 | $code = socket_last_error($this->handle); |
|
105 | throw new SocketException(socket_strerror($code), array(), $code); |
|
106 | } |
|
107 | ||
108 | if ($num < 1) { |
|
109 | return false; |
|
110 | } |
|
111 | ||
112 | if (! in_array($this->handle, $read)) { |
|
113 | return false; |
|
114 | } |
|
115 | ||
116 | return true; |
|
117 | } |
|
118 | ||
119 | /** |
|
120 | * |
|
@@ 124-152 (lines=29) @@ | ||
121 | * {@inheritdoc} |
|
122 | * @see \Generics\Streams\OutputStream::isWriteable() |
|
123 | */ |
|
124 | public function isWriteable(): bool |
|
125 | { |
|
126 | if (! is_resource($this->handle)) { |
|
127 | return false; |
|
128 | } |
|
129 | ||
130 | $read = null; |
|
131 | $write = array( |
|
132 | $this->handle |
|
133 | ); |
|
134 | $except = null; |
|
135 | ||
136 | $num = @socket_select($read, $write, $except, 0, 0); |
|
137 | ||
138 | if ($num === false) { |
|
139 | $code = socket_last_error($this->handle); |
|
140 | throw new SocketException(socket_strerror($code), array(), $code); |
|
141 | } |
|
142 | ||
143 | if ($num < 1) { |
|
144 | return false; |
|
145 | } |
|
146 | ||
147 | if (! in_array($this->handle, $write)) { |
|
148 | return false; |
|
149 | } |
|
150 | ||
151 | return true; |
|
152 | } |
|
153 | ||
154 | /** |
|
155 | * |