Show
Ignore:
Timestamp:
10/04/11 21:15:19 (3 years ago)
Author:
jesus
Message:

only warn about errors in a working stream.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Sniffer-Postgres/lib/Postgres/Request.pm

    r288 r290  
    5353  my $buf = shift; 
    5454  my $self = bless { whence => shift }, $class; 
     55  my $inflight = shift; 
    5556 
    5657  my $type = substr($$buf, 0, 1); 
    5758  if(!exists($types->{$type})) { 
    58     warn "unknown Request type: $type\n"; 
     59    if(!$$inflight) { 
     60      warn "unknown Request type: $type\n"; 
     61    } 
    5962    $$buf = ''; 
    6063    return undef; 
    6164  } 
     65  $$inflight = 0; 
    6266  # special case for cancel query 
    6367  if(unpack("N", substr($$buf, 0, 4)) == 16 && 
  • trunk/Sniffer-Postgres/lib/Postgres/Response.pm

    r288 r290  
    3838  'Z' => { name => 'Ready', complete => 1 }, 
    3939  'T' => { name => 'Row Description' }, 
     40  'R' => { name => 'Authentication' }, 
    4041}; 
    4142 
     
    5051  my $buf = shift; 
    5152  my $self = bless { whence => shift }, $class; 
     53  my $inflight = shift; 
    5254  my $type = substr($$buf, 0, 1); 
    5355 
    5456  if(!exists($types->{$type})) { 
    55     warn "unknown Response type: $type\n"; 
     57    if(!$$inflight) { 
     58      warn "unknown Response type: $type\n"; 
     59    } 
    5660    $$buf = ''; 
    5761    return undef; 
    5862  } 
     63  $$inflight = 0; 
    5964  # Gotta start somewhere 
    6065  return undef if (length($$buf) < 5); 
  • trunk/Sniffer-Postgres/lib/Sniffer/Connection/Postgres.pm

    r92 r290  
    4545 
    4646  my $tcp_log = delete $args{tcp_log} || sub {}; 
     47  my $inflight = (defined $args{inflight} && $args{inflight} != 0); 
     48  delete $args{inflight}; 
    4749 
    4850  my $self = $class->SUPER::new(\%args); 
     
    5355    closed        => sub {}, 
    5456    teardown      => sub { $self->closed->($self) }, 
     57    inflight      => $inflight, 
    5558    log           => $tcp_log, 
    5659  )); 
     
    125128    if (! (my $res = $self->_response)) { 
    126129      # We need to find something that looks like a valid Postgres request in our stream 
    127       $res = Postgres::Response->parse($buffer, $conn ? $conn->last_activity : undef); 
     130      $res = Postgres::Response->parse($buffer, $conn ? $conn->last_activity : undef, \$conn->{inflight}); 
    128131      return if not defined($res); 
    129132      $self->_response($res); 
     
    150153  while ($$buffer) { 
    151154    if (! (my $req = $self->_request)) { 
    152       $req = Postgres::Request->parse($buffer, $conn->last_activity); 
     155      $req = Postgres::Request->parse($buffer, $conn->last_activity, \$conn->{inflight}); 
    153156      return if not defined($req); 
    154157      $self->_request($req); 
  • trunk/Sniffer-Postgres/lib/Sniffer/Postgres.pm

    r92 r290  
    145145 
    146146sub find_or_create_connection { 
    147   my ($self,$tcp) = @_; 
     147  my ($self,$tcp,$inflight) = @_; 
    148148 
    149149  my $connections = $self->connections; 
     
    160160        %$c, 
    161161        tcp            => $tcp, 
     162        inflight       => $inflight 
    162163      ); 
    163164      $connections->{$key} = $o; 
     
    272273      if $i->{hlen} < 5; 
    273274  my $conn = $self->handle_tcp_packet(substr($i->{data}, 0, $i->{len}-($i->{hlen}*4)), $ts); 
    274   unless($conn->tcp_connection->dest_host) { 
     275  unless(!$conn || $conn->tcp_connection->dest_host) { 
    275276    $conn->tcp_connection->dest_host($i->{dest_ip}); 
    276277    $conn->tcp_connection->src_host($i->{src_ip}); 
     
    299300  if (! ref $tcp) { 
    300301    $tcp = NetPacket::TCP->decode($tcp); 
    301   } 
    302   my $conn = $self->find_or_create_connection($tcp); 
     302    return undef if(!exists($tcp->{src_port}) || 
     303                    !exists($tcp->{dest_port})); 
     304  } 
     305  my $conn = $self->find_or_create_connection($tcp, $self->inflight); 
    303306 
    304307  # This hacks mid-stream sessions