Subject: | Accept a timeout on Spread::connect |
Getting a spread handle takes time. We are preconnecting to spread in an
idle loop for a server. As such, we need time-bound connections to
spread.
Spread's C API supports this, it just wasn't available via the XS module.
So, I wrote the attached patch for the version of Spread in lenny.
Can you incorporate it into the CPAN version? Thanks :)
Subject: | spread-connect-timeout.patch |
commit 4db5f1e5917509cfd929a4ba4c43593074527372
Author: Sam Vilain <samv@build-sarge-amd64.wgtn.cat-it.co.nz>
Date: Fri Oct 13 14:23:40 2006 +1300
Implement timeout on Spread::connect()
Spread.pm did not allow a timeout on connect; allow it to take one.
diff --git a/perl/Spread/Spread.pm b/perl/Spread/Spread.pm
index 7b76d0e..7ca8223 100644
--- a/perl/Spread/Spread.pm
+++ b/perl/Spread/Spread.pm
@@ -158,6 +158,7 @@ sub connect {
$$aa{'private_name'} = $ENV{'USER'} unless defined($$aa{'private_name'});
$$aa{'priority'} = 0 unless defined($$aa{'priority'});
$$aa{'group_membership'} = 1 unless defined($$aa{'group_membership'});
+ $$aa{'timeout'} = 0 unless defined($$aa{'timeout'});
return connect_i($aa);
}
1;
diff --git a/perl/Spread/Spread.xs b/perl/Spread/Spread.xs
index bfcd7b0..388ec82 100644
--- a/perl/Spread/Spread.xs
+++ b/perl/Spread/Spread.xs
@@ -73,8 +73,9 @@ static char *connect_params[] = {
"private_name",
"priority",
"group_membership",
+ "timeout",
""};
-static int nconnect_params = 4;
+static int nconnect_params = 5;
SV *sv_NULL ;
@@ -504,6 +505,8 @@ GC_connect_i(rv)
SV **afetch;
int i, error, pr, gm;
mailbox mbox = -1;
+ sp_time timeout = { 0, 0 };
+ double timeout_v;
char *sn, *pn, pg[MAX_GROUP_NAME];
HV *hv;
PPCODE:
@@ -529,7 +532,17 @@ GC_connect_i(rv)
afetch = hv_fetch(hv, connect_params[i],
strlen(connect_params[i]), FALSE); i++;
gm = SvIV(*afetch);
- if((error = SP_connect(sn,pn,pr,gm,&mbox,pg))>0 && mbox>0) {
+ afetch = hv_fetch(hv, connect_params[i],
+ strlen(connect_params[i]), FALSE); i++;
+ if (SvNOK(*afetch)) {
+ timeout_v = SvNV(*afetch);
+ } else {
+ timeout_v = SvIV(*afetch);
+ }
+ timeout.sec = (unsigned long)timeout_v;
+ timeout.usec = (unsigned long)(1000000.0*(timeout_v-(double)timeout.sec));
+
+ if((error = SP_connect_timeout(sn,pn,pr,gm,&mbox,pg,timeout))>0 && mbox>0) {
MAILBOX = sv_2mortal(newSViv(mbox));
PRIVATE_GROUP = sv_2mortal(newSVpv(pg, 0));
} else {