Skip to content

Commit

Permalink
fixed more portability issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 3, 2011
1 parent fe4da1c commit 6dcf40c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Changes
Expand Up @@ -7,7 +7,7 @@ This file documents the revision history for Perl extension Mojolicious.
- Improved resolver tests.
- Fixed small formatting bug in Mojo::Headers.
- Fixed small proxy message generation bug.
- Fixed a few portability issues.
- Fixed many portability issues.

1.99 2011-09-29 00:00:00
- Deprecated direct hash access to the flash in
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Asset/File.pm
Expand Up @@ -28,7 +28,7 @@ has handle => sub {
my $fh;
until (sysopen $fh, $name, O_CREAT | O_EXCL | O_RDWR) {
croak qq/Can't open file "$name": $!/ if $file || $! != $!{EEXIST};
$name = "$base." . md5_sum(time . $$ . rand 999999999);
$name = "$base." . md5_sum(time . $$ . rand 9999999);
}
$file = $name;
$self->path($file);
Expand Down
20 changes: 14 additions & 6 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -7,6 +7,7 @@ use Mojo::IOLoop::Server;
use Mojo::IOLoop::Stream;
use Mojo::IOLoop::Trigger;
use Mojo::IOWatcher;
use Mojo::Util 'md5_sum';
use Scalar::Util 'weaken';
use Time::HiRes 'time';

Expand Down Expand Up @@ -52,9 +53,8 @@ sub connect {

# New client
my $client = $self->client_class->new;
(my $id) = "$client" =~ /0x([\da-f]+)/;
$id = $args->{id} if $args->{id};
my $c = $self->{connections}->{$id} ||= {};
my $id = $args->{id} ? $args->{id} : $self->_id;
my $c = $self->{connections}->{$id} ||= {};
$c->{client} = $client;
$client->resolver($self->resolver);
weaken $client->{resolver};
Expand Down Expand Up @@ -162,7 +162,7 @@ sub listen {

# New server
my $server = $self->server_class->new;
(my $id) = "$server" =~ /0x([\da-f]+)/;
my $id = $self->_id;
$self->{servers}->{$id} = $server;
$server->iowatcher($self->iowatcher);
weaken $server->{iowatcher};
Expand All @@ -179,8 +179,8 @@ sub listen {

# New stream
my $stream = $self->stream_class->new($handle);
(my $id) = "$stream" =~ /0x([\da-f]+)/;
my $c = $self->{connections}->{$id} ||= {};
my $id = $self->_id;
my $c = $self->{connections}->{$id} ||= {};
$c->{stream} = $stream;
$stream->iowatcher($self->iowatcher);
weaken $stream->{iowatcher};
Expand Down Expand Up @@ -382,6 +382,14 @@ sub _event {
return $self;
}

sub _id {
my $self = shift;
while (1) {
my $id = md5_sum('c' . time . rand 999999999);
return $id if !$self->{connections}->{$id} && !$self->{servers}->{$id};
}
}

sub _listening {
my $self = shift;

Expand Down
7 changes: 6 additions & 1 deletion lib/Mojo/IOWatcher.pm
Expand Up @@ -2,6 +2,7 @@ package Mojo::IOWatcher;
use Mojo::Base -base;

use IO::Poll qw/POLLERR POLLHUP POLLIN POLLOUT/;
use Mojo::Util 'md5_sum';
use Time::HiRes qw/time usleep/;

use constant DEBUG => $ENV{MOJO_IOWATCHER_DEBUG} || 0;
Expand Down Expand Up @@ -118,7 +119,11 @@ sub _timer {
my $self = shift;
my $cb = shift;
my $t = {cb => $cb, @_};
(my $id) = "$t" =~ /0x([\da-f]+)/;
my $id;
while (1) {
$id = md5_sum('t' . time . rand 999999999);
last unless $self->{timers}->{$id};
}
$self->{timers}->{$id} = $t;
return $id;
}
Expand Down

0 comments on commit 6dcf40c

Please sign in to comment.