setting TCP_NODELAY

Wrote new code? Fixed a bug? Want to discuss technical stuff? Feel free to post it here.

Moderator: Moderators

Message
Author
lazylionsby
Noob
Noob
Posts: 6
Joined: 08 Nov 2011, 05:57
Noob?: Yes

setting TCP_NODELAY

#1 Post by lazylionsby »

It might be better to set TCP_NODELAY in src/Network/DirectConnection.pm such as :

Code: Select all

use Socket;
then

Code: Select all

##
# $net->serverConnect(String host, int port)
# host: the host name/IP of the RO server to connect to.
# port: the port number of the RO server to connect to.
#
# Establish a connection to a Ragnarok Online server.
#
# This function is used internally by $net->checkConnection() and should not be used directly.
sub serverConnect {
        my $self = shift;
        my $host = shift;
        my $port = shift;
        my $return = 0;

        Plugins::callHook('Network::connectTo', {
                socket => \$self->{remote_socket},
                return => \$return,
                host => $host,
                port => $port
        });
        return if ($return);

        message TF("Connecting (%s:%s)... ", $host, $port), "connection";
        $self->{remote_socket} = new IO::Socket::INET(
                        LocalAddr       => $config{bindIp} || undef,
                        PeerAddr        => $host,
                        PeerPort        => $port,
                        Proto           => 'tcp',
                        Timeout         => 4);
        setsockopt($self->{remote_socket}, &Socket::IPPROTO_TCP, &Socket::TCP_NODELAY, 1);
        $self->{remote_socket}->setsockopt(&Socket::IPPROTO_TCP, &Socket::TCP_NODELAY, 1);
        ($self->{remote_socket} && inet_aton($self->{remote_socket}->peerhost()) eq inet_aton($host)) ?
                message T("connected\n"), "connection" :
                error(TF("couldn't connect: %s (error code %d)\n", "$!", int($!)), "connection");
        if ($self->getState() != Network::NOT_CONNECTED) {
                $incomingMessages->nextMessageMightBeAccountID();
        }
}
Thoughts?