| 1 | package SPVM::UV::Request::Write; | ||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | 1; | ||
| 6 | |||
| 7 | =encoding utf8 | ||
| 8 | |||
| 9 | =head1 Name | ||
| 10 | |||
| 11 | SPVM::UV::Request::Write - Write Request for libuv | ||
| 12 | |||
| 13 | =head1 Description | ||
| 14 | |||
| 15 | C<UV::Request::Write> in L<SPVM> represents the write request for L<libuv|https://libuv.org/>, corresponding to the C<uv_write_t> structure. | ||
| 16 | |||
| 17 | =head1 Usage | ||
| 18 | |||
| 19 | use UV::Request::Write; | ||
| 20 | |||
| 21 | my $req_write = UV::Request::Write->new; | ||
| 22 | |||
| 23 | =head1 Super Class | ||
| 24 | |||
| 25 | L<UV::Request|SPVM::UV::Request>. | ||
| 26 | |||
| 27 | =head1 Fields | ||
| 28 | |||
| 29 | =head2 write_cb | ||
| 30 | |||
| 31 | C<has write_cb : rw L<UV::Callback::Write|SPVM::UV::Callback::Write>;> | ||
| 32 | |||
| 33 | The callback called when the write request has completed. | ||
| 34 | |||
| 35 | =head2 write_buffer | ||
| 36 | |||
| 37 | C<has write_buffer : rw string;> | ||
| 38 | |||
| 39 | The buffer associated with the write request. | ||
| 40 | |||
| 41 | =head1 Class Methods | ||
| 42 | |||
| 43 | =head2 new | ||
| 44 | |||
| 45 | C<static method new : L<UV::Request::Write|SPVM::UV::Request::Write> ();> | ||
| 46 | |||
| 47 | Creates a new L<UV::Request::Write|SPVM::UV::Request::Write> object, and returns it. | ||
| 48 | |||
| 49 | =head1 Instance Methods | ||
| 50 | |||
| 51 | =head2 write | ||
| 52 | |||
| 53 | C<method write : void ($uv_stream : L<UV::Handle::Stream|SPVM::UV::Handle::Stream>, $buffer : string, $buffer_length : int, $cb : L<UV::Callback::Write|SPVM::UV::Callback::Write>, $buffer_offset : int = 0);> | ||
| 54 | |||
| 55 | Writes data from $buffer with length $buffer_length and offset $buffer_offset to the stream $uv_stream. | ||
| 56 | |||
| 57 | The callback $cb is stored in L</"write_cb"> field. The buffer $buffer is stored in L</"write_buffer"> field. | ||
| 58 | |||
| 59 | The callback $cb is invoked when the write operation completes. | ||
| 60 | |||
| 61 | Exceptions: | ||
| 62 | |||
| 63 | If $uv_stream is not defined, an exception is thrown. | ||
| 64 | |||
| 65 | If $buffer is not defined, an exception is thrown. | ||
| 66 | |||
| 67 | If $buffer_length is not a positive number, an exception is thrown. | ||
| 68 | |||
| 69 | If $buffer_offset + $buffer_length is greater than the length of $buffer, an exception is thrown. | ||
| 70 | |||
| 71 | If $cb is not defined, an exception is thrown. | ||
| 72 | |||
| 73 | If uv_write fails, an exception is thrown. | ||
| 74 | |||
| 75 | =head1 Copyright & License | ||
| 76 | |||
| 77 | Copyright (c) 2026 Yuki Kimoto | ||
| 78 | |||
| 79 | MIT License |