Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

TCP and UDP ports should follow each other. bug67

  • Loading branch information...
commit 6dc28e905d7b9f7809f6e8c0e372588740c28e47 1 parent b8ff918
Dustin Sallings dustin authored dormando committed

Showing 2 changed files with 94 additions and 0 deletions. Show diff stats Hide diff stats

  1. +10 0 memcached.c
  2. +84 0 t/issue_67.t
10 memcached.c
@@ -4250,6 +4250,8 @@ int main (int argc, char **argv) {
4250 4250 /* udp socket */
4251 4251 static int *u_socket = NULL;
4252 4252 bool protocol_specified = false;
  4253 + bool tcp_specified = false;
  4254 + bool udp_specified = false;
4253 4255
4254 4256 /* handle SIGINT */
4255 4257 signal(SIGINT, sig_handler);
@@ -4297,9 +4299,11 @@ int main (int argc, char **argv) {
4297 4299
4298 4300 case 'U':
4299 4301 settings.udpport = atoi(optarg);
  4302 + udp_specified = true;
4300 4303 break;
4301 4304 case 'p':
4302 4305 settings.port = atoi(optarg);
  4306 + tcp_specified = true;
4303 4307 break;
4304 4308 case 's':
4305 4309 settings.socketpath = optarg;
@@ -4465,6 +4469,12 @@ int main (int argc, char **argv) {
4465 4469 }
4466 4470 }
4467 4471
  4472 + if (tcp_specified && !udp_specified) {
  4473 + settings.udpport = settings.port;
  4474 + } else if (udp_specified && !tcp_specified) {
  4475 + settings.port = settings.udpport;
  4476 + }
  4477 +
4468 4478 if (maxcore != 0) {
4469 4479 struct rlimit rlim_new;
4470 4480 /*
84 t/issue_67.t
... ... @@ -0,0 +1,84 @@
  1 +#!/usr/bin/perl
  2 +
  3 +use strict;
  4 +use Test::More tests => 22;
  5 +use FindBin qw($Bin);
  6 +use lib "$Bin/lib";
  7 +use MemcachedTest;
  8 +use Carp qw(croak);
  9 +
  10 +use Cwd;
  11 +my $builddir = getcwd;
  12 +
  13 +$ENV{'MEMCACHED_PORT_FILENAME'} = "/tmp/ports.$$";
  14 +
  15 +sub read_ports {
  16 + my %rv = ();
  17 + open(my $f, "/tmp/ports.$$") || die("Can't open ports file.");
  18 + while(<$f>) {
  19 + my ($type, $port) = split(/:\s+/);
  20 + $rv{$type} = $port + 0;
  21 + }
  22 + unlink "/tmp/ports.$$";
  23 + return %rv;
  24 +}
  25 +
  26 +sub validate_port {
  27 + my ($name, $got, $expected) = @_;
  28 + # diag "Wanted $expected, got $got";
  29 + if ($expected == -1) {
  30 + ok(!defined($got), "$name expected no port, got $got");
  31 + } elsif ($expected == 0) {
  32 + ok($got != 11211, "$name expected random port (got $got)");
  33 + } else {
  34 + is($got, $expected, "$name");
  35 + }
  36 +}
  37 +
  38 +sub run_server {
  39 + my ($args) = @_;
  40 +
  41 + my $exe = "$builddir/memcached-debug";
  42 + croak("memcached binary doesn't exist. Haven't run 'make' ?\n") unless -e $exe;
  43 +
  44 + my $childpid = fork();
  45 +
  46 + my $cmd = "$builddir/timedrun 10 $exe $args";
  47 +
  48 + unless($childpid) {
  49 + exec $cmd;
  50 + exit; # NOTREACHED
  51 + }
  52 +
  53 + for (1..20) {
  54 + if (-f "/tmp/ports.$$") {
  55 + return Memcached::Handle->new(pid => $childpid);
  56 + }
  57 + select undef, undef, undef, 0.10;
  58 + }
  59 + croak "Failed to start server.";
  60 +}
  61 +
  62 +sub when {
  63 + my ($name, $params, $expected_tcp, $expected_udp) = @_;
  64 +
  65 + my $server = run_server($params);
  66 + my %ports = read_ports();
  67 +
  68 + validate_port($name, $ports{'TCP INET'}, $expected_tcp);
  69 + validate_port($name, $ports{'UDP INET'}, $expected_udp);
  70 +}
  71 +
  72 +# Disabling the defaults since it conflicts with a running instance.
  73 +# when('no arguments', '', 11211, 11211);
  74 +when('specifying tcp port', '-p 11212', 11212, 11212);
  75 +when('specifying udp port', '-U 11222', 11222, 11222);
  76 +when('specifying tcp ephemeral port', '-p -1', 0, 0);
  77 +when('specifying udp ephemeral port', '-U -1', 0, 0);
  78 +when('tcp port disabled', '-p 0', -1, -1);
  79 +when('udp port disabled', '-U 0', -1, -1);
  80 +when('specifying tcp and udp ports', '-p 11232 -U 11233', 11232, 11233);
  81 +when('specifying tcp and disabling udp', '-p 11242 -U 0', 11242, -1);
  82 +when('specifying udp and disabling tcp', '-p -1 -U 11252', 0, 11252);
  83 +when('specifying tcp and ephemeral udp', '-p 11262 -U -1', 11262, 0);
  84 +when('specifying udp and ephemeral tcp', '-p -1 -U 11272', 0, 11272);

0 comments on commit 6dc28e9

Please sign in to comment.
Something went wrong with that request. Please try again.