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