This file is indexed.

/usr/share/polymake/perllib/Polymake/Sockets.pm is in polymake-common 3.2r2-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#  Copyright (c) 1997-2018
#  Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
#  http://www.polymake.org
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version: http://www.gnu.org/licenses/gpl.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#-------------------------------------------------------------------------------

require Polymake::Pipe;

use strict;
use namespaces;
use warnings qw(FATAL void syntax misc);

package Polymake::ServerSocket;
use Socket;
use Fcntl;
use POSIX qw(:errno_h);

use Polymake::Struct (
   [ new => ';$' ],
   [ '$handle' => 'undef' ],
   [ '$port' => '#1' ],
);

# Constructor: new ServerSocket([ port ])
sub new {
   my $self=&_new;
   socket $self->handle, PF_INET, SOCK_STREAM, getprotobyname('tcp')
      or die "socket failed: $!\n";
   my $local_ip=$ENV{POLYMAKE_HOST_AGENT} ? INADDR_ANY : INADDR_LOOPBACK;
   if (defined $self->port) {
      bind $self->handle, sockaddr_in($self->port, $local_ip)
         or die "bind failed: $!\n";
   } else {
      my $port;
      for ($port=30000; $port<65536; ++$port) {
         last if bind $self->handle, sockaddr_in($port, $local_ip);
         die "bind failed: $!\n" if $! != EADDRINUSE;
      }
      if ($port==65536) {
         die "bind failed: all ports seem occupied\n";
      }
      $self->port=$port;
   }
   fcntl($self->handle, F_SETFD, FD_CLOEXEC);

   listen $self->handle, 1
      or die "listen failed: $!\n";
   $self;
}

sub translate_port {
   my ($port)=@_;
   if ($port > 0 && $ENV{POLYMAKE_HOST_AGENT}) {
      require "$Polymake::InstallTop/resources/host-agent/client.pl";
      $port=HostAgent::call("port $port");
   }
   $port
}

sub DESTROY {
   close($_[0]->handle);
}

sub fileno { fileno($_[0]->handle) }

sub accept {
   my ($self)=@_;
   accept my $s, $self->handle
      or die "accept failed: $!\n";
   $s->autoflush;
   $s;
}

####################################################################################
package Polymake::ClientSocket;
use Socket;

# Constructor: new ClientSocket(hostname, port) || new ClientSocket("named/socket/path")
sub new {
   shift;
   my $socket;
   if (@_==2) {
      my ($hostname, $port)=@_;
      my $hostaddr=inet_aton($hostname)
        or die "unknown host name $hostname\n";
      socket($socket, AF_INET, SOCK_STREAM, PF_UNSPEC)
        or die "can't create socket: $!\n";
      connect($socket, sockaddr_in($port, $hostaddr))
        or die "can't connect to $hostname: $!\n";
   } elsif (@_==1 && -S $_[0]) {
      socket($socket, AF_UNIX, SOCK_STREAM, PF_UNSPEC)
        or die "can't create socket: $!\n";
      connect($socket, sockaddr_un($_[0]))
        or die "can't connect to named socket $_[0]: $!\n";
   } else {
      die "ClientSocket constructor got neither a remote host:port combination nor a named socket\n";
   }
   $socket->autoflush;
   $socket;
}

####################################################################################
package Polymake::LocalServer;

use Polymake::Struct (
   [ '@ISA' => 'Selector::Member' ],
   [ new => '$$' ],
   [ '$server_socket' => 'undef' ],
   [ '$handler_pkg' => '#2' ],
   [ '$data_conn' => 'undef' ],
);

# Constructor: HandlerPackage [ , port ] =>

sub new {
   my $serv=new ServerSocket(splice @_, 2);
   my $self=Selector::Member::new($_[0], $serv->handle, $_[1]);
   $self->server_socket=$serv;
   $self;
}

sub in_avail {
   my $self=shift;
   $self->data_conn=$self->handler_pkg->new($self->server_socket->accept);
}

sub port { (shift)->server_socket->port }

1

# Local Variables:
# cperl-indent-level:3
# indent-tabs-mode:nil
# End: