mirror of
https://github.com/solemnwarning/ipxwrapper
synced 2024-12-30 16:45:37 +01:00
Improved bind tests.
Verify processes exiting abnormally don't hold onto addresses and check the error code when bind() fails.
This commit is contained in:
parent
4a63b807e2
commit
753280da5d
@ -38,6 +38,7 @@ use constant {
|
||||
NSPROTO_IPX => 1000,
|
||||
NSPROTO_SPX => 1256,
|
||||
NSPROTO_SPXII => 1257,
|
||||
WSAEADDRINUSE => 10048,
|
||||
};
|
||||
|
||||
my ($bind_type_a, $bind_proto_a);
|
||||
@ -124,7 +125,7 @@ shared_examples_for "bind address selection/reuse for one protocol" => sub
|
||||
|
||||
cmp_deeply(\@result, [
|
||||
{ net => "00:00:00:01", node => $remote_mac_a, sock => 1 },
|
||||
undef,
|
||||
{ errno => WSAEADDRINUSE },
|
||||
]);
|
||||
};
|
||||
|
||||
@ -137,7 +138,7 @@ shared_examples_for "bind address selection/reuse for one protocol" => sub
|
||||
|
||||
cmp_deeply(\@result, [
|
||||
{ net => "00:00:00:01", node => $remote_mac_a, sock => 1 },
|
||||
undef,
|
||||
{ errno => WSAEADDRINUSE },
|
||||
]);
|
||||
};
|
||||
|
||||
@ -208,7 +209,7 @@ shared_examples_for "bind address selection/reuse for one protocol" => sub
|
||||
]);
|
||||
|
||||
cmp_deeply([ $bind_b->result() ], [
|
||||
undef,
|
||||
{ errno => WSAEADDRINUSE },
|
||||
]);
|
||||
};
|
||||
|
||||
@ -227,7 +228,7 @@ shared_examples_for "bind address selection/reuse for one protocol" => sub
|
||||
]);
|
||||
|
||||
cmp_deeply([ $bind_b->result() ], [
|
||||
undef,
|
||||
{ errno => WSAEADDRINUSE },
|
||||
]);
|
||||
};
|
||||
|
||||
@ -338,6 +339,26 @@ shared_examples_for "bind address selection/reuse for one protocol" => sub
|
||||
{ net => "00:00:00:01", node => $remote_mac_a, sock => 1 },
|
||||
]);
|
||||
};
|
||||
|
||||
it "allows address reuse (between processes) if first process exits uncleanly" => sub
|
||||
{
|
||||
my $bind_a = IPXWrapper::Tool::Bind->new($remote_ip_a,
|
||||
$bind_type_a, $bind_proto_a, "00:00:00:00", $remote_mac_a, "1",
|
||||
"-e", # Forces early _exit()
|
||||
);
|
||||
|
||||
my $bind_b = IPXWrapper::Tool::Bind->new($remote_ip_a,
|
||||
$bind_type_b, $bind_proto_b, "00:00:00:00", $remote_mac_a, "1",
|
||||
);
|
||||
|
||||
cmp_deeply([ $bind_a->result() ], [
|
||||
{ net => "00:00:00:01", node => $remote_mac_a, sock => 1 },
|
||||
]);
|
||||
|
||||
cmp_deeply([ $bind_b->result() ], [
|
||||
{ net => "00:00:00:01", node => $remote_mac_a, sock => 1 },
|
||||
]);
|
||||
};
|
||||
};
|
||||
|
||||
describe "bind" => sub
|
||||
|
@ -56,11 +56,11 @@ sub new
|
||||
sock => $3,
|
||||
});
|
||||
}
|
||||
elsif($line eq "Failed")
|
||||
elsif($line =~ m/^Failed \(([0-9]+)\)$/)
|
||||
{
|
||||
push(@{ $self->{sockets} }, undef);
|
||||
push(@{ $self->{sockets} }, { errno => $1 });
|
||||
}
|
||||
elsif($line eq "Ready")
|
||||
elsif($line eq "Ready" || $line eq "Calling _exit")
|
||||
{
|
||||
return $self;
|
||||
}
|
||||
|
10
tools/bind.c
10
tools/bind.c
@ -20,6 +20,7 @@
|
||||
#include <wsipx.h>
|
||||
#include <wsnwlink.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
@ -38,6 +39,12 @@ int main(int argc, const char **argv)
|
||||
|
||||
for(int i = 1; i < argc; i += 5)
|
||||
{
|
||||
if(strcmp(argv[i], "-e") == 0)
|
||||
{
|
||||
printf("Calling _exit\n");
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
BOOL reuse = FALSE;
|
||||
if(strcmp(argv[i], "-r") == 0)
|
||||
{
|
||||
@ -56,6 +63,7 @@ int main(int argc, const char **argv)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s\n"
|
||||
"\t[-r] [-c] <type> <protocol> <network number> <node number> <socket number>\n"
|
||||
"\t[-e]\n"
|
||||
"\t...\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
@ -83,7 +91,7 @@ int main(int argc, const char **argv)
|
||||
printf("Bound socket to %s\n", bound_addr);
|
||||
}
|
||||
else{
|
||||
printf("Failed\n");
|
||||
printf("Failed (%u)\n", (unsigned int)(WSAGetLastError()));
|
||||
}
|
||||
|
||||
if(close)
|
||||
|
Loading…
x
Reference in New Issue
Block a user