@@ -55,6 +55,7 @@ class Mrloop
5555 callable $callback,
5656 ): void
5757 public tcpServer(int $port, callable $callback): void
58+ public writev(int $fd, string $message): void
5859 public static parseHttpRequest(string $request, int $headerlimit = 100): iterable
5960 public static parseHttpResponse(string $response, int $headerlimit = 100): iterable
6061 public addTimer(float $interval, callable $callback): void
@@ -69,6 +70,7 @@ class Mrloop
6970- [ ` Mrloop::addReadStream ` ] ( #mrloopaddreadstream )
7071- [ ` Mrloop::addWriteStream ` ] ( #mrloopaddwritestream )
7172- [ ` Mrloop::tcpServer ` ] ( #mrlooptcpserver )
73+ - [ ` Mrloop::writev ` ] ( #mrloopwritev )
7274- [ ` Mrloop::parseHttpRequest ` ] ( #mrloopparsehttprequest )
7375- [ ` Mrloop::parseHttpResponse ` ] ( #mrloopparsehttpresponse )
7476- [ ` Mrloop::addTimer ` ] ( #mrloopaddtimer )
@@ -242,6 +244,7 @@ Instantiates a simple TCP server.
242244 - ** client** (iterable) - An array containing client socket information.
243245 - ** client_addr** (string) - The client IP address.
244246 - ** client_port** (integer) - The client socket port.
247+ - ** client_fd** (integer) - The client socket file descriptor.
245248
246249** Return value(s)**
247250
@@ -282,6 +285,60 @@ The example above will produce output similar to that in the snippet to follow.
282285
283286```
284287
288+ ### ` Mrloop::writev `
289+
290+ ``` php
291+ public Mrloop::writev(int $fd, string $contents): void
292+ ```
293+
294+ Performs vectorized non-blocking write operation on a specified file descriptor.
295+
296+ ** Parameter(s)**
297+
298+ - ** fd** (integer) - The file descriptor to write to.
299+ - ** contents** (string) - The arbitrary contents to write.
300+
301+ ** Return value(s)**
302+
303+ The parser will throw an exception in the event that an invalid file descriptor is encountered and will not return anything otherwise.
304+
305+ ``` php
306+ use ringphp\Mrloop;
307+
308+ $loop = Mrloop::init();
309+
310+ $loop->tcpServer(
311+ 8080,
312+ function (string $message, iterable $client) use ($loop) {
313+ [
314+ 'client_addr' => $addr,
315+ 'client_port' => $port,
316+ 'client_fd' => $fd,
317+ ] = $client;
318+
319+ $loop->writev(
320+ $fd,
321+ \sprintf(
322+ "Hello, %s:%d\r\n",
323+ $addr,
324+ $port,
325+ ),
326+ );
327+ },
328+ );
329+
330+ echo "Listening on port 8080\n";
331+
332+ $loop->run();
333+ ```
334+
335+ The example above will produce output similar to that in the snippet to follow.
336+
337+ ```
338+ Listening on port 8080
339+
340+ ```
341+
285342### ` Mrloop::parseHttpRequest `
286343
287344``` php
0 commit comments