📄 ipc.pm
字号:
Creates a Unix Domain Socket channel object using the provided path.=cutsub new { my ($class, $path) = @_; ref ($class) and croak "class name needed"; my $self = { }; my $h = heartbeat::cl_raw::simple_hash_new(); heartbeat::cl_raw::simple_hash_insert($h, $heartbeat::cl_raw::IPC_PATH_ATTR, $path); $self->{raw} = heartbeat::cl_raw::ipc_channel_constructor( $heartbeat::cl_raw::IPC_DOMAIN_SOCKET,$h); heartbeat::cl_raw::simple_hash_destroy($h); bless $self, $class; return $self; }# Undocumented on purpose, should be called externally, only from the# WaitConnection wrapper!sub new_from_raw { my ($class, $ch) = @_; ref ($class) and croak "class name needed"; $ch =~ /^_p_IPC_Channel/o or croak("Need to supply a raw IPC_Channel reference!"); # By default, we assume we need to clean up after ourselves. my $self = { }; $self->{raw} = $ch; bless $self, $class; return $self;}=item $ch-E<gt>initiate_connection();Initiates the connection to the path given at creation time, and willreturn the corresponding IPC error/success code.=cutsub initiate_connection { my ($self) = @_; ref($self) or croak "Instance variable needed"; UNIVERSAL::isa($self, "heartbeat::clplumbing::ipc::channel") or croak "Wrong object type, not an IPC channel"; return heartbeat::cl_raw::ipc_ch_initiate_connection($self->{raw});}=item $ch-E<gt>verify_auth($auth);Verifies the authentication of the connection vs the supplied IPC_Authobject.Not implemented yet. TODO.=cutsub verify_auth { my ($self, $auth) = @_; ref($self) or croak "Instance variable needed"; UNIVERSAL::isa($self, "heartbeat::clplumbing::ipc::channel") or croak "Wrong object type, not an IPC channel"; UNIVERSAL::isa($auth, "heartbeat::clplumbing::ipc::auth") or croak "Wrong object type, not an IPC Auth"; croak("Not yet implemented.");}=item my ($rc, $msg) = $ch-E<gt>recv();Tries to receive an IPC message from the channel, which is automaticallyreturned as a C<heartbeat::clplumbing::ipc::message> object.Returns a list with the return code from the lower-level recv operationand the message.=cutsub recv { my ($self) = @_; ref($self) or croak "Instance variable needed"; UNIVERSAL::isa($self, "heartbeat::clplumbing::ipc::channel") or croak "Wrong object type, not an IPC channel"; my $msg_with_rc = heartbeat::cl_raw::ipc_ch_recv($self->{raw}); my $msg = heartbeat::clplumbing::ipc::message->new_from_raw( heartbeat::cl_rawc::IPC_MESSAGE_WITH_RC_msg_get($msg_with_rc)); my $rc = heartbeat::cl_rawc::IPC_MESSAGE_WITH_RC_rc_get($msg_with_rc); heartbeat::cl_raw::ipc_ch_msg_with_rc_destroy($msg_with_rc); return ($rc, $msg);}=item my $rc = $ch-E<gt>send($msg);Queues an IPC message for sending on the channel; you need to provide itan C<heartbeat::clplumbing::ipc::message> object.Returns the lower-level status code.=cutsub send { my ($self, $msg) = @_; ref($self) or croak "Instance variable needed"; UNIVERSAL::isa($self, "heartbeat::clplumbing::ipc::channel") or croak "Wrong object type, not an IPC channel"; UNIVERSAL::isa($msg, "heartbeat::clplumbing::ipc::message") or croak "Wrong object type, not an IPC message"; # After the message has been sent, it will be cleaned up. We # MUST NOT do this ourselves - flip the switch inside the IPC # Message object for this. $msg->{cleanup} = 0; return heartbeat::cl_raw::ipc_ch_send($self->{raw}, $msg->{raw});}=item $ch-E<gt>waitin();Wait until input is available, also returns the lower-level statuscode.=cutsub waitin { my ($self) = @_; ref($self) or croak "Instance variable needed"; UNIVERSAL::isa($self, "heartbeat::clplumbing::ipc::channel") or croak "Wrong object type, not an IPC channel"; return heartbeat::cl_raw::ipc_ch_waitin($self->{raw});}=item $ch-E<gt>waitout();Wait until all queued messages have been send or the channel isdisconnected. Also returns the lower-level status code.=cutsub waitout { my ($self) = @_; ref($self) or croak "Instance variable needed"; UNIVERSAL::isa($self, "heartbeat::clplumbing::ipc::channel") or croak "Wrong object type, not an IPC channel"; return heartbeat::cl_raw::ipc_ch_waitout($self->{raw});}=item $ch-E<gt>iswconn();Returns true if the channel is connected for writing.=cutsub iswconn { my ($self) = @_; ref($self) or croak "Instance variable needed"; UNIVERSAL::isa($self, "heartbeat::clplumbing::ipc::channel") or croak "Wrong object type, not an IPC channel"; return heartbeat::cl_raw::ipc_ch_iswconn($self->{raw});}=item $ch-E<gt>isrconn();Returns true if the channel is ready to be read from, ie either inIPC_OK or IPC_DISC_PENDING.=cutsub isrconn { my ($self) = @_; ref($self) or croak "Instance variable needed"; UNIVERSAL::isa($self, "heartbeat::clplumbing::ipc::channel") or croak "Wrong object type, not an IPC channel"; return heartbeat::cl_raw::ipc_ch_isrconn($self->{raw});}=item $ch-E<gt>status();Returns ch_status.=cutsub status { my ($self) = @_; ref($self) or croak "Instance variable needed"; UNIVERSAL::isa($self, "heartbeat::clplumbing::ipc::channel") or croak "Wrong object type, not an IPC channel"; return heartbeat::cl_rawc::IPC_CHANNEL_ch_status_get($self->{raw}); }=item $ch-E<gt>is_message_pending();Returns TRUE if a message can be read right now.=cutsub is_message_pending { my ($self) = @_; ref($self) or croak "Instance variable needed"; UNIVERSAL::isa($self, "heartbeat::clplumbing::ipc::channel") or croak "Wrong object type, not an IPC channel"; return heartbeat::cl_raw::ipc_ch_is_message_pending($self->{raw});}=item $ch-E<gt>is_sending_blocked();Returns true if the channel is connected and there is still a message inthe send queue.=cutsub is_sending_blocked { my ($self) = @_; ref($self) or croak "Instance variable needed"; UNIVERSAL::isa($self, "heartbeat::clplumbing::ipc::channel") or croak "Wrong object type, not an IPC channel"; return heartbeat::cl_raw::ipc_ch_is_sending_blocked($self->{raw});}=item $ch-E<gt>resume_io();Resume IO and return the status code.=cutsub resume_io { my ($self) = @_; ref($self) or croak "Instance variable needed"; UNIVERSAL::isa($self, "heartbeat::clplumbing::ipc::channel") or croak "Wrong object type, not an IPC channel"; return heartbeat::cl_raw::ipc_ch_resume_io($self->{raw});}=item $ch-E<gt>get_send_select_fd();Return the fd which can be used in the poll() function for the sendingside of the connection.=cutsub get_send_select_fd { my ($self) = @_; ref($self) or croak "Instance variable needed"; UNIVERSAL::isa($self, "heartbeat::clplumbing::ipc::channel") or croak "Wrong object type, not an IPC channel"; return heartbeat::cl_raw::ipc_ch_get_send_select_fd($self->{raw});}=item $ch-E<gt>get_recv_select_fd();Return the fd which can be used in the poll() function for the receivingside of the connection.=cutsub get_recv_select_fd { my ($self) = @_; ref($self) or croak "Instance variable needed"; UNIVERSAL::isa($self, "heartbeat::clplumbing::ipc::channel") or croak "Wrong object type, not an IPC channel"; return heartbeat::cl_raw::ipc_ch_get_recv_select_fd($self->{raw});}=item $ch-E<gt>set_send_qlen($i);Set the sending queue len to C<$i>, which needs to be a positiveinteger.=cutsub set_send_qlen { my ($self, $qlen) = @_; ref($self) or croak "Instance variable needed"; UNIVERSAL::isa($self, "heartbeat::clplumbing::ipc::channel") or croak "Wrong object type, not an IPC channel"; ($qlen <= 0) and croak "send_qlen needs to be greater than 0"; return heartbeat::cl_raw::ipc_ch_set_send_qlen($self->{raw}, $qlen);}=item $ch-E<gt>set_recv_qlen($i);Set the receiving queue len to C<$i>, which needs to be a positiveinteger.=cutsub set_recv_qlen { my ($self, $qlen) = @_; ref($self) or croak "Instance variable needed"; UNIVERSAL::isa($self, "heartbeat::clplumbing::ipc::channel") or croak "Wrong object type, not an IPC channel"; ($qlen <= 0) and croak "recv_qlen needs to be greater than 0"; return heartbeat::cl_raw::ipc_ch_set_recv_qlen($self->{raw}, $qlen);}sub DESTROY { my ($self) = @_; ref($self) or croak "Instance variable needed"; UNIVERSAL::isa($self, "heartbeat::clplumbing::ipc::channel") or croak "Wrong object type, not an IPC channel"; heartbeat::cl_raw::ipc_ch_destroy($self->{raw});}=back=cut1;__END__=head1 SEE ALSOThe IPC header files in heartbeat.=head1 AUTHORLars Marowsky-Bree, E<lt>lmb@suse.deE<gt>=head1 COPYRIGHT AND LICENSECopyright (C) 2004 by Lars Marowsky-BreeThis library is free software; you can redistribute it and/ormodify it under the terms of the GNU Lesser General PublicLicense as published by the Free Software Foundation; eitherversion 2.1 of the License, or (at your option) any later version.This library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser General Public License for more details.You should have received a copy of the GNU Lesser General PublicLicense along with this library; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA=cut
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -