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