| 1 | # |
| 2 | # Module Generated by Template::Tiny on Fri Aug 4 11:16:27 UTC 2023 |
| 3 | # |
| 4 | |
| 5 | package ZMQ::FFI::ZMQ4::Contextscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/; |
| 6 | $ZMQ::FFI::ZMQ4::Context::VERSIONscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/$VERSION. = '1.19'; |
| 7 | use FFI::Platypusscip-perl cpan ZMQ-FFI 1.19 FFI/Platypus/; |
| 8 | use ZMQ::FFI::Utilscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/Util/ qw(zmq_soname current_tid); |
| 9 | use ZMQ::FFI::Constantsscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/Constants/ qw(:all); |
| 10 | use ZMQ::FFI::ZMQ4::Socketscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Socket/; |
| 11 | use ZMQ::FFI::ZMQ4::Rawscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Raw/; |
| 12 | use ZMQ::FFI::Custom::Rawscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/Custom/Raw/; |
| 13 | use Try::Tinyscip-perl cpan ZMQ-FFI 1.19 Try/Tiny/; |
| 14 | use Scalar::Utilscip-perl cpan ZMQ-FFI 1.19 Scalar/Util/ qw(weaken); |
| 15 | |
| 16 | use FFI::Platypus::Memoryscip-perl cpan ZMQ-FFI 1.19 FFI/Platypus/Memory/ qw(free malloc); |
| 17 | use FFI::Platypus::Bufferscip-perl cpan ZMQ-FFI 1.19 FFI/Platypus/Buffer/ qw(buffer_to_scalar); |
| 18 | |
| 19 | use Mooscip-perl cpan ZMQ-FFI 1.19 Moo/; |
| 20 | use namespace::cleanscip-perl cpan ZMQ-FFI 1.19 namespace/clean/; |
| 21 | |
| 22 | with qw( |
| 23 | ZMQ::FFI::ContextRole |
| 24 | ZMQ::FFI::ErrorHelper |
| 25 | ZMQ::FFI::Versioner |
| 26 | ); |
| 27 | |
| 28 | my $FFI_LOADED; |
| 29 | |
| 30 | sub BUILDscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/BUILD(). { |
| 31 | my ($self) = @_scip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/`@_`.; |
| 32 | |
| 33 | unless ($FFI_LOADED) { |
| 34 | ZMQ::FFI::Custom::Raw::loadscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/Custom/Raw/load().($self->sonamescip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/soname().); |
| 35 | ZMQ::FFI::ZMQ4::Raw::loadscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Raw/load().($self->sonamescip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/soname().); |
| 36 | $FFI_LOADED = 1; |
| 37 | } |
| 38 | |
| 39 | $self->initscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/init().() |
| 40 | } |
| 41 | |
| 42 | |
| 43 | sub initscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/init(). { |
| 44 | my ($self) = @_scip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/`@_`.; |
| 45 | |
| 46 | try { |
| 47 | $self->context_ptrscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/context_ptr().( zmq_ctx_newscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/zmq_ctx_new().() ); |
| 48 | $self->check_nullscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/check_null().('zmq_ctx_new', $self->context_ptrscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/context_ptr().); |
| 49 | } |
| 50 | catch { |
| 51 | $self->context_ptrscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/context_ptr().(-1); |
| 52 | diescip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/die(). $_scip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/$_.; |
| 53 | }; |
| 54 | |
| 55 | if ( $self->has_threadsscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/has_threads(). ) { |
| 56 | $self->setscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/set().(ZMQ_IO_THREADS, $self->threadsscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/threads().); |
| 57 | } |
| 58 | |
| 59 | if ( $self->has_max_socketsscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/has_max_sockets(). ) { |
| 60 | $self->setscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/set().(ZMQ_MAX_SOCKETS, $self->max_socketsscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/max_sockets().); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | sub getscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/get(). { |
| 65 | my ($self, $option) = @_scip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/`@_`.; |
| 66 | |
| 67 | my $option_val = zmq_ctx_getscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/zmq_ctx_get().($self->context_ptrscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/context_ptr()., $option); |
| 68 | $self->check_errorscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/check_error().('zmq_ctx_get', $option_val); |
| 69 | |
| 70 | return $option_val; |
| 71 | } |
| 72 | |
| 73 | sub setscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/set(). { |
| 74 | my ($self, $option, $option_val) = @_scip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/`@_`.; |
| 75 | |
| 76 | $self->check_errorscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/check_error().( |
| 77 | 'zmq_ctx_set', |
| 78 | zmq_ctx_setscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/zmq_ctx_set().($self->context_ptrscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/context_ptr()., $option, $option_val) |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | sub socketscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/socket(). { |
| 83 | my ($self, $type) = @_scip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/`@_`.; |
| 84 | |
| 85 | my $socket; |
| 86 | |
| 87 | try { |
| 88 | my $socket_ptr = zmq_socketscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/zmq_socket().($self->context_ptrscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/context_ptr()., $type); |
| 89 | |
| 90 | $self->check_nullscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/check_null().('zmq_socket', $socket_ptr); |
| 91 | |
| 92 | $socket = ZMQ::FFI::ZMQ4::Socket->newscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Socket/new().( |
| 93 | socket_ptr => $socket_ptr, |
| 94 | context => $self, # this will become a weak ref |
| 95 | type => $type, |
| 96 | soname => $self->sonamescip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/soname()., |
| 97 | ); |
| 98 | } |
| 99 | catch { |
| 100 | diescip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/die(). $_scip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/$_.; |
| 101 | }; |
| 102 | |
| 103 | # add the socket to the socket hash |
| 104 | $self->_add_socketscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/_add_socket().($socket); |
| 105 | |
| 106 | return $socket; |
| 107 | } |
| 108 | |
| 109 | sub proxyscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/proxy(). { |
| 110 | my ($self, $frontend, $backend, $capture) = @_scip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/`@_`.; |
| 111 | |
| 112 | $self->check_errorscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/check_error().( |
| 113 | 'zmq_proxy', |
| 114 | zmq_proxyscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/zmq_proxy().( |
| 115 | $frontend->socket_ptrscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/socket_ptr()., |
| 116 | $backend->socket_ptrscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/socket_ptr()., |
| 117 | definedscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/defined(). $capture ? $capture->socket_ptrscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/socket_ptr(). : undef, |
| 118 | ) |
| 119 | ); |
| 120 | } |
| 121 | |
| 122 | sub devicescip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/device(). { |
| 123 | my ($self, $type, $frontend, $backend) = @_scip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/`@_`.; |
| 124 | |
| 125 | $self->bad_versionscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/bad_version().( |
| 126 | $self->verstrscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/verstr()., |
| 127 | "zmq_device not available in zmq >= 3.x", |
| 128 | ); |
| 129 | } |
| 130 | |
| 131 | sub destroyscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/destroy(). { |
| 132 | my ($self) = @_scip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/`@_`.; |
| 133 | |
| 134 | return if $self->context_ptrscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/context_ptr(). == -1; |
| 135 | |
| 136 | # don't try to cleanup context cloned from another thread |
| 137 | return unless $self->_tidscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/_tid(). == current_tidscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/Util/current_tid().(); |
| 138 | |
| 139 | # don't try to cleanup context copied from another process (fork) |
| 140 | return unless $self->_pidscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/_pid(). == $$scip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/$$.; |
| 141 | |
| 142 | $self->check_errorscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/check_error().( |
| 143 | 'zmq_ctx_term', |
| 144 | zmq_ctx_termscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/zmq_ctx_term().($self->context_ptrscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/context_ptr().) |
| 145 | ); |
| 146 | |
| 147 | $self->context_ptrscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/context_ptr().(-1); |
| 148 | } |
| 149 | |
| 150 | sub curve_keypairscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/curve_keypair(). { |
| 151 | my ($self) = @_scip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/`@_`.; |
| 152 | |
| 153 | my $public_key_buf = mallocscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/malloc().(41); |
| 154 | my $secret_key_buf = mallocscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/malloc().(41); |
| 155 | |
| 156 | $self->check_errorscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/check_error().( |
| 157 | 'zmq_curve_keypair', |
| 158 | zmq_curve_keypairscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/zmq_curve_keypair().($public_key_buf, $secret_key_buf) |
| 159 | ); |
| 160 | |
| 161 | my $public_key = buffer_to_scalarscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/buffer_to_scalar().($public_key_buf, 41); |
| 162 | my $secret_key = buffer_to_scalarscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/buffer_to_scalar().($secret_key_buf, 41); |
| 163 | freescip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/free().($public_key_buf); |
| 164 | freescip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/free().($secret_key_buf); |
| 165 | |
| 166 | return ($public_key, $secret_key); |
| 167 | } |
| 168 | |
| 169 | sub z85_encodescip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/z85_encode(). { |
| 170 | my ($self, $data) = @_scip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/`@_`.; |
| 171 | |
| 172 | my $dest_buf = mallocscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/malloc().(41); |
| 173 | |
| 174 | my $checked_data = substrscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/substr().($data, 0, 32); |
| 175 | |
| 176 | $self->check_nullscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/check_null().( |
| 177 | 'zmq_z85_encode', |
| 178 | zmq_z85_encodescip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/zmq_z85_encode().( $dest_buf, $checked_data, lengthscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/length().($checked_data) ) |
| 179 | ); |
| 180 | |
| 181 | my $dest = buffer_to_scalarscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/buffer_to_scalar().($dest_buf, 41); |
| 182 | freescip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/free().($dest_buf); |
| 183 | |
| 184 | return $dest; |
| 185 | } |
| 186 | |
| 187 | sub z85_decodescip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/z85_decode(). { |
| 188 | my ($self, $string) = @_scip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/`@_`.; |
| 189 | |
| 190 | my $dest_buf = mallocscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/malloc().(32); |
| 191 | |
| 192 | $self->check_nullscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/check_null().( |
| 193 | 'zmq_z86_decode', |
| 194 | zmq_z85_decodescip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/zmq_z85_decode().($dest_buf, $string) |
| 195 | ); |
| 196 | |
| 197 | my $dest = buffer_to_scalarscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/buffer_to_scalar().($dest_buf, 32); |
| 198 | freescip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/free().($dest_buf); |
| 199 | |
| 200 | return $dest; |
| 201 | } |
| 202 | |
| 203 | sub has_capabilityscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/has_capability(). { |
| 204 | my ($self) = @_scip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/`@_`.; |
| 205 | $self->bad_versionscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/bad_version().( |
| 206 | $self->verstrscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/verstr()., |
| 207 | "has_capability not available in < zmq 4.1" |
| 208 | ); |
| 209 | } |
| 210 | |
| 211 | |
| 212 | sub _add_socketscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/_add_socket(). { |
| 213 | my ($self, $socket) = @_scip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/`@_`.; |
| 214 | weakenscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/weaken().($self->socketsscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/sockets().->{$socket} = $socket); |
| 215 | } |
| 216 | |
| 217 | sub _remove_socketscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/_remove_socket(). { |
| 218 | my ($self, $socket) = @_scip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/`@_`.; |
| 219 | deletescip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/delete().($self->socketsscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/sockets().->{$socket}); |
| 220 | } |
| 221 | |
| 222 | sub DEMOLISHscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/DEMOLISH(). { |
| 223 | my ($self) = @_scip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/`@_`.; |
| 224 | |
| 225 | return if $self->context_ptrscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/context_ptr(). == -1; |
| 226 | |
| 227 | # check defined to guard against |
| 228 | # undef objects during global destruction |
| 229 | if (definedscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/defined(). $self->socketsscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/sockets().) { |
| 230 | for my $socket_k (keysscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/keys(). %{$self->socketsscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/sockets().}) { |
| 231 | my $socket = $self->_remove_socketscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/_remove_socket().($socket_k); |
| 232 | $socket->closescip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/close().() |
| 233 | if definedscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/defined(). $socket && $socket->socket_ptrscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/socket_ptr(). != -1; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | $self->destroyscip-perl cpan ZMQ-FFI 1.19 ZMQ/FFI/ZMQ4/Context/destroy().(); |
| 238 | } |
| 239 | |
| 240 | 1; |
| 241 | |
| 242 | # vim:ft=perl |
| 243 | |
| 244 | __END__ |
| 245 | |
| 246 | =pod |
| 247 | |
| 248 | =encoding UTF-8 |
| 249 | |
| 250 | =head1 NAME |
| 251 | |
| 252 | ZMQ::FFI::ZMQ4::Context |
| 253 | |
| 254 | =head1 VERSION |
| 255 | |
| 256 | version 1.19 |
| 257 | |
| 258 | =head1 AUTHOR |
| 259 | |
| 260 | Dylan Cali <[email protected]> |
| 261 | |
| 262 | =head1 COPYRIGHT AND LICENSE |
| 263 | |
| 264 | This software is copyright (c) 2023 by Dylan Cali. |
| 265 | |
| 266 | This is free software; you can redistribute it and/or modify it under |
| 267 | the same terms as the Perl 5 programming language system itself. |
| 268 | |
| 269 | =cut |