Skip to content
Snippets Groups Projects
Commit fc4e6f57 authored by rds's avatar rds
Browse files

- stops the possiblity of a race conition so long as server

  implementor calls X11::XRemote::block() when receiving a command.
- send_reply automatically unblocks.

I guess the alternative would be to send yourself a command or to emit
an event to act on.  Not sure which is best, but seems like a good idea
to stop people being able to create the race condition.
parent d71b6929
No related branches found
No related tags found
No related merge requests found
......@@ -102,6 +102,9 @@ sub send_commands{
my ($self, @commands) = @_;
return ("503:<xml><message>servers may not send_commands. command not sent</message></xml>") x @commands
if $self->_is_server();
warn __PACKAGE__ . ": Avoided race condition." if blocked();
return ("500:<xml>you cannot send while receiving until you have replied. See perldoc ".__PACKAGE__."</xml>") x @commands
if blocked();
$self->{'_response_list'} = [];
$self->{'_request_list'} = [];
foreach my $cmd(@commands){
......@@ -135,12 +138,29 @@ sub request_string{
}
return $req;
}
sub send_reply{
my ($self, $reply) = @_;
return unless $self->_is_server();
$self->_handle->reply($reply);
}
{
# BLOCK should only be available here!!!
# Nothing should be allowed to reset it except send_reply()
my $BLOCK = 0;
sub block{
$BLOCK = 1;
}
sub blocked{
return ($BLOCK ? 1 : undef);
}
sub send_reply{
my ($self, $reply) = @_;
return unless $self->_is_server();
local *unblock = sub {
$BLOCK = 0; # man perlref says this should work
};
$self->_handle->reply($reply);
unblock();
}
}
#==========================================================#
# INTERNALS #
#==========================================================#
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment