         # File lib/protocols/postgres.rb, line 166
    166:         def receive_data data
    167:                 @data << data
    168:                 while @data.length >= 5
    169:                         pktlen = @data[1...5].unpack("N").first
    170:                         if @data.length >= (1 + pktlen)
    171:                                 pkt = @data.slice!(0...(1+pktlen))
    172:                                 m = StringIO.open( pkt, "r" ) {|io| PostgresPR::Message.read( io ) }
    173:                                 if @pending_conn
    174:                                         dispatch_conn_message m
    175:                                 elsif @pending_query
    176:                                         dispatch_query_message m
    177:                                 else
    178:                                         raise "Unexpected message from database"
    179:                                 end
    180:                         else
    181:                                 break # very important, break out of the while
    182:                         end
    183:                 end
    184:         end