Skip to content

Commit 7e90878

Browse files
author
bradfitz
committed
don't depend on MSG_NOSIGNAL (which isn't on FreeBSD/Solaris)
git-svn-id: http://code.sixapart.com/svn/memcached/trunk/api/perl@169 b0b603af-a30f-0410-a34e-baf09ae79d0b
1 parent 161b596 commit 7e90878

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

ChangeLog

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2003-11-08
2+
* work on Solaris/BSD where there's no MSG_NOSIGNAL.
3+
the expense is extra syscalls to change the local
4+
SIGPIPE handler all the time. in the future, it'd
5+
be nice to have an option so Solaris/BSD callers
6+
can say, "Hey, I've turned off SIGPIPE globally,
7+
don't worry about it."
8+
19
2003-10-26
210
* add a test file, so automated CPAN test hosts are happy
311
* check MSG_NOSIGNAL immediately on module load, not on use,

Memcached.pm

+15-10
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ use IO::Handle ();
1515

1616
BEGIN {
1717
eval "use Time::HiRes qw (alarm);";
18-
19-
# so it'll bomb during tests on Solaris, until we make it work
20-
$_ = MSG_NOSIGNAL;
2118
}
2219

2320
# flag definitions
@@ -27,11 +24,13 @@ use constant F_COMPRESS => 2;
2724
# size savings required before saving compressed value
2825
use constant COMPRESS_SAVINGS => 0.20; # percent
2926

30-
use vars qw($VERSION $HAVE_ZLIB);
27+
use vars qw($VERSION $HAVE_ZLIB $FLAG_NOSIGNAL);
3128
$VERSION = "1.0.12-pre";
3229

30+
$FLAG_NOSIGNAL = 0;
3331
BEGIN {
3432
$HAVE_ZLIB = eval "use Compress::Zlib (); 1;";
33+
$FLAG_NOSIGNAL = eval { MSG_NOSIGNAL } || 0;
3534
}
3635

3736
my %host_dead; # host -> unixtime marked dead until
@@ -218,10 +217,11 @@ sub delete {
218217
my $cmd = "delete $key$time\r\n";
219218
my $res = "";
220219

220+
local $SIG{'PIPE'} = "IGNORE" unless $FLAG_NOSIGNAL;
221221
local $SIG{'ALRM'} = sub { _dead_sock($sock); die "alarm"; };
222222
alarm($SOCK_TIMEOUT);
223223
eval {
224-
send($sock, $cmd, MSG_NOSIGNAL) ?
224+
send($sock, $cmd, $FLAG_NOSIGNAL) ?
225225
($res = readline($sock)) :
226226
_dead_sock($sock);
227227
alarm(0);
@@ -277,11 +277,12 @@ sub _set {
277277

278278
$exptime = int($exptime || 0);
279279

280+
local $SIG{'PIPE'} = "IGNORE" unless $FLAG_NOSIGNAL;
280281
local $SIG{'ALRM'} = sub { _dead_sock($sock); die "alarm"; };
281282
alarm($SOCK_TIMEOUT);
282283
my ($res, $line) = (0, "");
283284
eval {
284-
$res = send($sock, "$cmdname $key $flags $exptime $len\r\n$val\r\n", MSG_NOSIGNAL);
285+
$res = send($sock, "$cmdname $key $flags $exptime $len\r\n$val\r\n", $FLAG_NOSIGNAL);
285286
if ($res) {
286287
$line = readline($sock);
287288
$res = $line eq "STORED\r\n";
@@ -316,11 +317,12 @@ sub _incrdecr {
316317
$self->{'stats'}->{$cmdname}++;
317318
$value = 1 unless defined $value;
318319

320+
local $SIG{'PIPE'} = "IGNORE" unless $FLAG_NOSIGNAL;
319321
local $SIG{'ALRM'} = sub { _dead_sock($sock); die "alarm"; };
320322
alarm($SOCK_TIMEOUT);
321323
my $line;
322324
eval {
323-
send($sock, "$cmdname $key $value\r\n", MSG_NOSIGNAL) ?
325+
send($sock, "$cmdname $key $value\r\n", $FLAG_NOSIGNAL) ?
324326
$line = readline($sock) :
325327
_dead_sock($sock);
326328
alarm(0);
@@ -342,10 +344,11 @@ sub get {
342344

343345
my %val;
344346

347+
local $SIG{'PIPE'} = "IGNORE" unless $FLAG_NOSIGNAL;
345348
local $SIG{'ALRM'} = sub { _dead_sock($sock); die "alarm"; };
346349
alarm($SOCK_TIMEOUT);
347350
eval {
348-
send($sock, "get $key\r\n", MSG_NOSIGNAL) ?
351+
send($sock, "get $key\r\n", $FLAG_NOSIGNAL) ?
349352
_load_items($sock, \%val) :
350353
_dead_sock($sock, undef);
351354
alarm(0);
@@ -381,6 +384,7 @@ sub get_multi {
381384
$self->{'stats'}->{"get_keys"} += @_;
382385
$self->{'stats'}->{"get_socks"} += @socks;
383386

387+
local $SIG{'PIPE'} = "IGNORE" unless $FLAG_NOSIGNAL;
384388
local $SIG{'ALRM'} = sub { _dead_sock($sock); die "alarm"; };
385389

386390
# pass 1: send out requests
@@ -389,7 +393,7 @@ sub get_multi {
389393
alarm($SOCK_TIMEOUT);
390394
foreach my $sock (@socks) {
391395
eval {
392-
if (send($sock, "get @{$sock_keys{$sock}}\r\n", MSG_NOSIGNAL)) {
396+
if (send($sock, "get @{$sock_keys{$sock}}\r\n", $FLAG_NOSIGNAL)) {
393397
push @gather, $sock;
394398
} else {
395399
_dead_sock($sock);
@@ -470,10 +474,11 @@ sub run_command {
470474
my ($sock, $cmd) = @_;
471475
return () unless $sock;
472476
my @ret;
477+
local $SIG{'PIPE'} = "IGNORE" unless $FLAG_NOSIGNAL;
473478
local $SIG{'ALRM'} = sub { _dead_sock($sock); die "alarm"; };
474479
alarm($SOCK_TIMEOUT);
475480
eval {
476-
if (send($sock, $cmd, MSG_NOSIGNAL)) {
481+
if (send($sock, $cmd, $FLAG_NOSIGNAL)) {
477482
while (my $res = readline($sock)) {
478483
push @ret, $res;
479484
last if $res eq "END\r\n";

TODO

-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,2 @@
1-
-- MSG_NOSIGNAL is undefined on Solaris, so module is unusable.
2-
instead, should let callers choose to handle it themselves
3-
($SIG{'PIPE'} = "IGNORE";) or otherwise let the module do it
4-
itself, in which case it'll do MSG_NOSIGNAL if available,
5-
or localize $SIG{'PIPE'} everywhere, which is kinda slow.
6-
(lot of syscalls)
7-
81
-- provide option to not do remapping, to avoid the "netsplit
92
problem". (some apps might have a problem with that)

0 commit comments

Comments
 (0)