Skip to content

Commit

Permalink
fix minor breakage when depreciating State for Event. now the tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
rcaputo committed May 1, 2001
1 parent 4ef3ba9 commit 1c6ab16
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 51 deletions.
4 changes: 3 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ POE is due for a round of breakage to make things more consistent.
define states, they emit events. Calling Wheels' parameters
/.*State/ is inconsistent and confusing.

TODO: Verify that the new code passes existing tests.
TODO: Port existing tests and samples to /.*Event/.

TODO: Have the support and documentation changes on the CPAN for
Expand Down Expand Up @@ -96,6 +95,9 @@ depreciation warnings are also commented. Changed the documentation
to say /.*Event/ instead of /.*State/, so new users will not learn the
depreciated ways.

Verified that the depreciation from State to Event does not break
existing tests. The samples directory is still lagging behind here.


0.14 2001.04.23
---------------
Expand Down
12 changes: 6 additions & 6 deletions lib/POE/Wheel/FollowTail.pm
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@ sub event {
my $self = shift;
push(@_, undef) if (scalar(@_) & 1);

# STATE-EVENT
if ($name =~ /^(.*?)State$/) {
# depreciation warning goes here
$name = $1 . 'Event';
}

while (@_) {
my ($name, $event) = splice(@_, 0, 2);

# STATE-EVENT
if ($name =~ /^(.*?)State$/) {
# depreciation warning goes here
$name = $1 . 'Event';
}

if ($name eq 'InputEvent') {
if (defined $event) {
$self->[SELF_EVENT_INPUT] = $event;
Expand Down
12 changes: 6 additions & 6 deletions lib/POE/Wheel/ListenAccept.pm
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ sub event {
my $self = shift;
push(@_, undef) if (scalar(@_) & 1);

# STATE-EVENT
if ($name =~ /^(.*?)State$/) {
# depreciation warning goes here
$name = $1 . 'Event';
}

while (@_) {
my ($name, $event) = splice(@_, 0, 2);

# STATE-EVENT
if ($name =~ /^(.*?)State$/) {
# depreciation warning goes here
$name = $1 . 'Event';
}

if ($name eq 'AcceptEvent') {
if (defined $event) {
$self->[SELF_EVENT_ACCEPT] = $event;
Expand Down
36 changes: 36 additions & 0 deletions lib/POE/Wheel/ReadWrite.pm
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,42 @@ sub new {
}
}

# STATE-EVENT
if (exists $params{InputState}) {
if (exists $params{InputEvent}) {
carp "InputEvent takes precedence over depreciated InputState";
delete $params{InputState};
}
else {
# depreciation warning goes here
$params{InputEvent} = delete $params{InputState};
}
}

# STATE-EVENT
if (exists $params{ErrorState}) {
if (exists $params{ErrorEvent}) {
carp "ErrorEvent takes precedence over depreciated ErrorState";
delete $params{ErrorState};
}
else {
# depreciation warning goes here
$params{ErrorEvent} = delete $params{ErrorState};
}
}

# STATE-EVENT
if (exists $params{FlushedState}) {
if (exists $params{FlushedEvent}) {
carp "FlushedEvent takes precedence over depreciated FlushedState";
delete $params{FlushedState};
}
else {
# depreciation warning goes here
$params{FlushedEvent} = delete $params{FlushedState};
}
}

{ my $mark_errors = 0;
if (defined($params{HighMark}) xor defined($params{LowMark})) {
carp "HighMark and LowMark parameters require each-other";
Expand Down
74 changes: 37 additions & 37 deletions lib/POE/Wheel/SocketFactory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ sub _define_accept_state {

my $domain = $map_family_to_domain{ $self->[MY_SOCKET_DOMAIN] };
$domain = '(undef)' unless defined $domain;
my $success_state = \$self->[MY_EVENT_SUCCESS];
my $failure_state = \$self->[MY_EVENT_FAILURE];
my $success_event = \$self->[MY_EVENT_SUCCESS];
my $failure_event = \$self->[MY_EVENT_FAILURE];
my $unique_id = $self->[MY_UNIQUE_ID];

$poe_kernel->state
Expand All @@ -122,14 +122,14 @@ sub _define_accept_state {
else {
die "sanity failure: socket domain == $domain";
}
$k->call( $me, $$success_state,
$k->call( $me, $$success_event,
$new_socket, $peer_addr, $peer_port,
$unique_id
);
}
elsif ($! != EWOULDBLOCK) {
$$failure_state &&
$k->call( $me, $$failure_state,
$$failure_event &&
$k->call( $me, $$failure_event,
'accept', ($!+0), $!, $unique_id
);
}
Expand All @@ -151,8 +151,8 @@ sub _define_connect_state {

my $domain = $map_family_to_domain{ $self->[MY_SOCKET_DOMAIN] };
$domain = '(undef)' unless defined $domain;
my $success_state = \$self->[MY_EVENT_SUCCESS];
my $failure_state = \$self->[MY_EVENT_FAILURE];
my $success_event = \$self->[MY_EVENT_SUCCESS];
my $failure_event = \$self->[MY_EVENT_FAILURE];
my $unique_id = $self->[MY_UNIQUE_ID];
my $socket_selected = \$self->[MY_SOCKET_SELECTED];

Expand All @@ -170,8 +170,8 @@ sub _define_connect_state {
# Throw a failure if the connection failed.
$! = unpack('i', getsockopt($handle, SOL_SOCKET, SO_ERROR));
if ($!) {
(defined $$failure_state) and
$k->call( $me, $$failure_state,
(defined $$failure_event) and
$k->call( $me, $$failure_event,
'connect', ($!+0), $!, $unique_id
);
return;
Expand All @@ -180,8 +180,8 @@ sub _define_connect_state {
# Get the remote address, or throw an error if that fails.
my $peer = getpeername($handle);
if ($!) {
(defined $$failure_state) and
$k->call( $me, $$failure_state,
(defined $$failure_event) and
$k->call( $me, $$failure_event,
'getpeername', ($!+0), $!, $unique_id
);
return;
Expand Down Expand Up @@ -218,7 +218,7 @@ sub _define_connect_state {
}

# Tell the session it went okay.
$k->call( $me, $$success_state,
$k->call( $me, $$success_event,
$handle, $peer_addr, $peer_port, $unique_id
);
}
Expand Down Expand Up @@ -396,7 +396,7 @@ sub new {
# testing duplicates of.
my $abstract_domain = $map_family_to_domain{$self->[MY_SOCKET_DOMAIN]};
unless (defined $abstract_domain) {
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'domain', 0, '', $self->[MY_UNIQUE_ID]
);
return $self;
Expand Down Expand Up @@ -427,7 +427,7 @@ sub new {

if ($socket_protocol !~ /^\d+$/) {
unless ($socket_protocol = getprotobyname($socket_protocol)) {
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'getprotobyname', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
Expand All @@ -439,7 +439,7 @@ sub new {
# programmer wonder why things fail later.
$protocol_name = lc(getprotobynumber($socket_protocol));
unless ($protocol_name) {
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'getprotobynumber', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
Expand Down Expand Up @@ -472,7 +472,7 @@ sub new {
$self->[MY_SOCKET_TYPE], $self->[MY_SOCKET_PROTOCOL]
)
) {
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'socket', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
Expand Down Expand Up @@ -501,7 +501,7 @@ sub new {
$set_it
)
or do {
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'ioctl', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
Expand All @@ -512,14 +512,14 @@ sub new {
else {
my $flags = fcntl($socket_handle, F_GETFL, 0)
or do {
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'fcntl', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
};
$flags = fcntl($socket_handle, F_SETFL, $flags | O_NONBLOCK)
or do {
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'fcntl', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
Expand All @@ -537,7 +537,7 @@ sub new {
{
setsockopt($socket_handle, SOL_SOCKET, SO_REUSEADDR, 1)
or do {
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'setsockopt', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
Expand Down Expand Up @@ -569,7 +569,7 @@ sub new {
or ($bind_address = inet_aton($bind_address));
unless (defined $bind_address) {
$! = EADDRNOTAVAIL;
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'inet_aton', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
Expand All @@ -582,7 +582,7 @@ sub new {
$bind_port = getservbyname($bind_port, $protocol_name);
unless (defined $bind_port) {
$! = EADDRNOTAVAIL;
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'getservbyname', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
Expand All @@ -591,7 +591,7 @@ sub new {

$bind_address = pack_sockaddr_in($bind_port, $bind_address);
unless (defined $bind_address) {
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'pack_sockaddr_in', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
Expand All @@ -608,7 +608,7 @@ sub new {
# Is this necessary, or will bind() return EADDRINUSE?
if (defined $params{RemotePort}) {
$! = EADDRINUSE;
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'bind', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
Expand All @@ -617,7 +617,7 @@ sub new {
$bind_address = &condition_unix_address($params{BindAddress});
$bind_address = pack_sockaddr_un($bind_address);
unless ($bind_address) {
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'pack_sockaddr_un', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
Expand All @@ -634,7 +634,7 @@ sub new {
# Perform the actual bind, if there's a bind address to bind to.
if (defined $bind_address) {
unless (bind($socket_handle, $bind_address)) {
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'bind', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
Expand Down Expand Up @@ -663,7 +663,7 @@ sub new {
if ($remote_port =~ /[^0-9]/) {
unless ($remote_port = getservbyname($remote_port, $protocol_name)) {
$! = EADDRNOTAVAIL;
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'getservbyname', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
Expand All @@ -673,7 +673,7 @@ sub new {
$connect_address = inet_aton($params{RemoteAddress});
unless (defined $connect_address) {
$! = EADDRNOTAVAIL;
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'inet_aton', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
Expand All @@ -682,7 +682,7 @@ sub new {
$connect_address = pack_sockaddr_in($remote_port, $connect_address);
unless ($connect_address) {
$! = EADDRNOTAVAIL;
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'pack_sockaddr_in', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
Expand All @@ -697,7 +697,7 @@ sub new {
$connect_address = condition_unix_address($params{RemoteAddress});
$connect_address = pack_sockaddr_un($connect_address);
unless (defined $connect_address) {
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'pack_sockaddr_un', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
Expand Down Expand Up @@ -726,7 +726,7 @@ sub new {
# I don't know what AS's Perl uses instead. What to do here?

if ($! and ($! != EINPROGRESS) and ($! != EWOULDBLOCK)) {
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'connect', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
Expand Down Expand Up @@ -759,7 +759,7 @@ sub new {
my $listen_queue = $params{ListenQueue} || SOMAXCONN;
($listen_queue > SOMAXCONN) && ($listen_queue = SOMAXCONN);
unless (listen($socket_handle, $listen_queue)) {
$poe_kernel->yield( $state_failure,
$poe_kernel->yield( $event_failure,
'listen', $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
Expand All @@ -780,7 +780,7 @@ sub new {
if ($protocol_op eq SVROP_NOTHING) {
# Do nothing. Duh. Fire off a success event immediately, and
# return.
$poe_kernel->yield( $state_success,
$poe_kernel->yield( $event_success,
$socket_handle, undef, undef, $self->[MY_UNIQUE_ID]
);
return $self;
Expand Down Expand Up @@ -848,7 +848,7 @@ POE::Wheel::SocketFactory - non-blocking socket creation and management
SocketDomain => AF_UNIX, # Sets the socket() domain
BindAddress => $unix_socket_address, # Sets the bind() address
SuccessEvent => $success_event, # Event to emit upon accept()
FailureEvent => $failure_event, # Event to emit upon error
FailureEvent => $event_failure, # Event to emit upon error
# Optional parameters (and default values):
SocketType => SOCK_STREAM, # Sets the socket() type
);
Expand All @@ -858,7 +858,7 @@ POE::Wheel::SocketFactory - non-blocking socket creation and management
SocketDomain => AF_UNIX, # Sets the socket() domain
RemoteAddress => $unix_server_address, # Sets the connect() address
SuccessEvent => $success_event, # Event to emit on connection
FailureEvent => $failure_event, # Event to emit on error
FailureEvent => $event_failure, # Event to emit on error
# Optional parameters (and default values):
SocketType => SOCK_STREAM, # Sets the socket() type
# Optional parameters (that have no defaults):
Expand All @@ -870,7 +870,7 @@ POE::Wheel::SocketFactory - non-blocking socket creation and management
BindAddress => $inet_address, # Sets the bind() address
BindPort => $inet_port, # Sets the bind() port
SuccessEvent => $success_event, # Event to emit upon accept()
FailureEvent => $failure_event, # Event to emit upon error
FailureEvent => $event_failure, # Event to emit upon error
# Optional parameters (and default values):
SocketDomain => AF_INET, # Sets the socket() domain
SocketType => SOCK_STREAM, # Sets the socket() type
Expand All @@ -884,7 +884,7 @@ POE::Wheel::SocketFactory - non-blocking socket creation and management
RemoteAddress => $inet_address, # Sets the connect() address
RemotePort => $inet_port, # Sets the connect() port
SuccessEvent => $success_event, # Event to emit on connection
FailureEvent => $failure_event, # Event to emit on error
FailureEvent => $event_failure, # Event to emit on error
# Optional parameters (and default values):
SocketDomain => AF_INET, # Sets the socket() domain
SocketType => SOCK_STREAM, # Sets the socket() type
Expand Down
Loading

0 comments on commit 1c6ab16

Please sign in to comment.