Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

(!!!) Change the ClientFilter and Filter parameters in Server::TCP and

Client::TCP respectively.  They were recently "enhanced" to accept
filter instances, and they would create filter instances from class
names internally.  However, this new "feature" meant that every
connection SHARED THE SAME FILTER.  The changes now let them accept
class names and optional constructor parameters, and the components
will instantiate new filters for each connection.  "MarkClone" on
efnet reported that the POE Cookbook web server was only honoring its
first request; the remainders were bombing out with an error which led
me to this problem.
  • Loading branch information...
commit 679d7b8d1626a62d20b09c649a1b53a61996b523 1 parent f52dfa4
@rcaputo authored
Showing with 38 additions and 18 deletions.
  1. +19 −8 lib/POE/Component/Client/TCP.pm
  2. +19 −10 lib/POE/Component/Server/TCP.pm
View
27 lib/POE/Component/Client/TCP.pm
@@ -85,9 +85,15 @@ sub new {
# Defaults.
+ my @filter_args;
$address = '127.0.0.1' unless defined $address;
- $filter = POE::Filter::Line->new() unless defined $filter;
- $filter = $filter->new() unless ref($filter);
+ unless (defined $filter) {
+ $filter = "POE::Filter::Line";
+ }
+ elsif (ref($filter) eq 'ARRAY') {
+ @filter_args = @$filter;
+ $filter = shift @filter_args;
+ }
$conn_error_callback = \&_default_error unless defined $conn_error_callback;
$error_callback = \&_default_error unless defined $error_callback;
@@ -133,7 +139,7 @@ sub new {
$_[HEAP]->{server} = POE::Wheel::ReadWrite->new
( Handle => $socket,
Driver => POE::Driver::SysRW->new( BlockSize => 4096 ),
- Filter => $filter,
+ Filter => $filter->new(@filter_args),
InputEvent => 'got_server_input',
ErrorEvent => 'got_server_error',
FlushedEvent => 'got_server_flush',
@@ -250,7 +256,7 @@ POE::Component::Client::TCP - a simplified TCP client
ServerError => \&handle_server_error,
ServerFlushed => \&handle_server_flush,
- Filter => POE::Filter::Something->new(),
+ Filter => "POE::Filter::Something",
InlineStates => { ... },
PackageStates => [ ... ],
@@ -367,10 +373,15 @@ requested.
=item Filter
-Filter may contain either a POE::Filter class name, such as
-C<"POE::Filter::Stream"> or a POE::Filter instance, such as C<new
-POE::Filter::Reference>. It is optional, and the component will
-default to "POE::Filter::Line" if a Filter is omitted.
+Filter specifies the type of filter that will parse input from a
+server. It may either be a scalar or a list reference. If it is a
+scalar, it will contain a POE::Filter class name. If it is a list
+reference, the first item in the list will be a POE::Filter class
+name, and the remaining items will be constructor parameters for the
+filter.
+
+Filter is optional. The component will supply a "POE::Filter::Line"
+instance none is specified.
=item InlineStates
View
29 lib/POE/Component/Server/TCP.pm
@@ -65,6 +65,7 @@ sub new {
}
}
+ my @client_filter_args;
my $client_connected = delete $param{ClientConnected};
my $client_disconnected = delete $param{ClientDisconnected};
my $client_error = delete $param{ClientError};
@@ -78,8 +79,15 @@ sub new {
$error_callback = \&_default_server_error unless defined $error_callback;
if (defined $client_input) {
- $client_filter = "POE::Filter::Line" unless defined $client_filter;
- $client_filter = $client_filter->new() unless ref($client_filter);
+ unless (defined $client_filter) {
+ $client_filter = "POE::Filter::Line";
+ @client_filter_args = ();
+ }
+ elsif (ref($client_filter) eq 'ARRAY') {
+ @client_filter_args = @$client_filter;
+ $client_filter = shift @client_filter_args;
+ }
+
$client_error = \&_default_client_error unless defined $client_error;
$client_connected = sub {} unless defined $client_connected;
$client_disconnected = sub {} unless defined $client_disconnected;
@@ -121,7 +129,7 @@ sub new {
$heap->{client} = POE::Wheel::ReadWrite->new
( Handle => $socket,
Driver => POE::Driver::SysRW->new( BlockSize => 4096 ),
- Filter => $client_filter,
+ Filter => $client_filter->new(@client_filter_args),
InputEvent => 'tcp_server_got_input',
ErrorEvent => 'tcp_server_got_error',
FlushedEvent => 'tcp_server_got_flush',
@@ -419,14 +427,15 @@ connection.
=item ClientFilter
-ClientFilter may contain either a POE::Filter class name, such as
-C<"POE::Filter::Block"> or a POE::Filter instance, such as C<new
-POE::Filter::HTTPD>. ClientFilter is optional;
-POE::Component::Server::TCP will provide a generic Line filter by
-default.
+ClientFilter specifies the type of filter that will parse input from
+each client. It may either be a scalar or a list reference. If it is
+a scalar, it will contain a POE::Filter class name. If it is a list
+reference, the first item in the list will be a POE::Filter class
+name, and the remaining items will be constructor parameters for the
+filter.
-If a ClientFilter class is specified, it's up to the programmer to use
-or define that class.
+ClientFilter is optional. The component will supply a
+"POE::Filter::Line" instance none is specified.
=item ClientInput
Please sign in to comment.
Something went wrong with that request. Please try again.