<commit_before>#!/usr/bin/perl
##
# This file is part of the XP Framework's experiments
#
# $Id$
 
package EASC::Protocol::XpProtocolHandler;

use strict;
use warnings;
use Carp qw(confess);

use EASC::Protocol::Serializer;
use EASC::Protocol::ByteCountedString;

use IO::Socket;

require Exporter;

our $VERSION = 1.0;

our @ISA = qw(Exporter);
our @EXPORT= qw();
our %EXPORT_TAGS = ( );
our @EXPORT_OK = qw();

use vars qw();

# Its maaaaaagic
  sub DEFAULT_PROTOCOL_MAGIC_NUMBER  { 0x3C872747 };
  
# Request messages
  sub REMOTE_MSG_INIT      { 0 };
  sub REMOTE_MSG_LOOKUP    { 1 };
  sub REMOTE_MSG_CALL      { 2 };
  sub REMOTE_MSG_FINALIZE  { 3 };
  sub REMOTE_MSG_TRAN_OP   { 4 };  
# Response messages
  sub REMOTE_MSG_VALUE     { 5 };
  sub REMOTE_MSG_EXCEPTION { 6 };
  sub REMOTE_MSG_ERROR     { 7 };
# Transaction message types
  sub REMOTE_TRAN_BEGIN    { 1 };
  sub REMOTE_TRAN_STATE    { 2 };
  sub REMOTE_TRAN_COMMIT   { 3 };
  sub REMOTE_TRAN_ROLLBACK { 4 };



# Initialize this protocol handler
# @access    public
# @param     \%URL-Data

sub new {
    my ($classname, @args) = @_;
    my $self = {};
    
    $self->{versionMajor} = 0;
    $self->{versionMinor} = 0;
    $self->{_socket} = undef;

    bless($self, $classname);
    return $self->_init(@args);
}


# Initialize this protocol handler
# @access    private
sub _init {
    my ($self, $proxy) = @_;
    $self->{versionMajor} = $proxy->{versionMajor};
    $self->{versionMinor} = $proxy->{versionMinor};
    $self->{host} = $proxy->{host};
    $self->{port} = $proxy->{port};
    
    # Connect to Socket
    my $sock = IO::Socket::INET->new(
        PeerAddr => $self->{host},
        PeerPort => $self->{port},
		Proto    => "tcp",
		Type     => SOCK_STREAM 
    );

    # SMELL: die instead of execption-handling
    $sock or die "Couldn't connect to $self->{host}:$self->{port}. Error: $@\n";
    $self->{_sock} = $sock;

    my $response;
    if (defined $proxy->{user}) {     # Authentification 
        my $login= [ 
            EASC::Protocol::ByteCountedString::->new($proxy->{user}), 
            EASC::Protocol::ByteCountedString::->new($proxy->{pass})   
        ];
        $response = $self->sendPacket(REMOTE_MSG_INIT, "\1", $login);
    } else {                          # no Authentification
        $response = $self->sendPacket(REMOTE_MSG_INIT, "\0");   
    }
    return $response ? $self : undef;<commit_msg>- Set TCP_NODELAY forcefully on socket just to be sure<commit_after>#!/usr/bin/perl
##
# This file is part of the XP Framework's experiments
#
# $Id$
 
package EASC::Protocol::XpProtocolHandler;

use strict;
use warnings;
use Carp qw(confess);

use EASC::Protocol::Serializer;
use EASC::Protocol::ByteCountedString;

use IO::Socket;
use Socket qw(TCP_NODELAY);

require Exporter;

our $VERSION = 1.0;

our @ISA = qw(Exporter);
our @EXPORT= qw();
our %EXPORT_TAGS = ( );
our @EXPORT_OK = qw();

use vars qw();

# Its maaaaaagic
  sub DEFAULT_PROTOCOL_MAGIC_NUMBER  { 0x3C872747 };
  
# Request messages
  sub REMOTE_MSG_INIT      { 0 };
  sub REMOTE_MSG_LOOKUP    { 1 };
  sub REMOTE_MSG_CALL      { 2 };
  sub REMOTE_MSG_FINALIZE  { 3 };
  sub REMOTE_MSG_TRAN_OP   { 4 };  
# Response messages
  sub REMOTE_MSG_VALUE     { 5 };
  sub REMOTE_MSG_EXCEPTION { 6 };
  sub REMOTE_MSG_ERROR     { 7 };
# Transaction message types
  sub REMOTE_TRAN_BEGIN    { 1 };
  sub REMOTE_TRAN_STATE    { 2 };
  sub REMOTE_TRAN_COMMIT   { 3 };
  sub REMOTE_TRAN_ROLLBACK { 4 };



# Initialize this protocol handler
# @access    public
# @param     \%URL-Data

sub new {
    my ($classname, @args) = @_;
    my $self = {};
    
    $self->{versionMajor} = 0;
    $self->{versionMinor} = 0;
    $self->{_socket} = undef;

    bless($self, $classname);
    return $self->_init(@args);
}


# Initialize this protocol handler
# @access    private
sub _init {
    my ($self, $proxy) = @_;
    $self->{versionMajor} = $proxy->{versionMajor};
    $self->{versionMinor} = $proxy->{versionMinor};
    $self->{host} = $proxy->{host};
    $self->{port} = $proxy->{port};
    
    # Connect to Socket
    my $sock = IO::Socket::INET->new(
        PeerAddr => $self->{host},
        PeerPort => $self->{port},
		Proto    => "tcp",
		Type     => SOCK_STREAM 
    );
    $sock->sockopt(Socket::TCP_NODELAY, 1);

    # SMELL: die instead of execption-handling
    $sock or die "Couldn't connect to $self->{host}:$self->{port}. Error: $@\n";
    $self->{_sock} = $sock;

    my $response;
    if (defined $proxy->{user}) {     # Authentification 
        my $login= [ 
            EASC::Protocol::ByteCountedString::->new($proxy->{user}), 
            EASC::Protocol::ByteCountedString::->new($proxy->{pass})   
        ];
        $response = $self->sendPacket(REMOTE_MSG_INIT, "\1", $login);
    } else {                          # no Authentification
        $response = $self->sendPacket(REMOTE_MSG_INIT, "\0");   
    }
    return $response ? $self : undef;
{'fraction_non_alphanumeric': 0.15488965377606803, 'fraction_numerical': 0.010730917189714518, 'mean_word_length': 2.886703383162864, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1461872', 'n_tokens_mistral': 1896, 'n_tokens_neox': 1732, 'n_words': 395}