Browse Source

Merge branch 'master' into test1

Conflicts:
	src/ckpool.h
	src/generator.c
master
Con Kolivas 9 years ago
parent
commit
527afb4f69
  1. 167
      pool/inc.php
  2. 6
      pool/page.php
  3. 2
      pool/page_userinfo.php
  4. 25
      pool/page_workers.php
  5. 14
      src/ckdb.c
  6. 41
      src/ckpool.c
  7. 11
      src/ckpool.h
  8. 16
      src/generator.c
  9. 35
      src/libckpool.c
  10. 17
      src/libckpool.h
  11. 2
      src/stratifier.c

167
pool/inc.php

@ -2,15 +2,15 @@
# #
function GBaseJS() function GBaseJS()
{ {
$g = "function hasCan(){var c0=document.getElementById('can0');c=document.getElementById('can');return !!(c0&&c&&c.getContext&&c.getContext('2d'));} $g = "function hasCan(){var c0=document.getElementById('can0');c=document.getElementById('can');return !!(c0 && c && c.getContext && c.getContext('2d'))}
function sep(d){ans={};var ar=d.split('\\t');var l=ar.length;for(var i=0;i<l;i++){var e=ar[i].indexOf('=');ans[ar[i].substr(0,e)]=ar[i].substr(e+1)};return ans} function sep(d){ans={};var ar=d.split('\\t');var l=ar.length;for(var i=0;i<l;i++){var e=ar[i].indexOf('=');ans[ar[i].substr(0,e)]=ar[i].substr(e+1)}return ans}
function dfmt(c,e){var d=new Date(e*1000);var DD,HH,MM;if(c['utc']){DD=d.getUTCDate();HH=d.getUTCHours();MM=d.getUTCMinutes()}else{DD=d.getDate();HH=d.getHours();MM=d.getMinutes()}var ans=''+DD+'/';if(HH<10){ans+='0'}ans+=''+HH+':';if(MM<10){ans+='0'}ans+=''+MM;return ans} function dfmt(c,e){var d=new Date(e*1000);var DD,HH,MM;if(c['utc']){DD=d.getUTCDate();HH=d.getUTCHours();MM=d.getUTCMinutes()}else{DD=d.getDate();HH=d.getHours();MM=d.getMinutes()}var ans=''+DD+'/';if(HH<10){ans += '0'}ans += ''+HH+':';if(MM<10){ans += '0'}ans += ''+MM;return ans}
function ccb(c,n){var e=document.getElementById(n);c[n]=(e&&e.checked)} function ccb(c,n){var e=document.getElementById(n);c[n]=(e&&e.checked)}
function gch(z,zm){if(z<0.5){return 0.5}if(z>(zm-0.5)){return(zm-0.5)}return z} function gch(z,zm){if(z<0.5){return 0.5}if(z>(zm-0.5)){return(zm-0.5)}return z}
function gchx(c,x){return gch(x*c['xm']+c['xo'],c['ctx'].canvas.width)} function gchx(c,x){return gch(x*c['xm']+c['xo'],c['ctx'].canvas.width)}
function gchy(c,y){return gch((1-y)*c['ym']+c['yo'],c['ctx'].canvas.height)} function gchy(c,y){return gch((1-y)*c['ym']+c['yo'],c['ctx'].canvas.height)}
function gx0(c){return -c['xo']/c['xm']}; function gx0(c){return -c['xo']/c['xm']}
function gy0(c){return -c['yo']/c['ym']}; function gy0(c){return -c['yo']/c['ym']}
function gto(c,xo,yo){c['xo']+=xo;c['yo']+=yo} function gto(c,xo,yo){c['xo']+=xo;c['yo']+=yo}
function gts(c,xs,ys){c['xm']*=xs;c['ym']*=ys} function gts(c,xs,ys){c['xm']*=xs;c['ym']*=ys}
function gtso(c,xs,ys){gto(c,c['xm']*(1.0-xs)/2.0,c['ym']*(1.0-ys)/2.0);gts(c,xs,ys)} function gtso(c,xs,ys){gto(c,c['xm']*(1.0-xs)/2.0,c['ym']*(1.0-ys)/2.0);gts(c,xs,ys)}
@ -27,34 +27,9 @@ function gfl(c){c['ctx'].fill()}
function gst(c){c['ctx'].stroke()} function gst(c){c['ctx'].stroke()}
function gfi(c){gle(c);gst(c)} function gfi(c){gle(c);gst(c)}
function gbd(c){gbe(c,0,0);gln(c,1,0);gln(c,1,1);gln(c,0,1);gle(c);gfl(c);gst(c)} function gbd(c){gbe(c,0,0);gln(c,1,0);gln(c,1,1);gln(c,0,1);gle(c);gfl(c);gst(c)}
function ggr(c,xs,ys,yt,xn,x0,x1,y0,y1,ar,nx,vx,vy,av,w,cols){ function ggr(c,xs,ys,yt,xn,x0,x1,y0,y1,ar,nx,vx,vy,av,w,cols){gtso(c,xs,ys);gss(c,'black');glw(c,1.5);gbe(c,0,1);gln(c,0,0);gln(c,1,0);gst(c);glw(c,0.2);var hi=c['ctx'].measureText('M').width, wi=c['ctx'].measureText('1').width;for(var i=0;i<11;i++){var y=i/10.0;gbe(c,-0.01,y);gln(c,1,y);gst(c);var t=''+(((y1-y0)*i/10+y0).toFixed(2));gfz(c,0,y,-wi,0,t,'black','end')}gfz(c,gx0(c),0.55,wi,0,yt,'#0080ff','left');var m=Math.round(0.5+xn/20.0);for(var i=0;i<xn;i++){var n=ar[nx+i];var x=ar[vx+i];var xo=(x-x0)/(x1-x0);if(c['skey'] && (i<(xn-1)) && (i%m) == 0){gbe(c,xo,0);gln(c,xo,-0.01);gst(c);gfz(c,xo,0,0,-hi*1.5,n,'#00a050','center')}if(c['slines']){gbe(c,xo,0);gln(c,xo,1);gst(c)}}var xhr=3600+x1-(x1%3600);gss(c,'brown');if(c['tkey'] || c['tlines']){var hlv=c['hln'][c['hl']];hrs=c['hrs'][c['hr']]*3600/hlv;var l=0;tpos=2.7;if(c['over']){tpos=1.5}for(var i=xhr;i>=x0;i-=hrs){var n=dfmt(c,i);var xo=(i-x0)/(x1-x0);if(xo<=1 && c['tkey'] && ((l%hlv)==0)){gbe(c,xo,0);gln(c,xo,-0.02);gst(c);gfz(c,xo,0,0,-hi*tpos,n,'brown','center')}if(xo<=1 && c['tlines']){gbe(c,xo,0);gln(c,xo,1);gst(c)}l++}}glw(c,1);if(c['smooth']){for(var j=1;j<w.length;j++){var f=1;gss(c,cols[j-1]);var xa=0,ya=0,xb=0,yb=0;for(var i=0;i<xn;i++){var x=ar[vx+i];var y=ar[w[j]+vy+i];var xo=(x-x0)/(x1-x0);var yo=(y-y0)/(y1-y0);if(f==1){gbe(c,xo,yo);f=0;xb=xo;yb=yo}else{gct(c,(xa+xb)/2,(ya+yb)/2,xb,yb,(xb+xo)/2,(yb+yo)/2)}xa=xb;ya=yb;xb=xo;yb=yo}gct(c,(xa+xb)/2,(ya+yb)/2,xo,yo,xo,yo);gst(c)}}else{for(var j=1;j<w.length;j++){var f=1;gss(c,cols[j-1]);for(var i=0;i<xn;i++){var x=ar[vx+i];var y=ar[w[j]+vy+i];var xo=(x-x0)/(x1-x0);var yo=(y-y0)/(y1-y0);if(f==1){gbe(c,xo,yo);f=0}else{gln(c,xo,yo)}}gst(c)}}glw(c,1);for(var j=1;j<w.length;j++){if(av[j-1]>0){gss(c,'red');var y=(av[j-1]-y0)/(y1-y0);gbe(c,0,y);gln(c,1,y);gst(c);var t=''+av[j-1].toFixed(2)+'av';gfz(c,1,y,1,0,t,cols[j-1],'left')}}if(c['tkey']){var col,hrl=c['hrs'].length;for(var i=0;i<hrl;i++){if(c['hr']==i){col='red'}else{col='black'}gfz(c,1,0,c['xo']-c['pxe'],hi*(i+1)*2,''+c['hrs'][i],col,'end')}for(var i=0;i<c['hln'].length;i++){if(c['hl']==i){col='red'}else{col='black'}gfz(c,1,0,c['xo']-c['pxe'],hi*(i+2+hrl)*2,''+c['hrs'][i],col,'end')}}}
gtso(c,xs,ys);
gss(c,'black');glw(c,1.5);
gbe(c,0,1);gln(c,0,0);gln(c,1,0);gst(c);
glw(c,0.2);
var hi=c['ctx'].measureText('M').width, wi=c['ctx'].measureText('1').width;
for(var i=0;i<11;i++){var y=i/10.0;gbe(c,-0.01,y);gln(c,1,y);gst(c);var t=''+(((y1-y0)*i/10+y0).toFixed(2));gfz(c,0,y,-wi,0,t,'black','end')}
gfz(c,gx0(c),0.55,wi,0,yt,'#0080ff','left');
var m=Math.round(0.5+xn/20.0);
for(var i=0;i<xn;i++){var n=ar[nx+i];var x=ar[vx+i];var xo=(x-x0)/(x1-x0);if(c['skey']&&(i<(xn-1))&&(i%m)==0){gbe(c,xo,0);gln(c,xo,-0.01);gst(c);gfz(c,xo,0,0,-hi*1.5,n,'#00a050','center')}if(c['slines']){gbe(c,xo,0);gln(c,xo,1);gst(c)}}
var xhr=3600+x1-(x1%3600);
gss(c,'brown');
if(c['tkey']||c['tlines']){var hlv=c['hln'][c['hl']];hrs=c['hrs'][c['hr']]*3600/hlv;
var l=0;tpos=2.7;if(c['over']){tpos=1.5}
for(var i=xhr;i>=x0;i-=hrs){var n=dfmt(c,i);var xo=(i-x0)/(x1-x0);if(xo<=1&&c['tkey']&&((l%hlv)==0)){gbe(c,xo,0);gln(c,xo,-0.02);gst(c);gfz(c,xo,0,0,-hi*tpos,n,'brown','center')}if(xo<=1&&c['tlines']){gbe(c,xo,0);gln(c,xo,1);gst(c)}l++}}
glw(c,1);
if(c['smooth']){for(var j=1;j<w.length;j++){var f=1;gss(c,cols[j-1]);
var xa=0,ya=0,xb=0,yb=0;
for(var i=0;i<xn;i++){var x=ar[vx+i];var y=ar[w[j]+vy+i];var xo=(x-x0)/(x1-x0);var yo=(y-y0)/(y1-y0);if(f==1){gbe(c,xo,yo);f=0;xb=xo;yb=yo}else{gct(c,(xa+xb)/2,(ya+yb)/2,xb,yb,(xb+xo)/2,(yb+yo)/2)}xa=xb;ya=yb;xb=xo;yb=yo}gct(c,(xa+xb)/2,(ya+yb)/2,xo,yo,xo,yo);gst(c);}}
else{for(var j=1;j<w.length;j++){var f=1;gss(c,cols[j-1]);
for(var i=0;i<xn;i++){var x=ar[vx+i];var y=ar[w[j]+vy+i];var xo=(x-x0)/(x1-x0);var yo=(y-y0)/(y1-y0);if(f==1){gbe(c,xo,yo);f=0}else{gln(c,xo,yo)}}gst(c);}}
glw(c,1);
for(var j=1;j<w.length;j++){if(av[j-1]>0){gss(c,'red');var y=(av[j-1]-y0)/(y1-y0);gbe(c,0,y);gln(c,1,y);gst(c);
var t=''+av[j-1].toFixed(2)+'av';gfz(c,1,y,1,0,t,cols[j-1],'left')}}
if(c['tkey']){var col,hrl=c['hrs'].length;for(var i=0;i<hrl;i++){if(c['hr']==i){col='red'}else{col='black'}gfz(c,1,0,c['xo']-c['pxe'],hi*(i+1)*2,''+c['hrs'][i],col,'end')}for(var i=0;i<c['hln'].length;i++){if(c['hl']==i){col='red'}else{col='black'}gfz(c,1,0,c['xo']-c['pxe'],hi*(i+2+hrl)*2,''+c['hrs'][i],col,'end')}}
}
function sn(i,shi){if(shi.indexOf(' Shift ')<0){return ''+(i%10)}else{return shi.replace(/.* ([a-z])[a-z]*$/,'$1')}} function sn(i,shi){if(shi.indexOf(' Shift ')<0){return ''+(i%10)}else{return shi.replace(/.* ([a-z])[a-z]*$/,'$1')}}
function gc(c){var div=document.getElementById('can0');while(div.firstChild){div.removeChild(div.firstChild)}c['can']=document.createElement('canvas');c['can'].id='can';c['wx']=window.innerWidth;c['wy']=window.innerHeight;c['xm']=Math.max(Math.round(c['wx']*0.9+0.5),400);c['ym']=Math.max(Math.round(c['wy']*0.8+0.5),400);if(c['ym']>c['xm']){c['ym']=c['xm']}c['xo']=0.0;c['yo']=0.0;c['ctx']=c['can'].getContext('2d');c['ctx'].canvas.width=c['xm']+1;c['ctx'].canvas.height=c['ym']+1;div.appendChild(c['can']);c['pxe']=Math.max(Math.round(c['xm']/250),1)} function gc(c){var div=document.getElementById('can0');while (div.firstChild){div.removeChild(div.firstChild)}c['can']=document.createElement('canvas');c['can'].id='can';c['wx']=window.innerWidth;c['wy']=window.innerHeight;c['xm']=Math.max(Math.round(c['wx']*0.9+0.5),400);c['ym']=Math.max(Math.round(c['wy']*0.8+0.5),400);if(c['ym']>c['xm']){c['ym']=c['xm']}c['xo']=0.0;c['yo']=0.0;c['ctx']=c['can'].getContext('2d');c['ctx'].canvas.width=c['xm']+1;c['ctx'].canvas.height=c['ym']+1;div.appendChild(c['can']);c['pxe']=Math.max(Math.round(c['xm']/250),1)}
function opts(t,i){var e=document.getElementById(i);if(t.checked){e.style.visibility='visible'}else{e.style.visibility='hidden'}} function opts(t,i){var e=document.getElementById(i);if(t.checked){e.style.visibility='visible'}else{e.style.visibility='hidden'}}
function ghrs(c){c['hrs']=[1,2,3,4,6,8,12,24,48];c['hln']=[1,2,3,4,6]} function ghrs(c){c['hrs']=[1,2,3,4,6,8,12,24,48];c['hln']=[1,2,3,4,6]}
function ghg(c,dx){var tl=dx/(gchx(c,1)/50)/3600;for(var j=c['hrs'].length-1;j>=0;j--){if(tl<c['hrs'][j]){c['hr']=j}else{break}}if(tl<0.5){var tb=1/tl;for(var k=0;k<c['hln'].length;k++){if(c['hln'][k]<tb){c['hl']=k}else{break}}}else{c['hl']=1}} function ghg(c,dx){var tl=dx/(gchx(c,1)/50)/3600;for(var j=c['hrs'].length-1;j>=0;j--){if(tl<c['hrs'][j]){c['hr']=j}else{break}}if(tl<0.5){var tb=1/tl;for(var k=0;k<c['hln'].length;k++){if(c['hln'][k]<tb){c['hl']=k}else{break}}}else{c['hl']=1}}
@ -71,14 +46,14 @@ function tip(i,n){var e=document.getElementById(i);if(e){if(e.style.visibility==
"; ";
return $t; return $t;
} }
#
function TipsCSS() function TipsCSS()
{ {
$c = "span.tip0 {position:absolute;z-index:42;pointer-events:none;font-size:smaller;text-align:left;} $c = "span.tip0 {position:absolute;z-index:42;pointer-events:none;font-size:smaller;text-align:left;}
span.notip {position:relative;color:#0077ee;background:#bbffff;border-style:solid;border-color:black;border-width:1px;left:-10px;width:200px;padding:2px;float:left;transition:visibility 0.5s,opacity 0.5s;visibility:hidden;opacity:0} span.notip {position:relative;color:#0077ee;background:#bbffff;border-style:solid;border-color:black;border-width:1px;left:-10px;width:200px;padding:2px;float:left;transition:visibility 0.5s,opacity 0.5s;visibility:hidden;opacity:0;}
span.tip {visibility: visibile;} span.tip {visibility:visibile;}
span.q {position: relative; width: 16px; height: 16px; display: inline-block; background-color: #0077ee; line-height: 16px; color: White; font-size: 13px; font-weight: bold; border-radius: 8px; text-align: center; cursor: pointer;} span.q {position:relative;width:16px;height:16px;display:inline-block;background-color:#0077ee;line-height:16px;color:White;font-size:13px;font-weight:bold;border-radius:8px;text-align:center;cursor:pointer;}
ul.tip {margin-top:0;margin-bottom:0;list-style:disc inside none;margin-left:0;padding-left:0.5em;display:block} ul.tip {margin-top:0;margin-bottom:0;list-style:disc inside none;margin-left:0;padding-left:0.5em;display:block;}
li {padding-left:0.5em;} li {padding-left:0.5em;}
"; ";
return $c; return $c;
@ -86,77 +61,89 @@ li {padding-left:0.5em;}
# #
function HeadJS() function HeadJS()
{ {
$h = "function gcn(n){var ans='',d=document.cookie;if(d){var c0=d.indexOf(n+'='),cs=d.indexOf(' '+n+'=');if(c0==0||cs>0){if(cs>0){c0=cs+1}var c=d.substr(c0).split(';',1);var e=c[0].indexOf('=');if(e>0){ans=c[0].substr(e+1)}}}return ans} $h = "function gcn(n){var ans='',d=document.cookie;if(d){var c0=d.indexOf(n+'='),cs=d.indexOf(' '+n+'=');if(c0==0 || cs>0){if(cs>0){c0=cs+1}var c=d.substr(c0).split(';',1);var e=c[0].indexOf('=');if(e>0){ans=c[0].substr(e+1)}}}return ans}
function scnv(n,v){var d=new Date();d.setTime(d.getTime()+(864*Math.pow(10,8)));document.cookie=n+'='+v+'; expires='+d.toUTCString()+'; path=/'} function scnv(n,v){var d=new Date();d.setTime(d.getTime()+(864*Math.pow(10,8)));document.cookie=n+'='+v+';expires='+d.toUTCString()+';path=/'}
function ni(e,o){if(e){if(o==0){e.defd=e.style.display;e.style.display='none'}else{e.style.display=e.defd}}} function ni(e,o){if(e){if(o==0){e.defd=e.style.display;e.style.display='none'}else{e.style.display=e.defd}}}
function domin(o){var e=document.getElementById('minicb');if(e){if(o==0){e.checked=true}else{e.checked=false}};for(var i=0;i<10;i++){e=document.getElementById('mini'+i);ni(e,o)}} function domin(o){var e=document.getElementById('minicb');if(e){if(o==0){e.checked=true}else{e.checked=false}}for(var i=0;i<10;i++){e=document.getElementById('mini'+i);ni(e,o)}}
function mini(){var hm=gcn('mini');if(hm==''){domin(1)}else{domin(0)}} function mini(){var hm=gcn('mini');if(hm==''){domin(1)}else{domin(0)}}
function md(e){var c='';if(e.checked){c='y'}scnv('mini',c);mini()} function md(e){var c='';if(e.checked){c='y'}scnv('mini',c);mini()}
function tim(){var e=document.getElementById('ftr');if(e){var now=new Date(),t=document.createTextNode(now.toLocaleString());e.appendChild(t)}} function tim(){var e=document.getElementById('ftr');if(e){var now=new Date(),t=document.createTextNode(now.toLocaleString());e.appendChild(t)}}
function jst(){var e=document.getElementById('jst');if(e){e.style.visibility='hidden'}}"; function jst(){var e=document.getElementById('jst');if(e){e.style.visibility='hidden'}}
";
return $h; return $h;
} }
# #
function HeadCSS($iCrap = false) function HeadCSS($iCrap = false)
{ {
$h = "input[type=checkbox] {vertical-align: -2px;} $h = "input[type=checkbox] {vertical-align:-2px;}
form {display: inline-block;} form {display:inline-block;}
html, body {height: 100%; font-family:Arial, Verdana, sans-serif; font-size:12pt; background-color:#eeffff; text-align: center; background-repeat: no-repeat; background-position: center;} html, body {height:100%;font-family:Arial, Verdana, sans-serif;font-size:12pt;background-color:#eeffff;text-align:center;background-repeat:no-repeat;background-position:center;}
.page {min-height: 100%; height: auto !important; height: 100%; margin: 0 auto -50px; position: relative;} .page {min-height:100%;height:auto !important;height:100%;margin:0 auto -50px;position:relative;}
div.jst {color:red; font-weight: bold; font-size: 8; text-align: center; vertical-align: top;} div.jst {color:red;font-weight:bold;font-size:8;text-align:center;vertical-align:top;}
div.accwarn {color:red; font-weight: bold; font-size: 8; text-align: center; vertical-align: top;} div.accwarn {color:red;font-weight:bold;font-size:8;text-align:center;vertical-align:top;}
div.topd {background-color:#cff; border-color: #cff; border-style: solid; border-width: 9px;} div.topd {background-color:#cff;border-color:#cff;border-style:solid;border-width:9px;}
.topdes {color:blue; text-align: right;} .topdes {color:blue;text-align:right;}
.topdesl {color:blue; text-align: left;} .topdesl {color:blue;text-align:left;}
.topwho {color:black; font-weight: bold; margin-right: 8px;} .topwho {color:black;font-weight:bold;margin-right:8px;}
.topdat {margin-left: 8px; margin-right: 24px; color:green; font-weight: bold;} .topdat {margin-left:8px;margin-right:24px;color:green;font-weight:bold;}
span.nb {white-space: pre;} span.nb {white-space:pre;}
span.login {float: right; margin-left: 8px; margin-right: 24px;} span.login {float:right;margin-left:8px;margin-right:24px;}
span.hil {color:blue;} span.hil {color:blue;}
span.user {color:green;} span.user {color:green;}
span.addr {color:brown;} span.addr {color:brown;}
span.warn {color:orange; font-weight:bold;} span.warn {color:orange;font-weight:bold;}
span.urg {color:red; font-weight:bold;} span.urg {color:red;font-weight:bold;}
span.err {color:red; font-weight:bold; font-size:120%;} span.err {color:red;font-weight:bold;font-size:120%;}
span.alert {color:red; font-weight:bold; font-size:250%;} span.alert {color:red;font-weight:bold;font-size:250%;}
input.tiny {width: 0px; height: 0px; margin: 0px; padding: 0px; outline: none; border: 0px;} input.tiny {width:0px;height:0px;margin:0px;padding:0px;outline:none;border:0px;}
#n42 {margin:0; position: relative; color:#ffffff; background:#0077ee;} #n42 {margin:0;position:relative;color:#ffffff;background:#0077ee;}
#n42 a {color:#fff; text-decoration:none; padding: 6px; display:block;} #n42 a {color:#fff;text-decoration:none;padding:6px;display:block;}
#n42 td {min-width: 100px; float: left; vertical-align: top; padding: 0px 2px;} #n42 td {min-width:100px;float:left;vertical-align:top;padding:0px 2px;}
#n42 td.navboxr {float: right;} #n42 td.navboxr {float:right;}
#n42 td.nav {position: relative;} #n42 td.nav {position:relative;}
#n42 td.ts {border-width: 1px; border-color: #0022ee; border-style: solid none none none;}"; #n42 td.ts {border-width:1px;border-color:#0022ee;border-style:solid none none none;}
";
if (!$iCrap) if (!$iCrap)
{ {
$h .= " $h .= "#n42 div.sub {left:0px;z-index:42;position:absolute;visibility:hidden;}
#n42 div.sub {left: 0px; z-index: 42; position: absolute; visibility: hidden;}
#n42 td.nav:hover {background:#0099ee;} #n42 td.nav:hover {background:#0099ee;}
#n42 td.nav:hover div.sub {background:#0077ee; visibility: visible;}"; #n42 td.nav:hover div.sub {background:#0077ee;visibility:visible;}
";
} }
$h .= " $h .= "h1 {margin-top:20px;float:middle;font-size:20px;}
h1 {margin-top: 20px; float:middle; font-size: 20px;} .foot, .push {height:50px;}
.foot, .push {height: 50px;} .title {background-color:#909090;}
.title {background-color: #909090;} .even {background-color:#cccccc;}
.even {background-color: #cccccc;} .odd {background-color:#a8a8a8;}
.odd {background-color: #a8a8a8;} .hid {display:none;}
.hid {display: none;} .dl {text-align:left;padding:2px 8px;}
.dl {text-align: left; padding: 2px 8px;} .dr {text-align:right;padding:2px 8px;}
.dr {text-align: right; padding: 2px 8px;} .dc {text-align:center;padding:2px 8px;}
.dc {text-align: center; padding: 2px 8px;} .dls {text-align:left;padding:2px 8px;text-decoration:line-through;font-weight:lighter;}
.dls {text-align: left; padding: 2px 8px; text-decoration:line-through; font-weight:lighter;} .drs {text-align:right;padding:2px 8px;text-decoration:line-through;font-weight:lighter;}
.drs {text-align: right; padding: 2px 8px; text-decoration:line-through; font-weight:lighter;} .dcs {text-align:center;padding:2px 8px;text-decoration:line-through;font-weight:lighter;}
.dcs {text-align: center; padding: 2px 8px; text-decoration:line-through; font-weight:lighter;}
.st0 {font-weight:bold;} .st0 {font-weight:bold;}
.st1 {color:red; font-weight:bold;} .st1 {color:red;font-weight:bold;}
.st2 {color:green; font-weight:bold;} .st2 {color:green;font-weight:bold;}
.st3 {color:blue; font-weight:bold;} .st3 {color:blue;font-weight:bold;}
.fthi {color:red; font-size:7px;} .fthi {color:red;font-size:7px;}
.ftlo {color:green; font-size:7px;} .ftlo {color:green;font-size:7px;}
.ft {color:blue; font-size:7px;} .ft {color:blue;font-size:7px;}
.ftl {text-align: left; color:blue; font-size:7px; display:inline-block; width:20%; white-space: nowrap;} .ftl {text-align:left;color:blue;font-size:7px;display:inline-block;width:20%;white-space:nowrap;}
.ftm {text-align: middle; font-size:10pt; display:inline-block; width:60%; white-space: nowrap;} .ftm {text-align:middle;font-size:10pt;display:inline-block;width:60%;white-space:nowrap;}
.ftr {text-align: rigth; color:blue; font-size:7px; display:inline-block; width:20%; white-space: nowrap;}"; .ftr {text-align:rigth;color:blue;font-size:7px;display:inline-block;width:20%;white-space:nowrap;}
";
return $h; return $h;
} }
# #
function SortJS()
{
$s = "function sot(t,s,o){if(t && s>=0){var rs=t.rows;if(rs && rs.length>2){var all=[], rn, ok=true;for(rn=1;rn<rs.length-1;rn++){if(rs[rn]){var c=rs[rn].cells[s];if(c){var key=c.getAttribute('data-srt');if(key){all.push([rs[rn],key])}else{all.push([rs[rn],c.innerHTML])}}else{ok=false}}else{ok=false}}if(ok){if(o=='s'){all.sort(function(a,b){return a[1].localeCompare(b[1])})}if(o=='n'){all.sort(function(a,b){return a[1]-b[1]})}if(o=='r'){all.sort(function(a,b){return b[1]-a[1]})}for(rn=0;rn<all.length;rn++){t.removeChild(all[rn][0])}var b4=t.lastChild;for(rn=0;rn<all.length;rn++){t.insertBefore(all[rn][0], b4);if(rn%2){all[rn][0].className='odd'}else{all[rn][0].className='even'}}}}}}
function sott(cn,t){if(t){var sf=t.getAttribute('data-sf');var o=sf.substring(0,1);var s=Number(sf.substring(1));var id=t.id;scnv(cn,id);t.checked=true;sot(t.parentNode.parentNode.parentNode.parentNode,s,o)}}
function sotn(cn,n){var e=document.getElementById(n);if(e){sott(cn,e)}}
function sotc(cn,d){var ws=gcn(cn);if(ws==''){ws=d}sotn(cn,ws)}
";
return $s;
}
#
?> ?>

6
pool/page.php

@ -66,6 +66,11 @@ function addTips()
addCSS($tcss); addCSS($tcss);
} }
# #
function addSort()
{
$s = SortJS();
addScript($s);
}
# #
function makeURL($page) function makeURL($page)
{ {
@ -75,6 +80,7 @@ function makeURL($page)
$page = '?k='.$page; $page = '?k='.$page;
return "/index.php$page"; return "/index.php$page";
} }
#
function makeLink($page, $rest = '') function makeLink($page, $rest = '')
{ {
$href = "<a href='".makeURL($page)."'"; $href = "<a href='".makeURL($page)."'";

2
pool/page_userinfo.php

@ -19,7 +19,7 @@ function douserinfo($data, $user)
$ans = getUserInfo($user); $ans = getUserInfo($user);
$pg = '<h1>Block Acclaim</h1>'.$pg; $pg = '<h1>Block Acclaim</h1>';
$pg .= "<table callpadding=0 cellspacing=0 border=0>\n"; $pg .= "<table callpadding=0 cellspacing=0 border=0>\n";
$pg .= "<tr class=title>"; $pg .= "<tr class=title>";
$pg .= "<td class=dl>User</td>"; $pg .= "<td class=dl>User</td>";

25
pool/page_workers.php

@ -2,15 +2,17 @@
# #
function worktitle($data, $user) function worktitle($data, $user)
{ {
addSort();
$r = "input type=radio name=srt onclick=\"sott('worksrt',this);\"";
$pg = '<tr class=title>'; $pg = '<tr class=title>';
$pg .= '<td class=dl>Worker Name</td>'; $pg .= "<td class=dl>Worker <span class=nb>Name:<$r id=srtwrk data-sf=s0></span></td>";
$pg .= '<td class=dr>Work Diff</td>'; $pg .= '<td class=dr>Work Diff</td>';
$pg .= '<td class=dr>Last Share</td>'; $pg .= "<td class=dr><span class=nb><$r id=srtlst data-sf=n2>:Last</span> Share</td>";
$pg .= '<td class=dr>Shares</td>'; $pg .= '<td class=dr>Shares</td>';
$pg .= '<td class=dr>Diff</td>'; $pg .= "<td class=dr><span class=nb><$r id=srtdiff data-sf=r4>:Diff</span></td>";
$pg .= '<td class=dr>Invalid</td>'; $pg .= '<td class=dr>Invalid</td>';
$pg .= '<td class=dr>Block %</td>'; $pg .= '<td class=dr>Block %</td>';
$pg .= '<td class=dr>Hash Rate</td>'; $pg .= "<td class=dr><span class=nb><$r id=srtrate data-sf=r7>:Hash</span> Rate</td>";
$pg .= "</tr>\n"; $pg .= "</tr>\n";
return $pg; return $pg;
} }
@ -86,14 +88,15 @@ function workuser($data, $user, &$offset, &$totshare, &$totdiff,
$ld = '&nbsp;'; $ld = '&nbsp;';
$pg .= "<td class=dr>$ld</td>"; $pg .= "<td class=dr>$ld</td>";
$pg .= '<td class=dr>'.howlongago($lst).'</td>'; $pg .= "<td class=dr data-srt=$lst>".howlongago($lst).'</td>';
$shareacc = number_format($all[$i]['w_shareacc'], 0); $shareacc = number_format($all[$i]['w_shareacc'], 0);
$totshare += $all[$i]['w_shareacc']; $totshare += $all[$i]['w_shareacc'];
$diffacc = number_format($all[$i]['w_diffacc'], 0); $diffacc = number_format($all[$i]['w_diffacc'], 0);
$ds = round($all[$i]['w_diffacc']);
$totdiff += $all[$i]['w_diffacc']; $totdiff += $all[$i]['w_diffacc'];
$pg .= "<td class=dr>$shareacc</td>"; $pg .= "<td class=dr>$shareacc</td>";
$pg .= "<td class=dr>$diffacc</td>"; $pg .= "<td class=dr data-srt=$ds>$diffacc</td>";
$dtot = $all[$i]['w_diffacc'] + $all[$i]['w_diffinv']; $dtot = $all[$i]['w_diffacc'] + $all[$i]['w_diffinv'];
if ($dtot > 0) if ($dtot > 0)
@ -113,13 +116,17 @@ function workuser($data, $user, &$offset, &$totshare, &$totdiff,
$uhr = $all[$i]['w_uhr']; $uhr = $all[$i]['w_uhr'];
if ($uhr == '?') if ($uhr == '?')
{
$uhr = '?GHs'; $uhr = '?GHs';
$su = 0;
}
else else
{ {
$su = round($uhr);
$totrate += $uhr; $totrate += $uhr;
$uhr = dsprate($uhr); $uhr = dsprate($uhr);
} }
$pg .= "<td class=dr>$uhr</td>"; $pg .= "<td class=dr data-srt=$su>$uhr</td>";
$pg .= "</tr>\n"; $pg .= "</tr>\n";
@ -137,7 +144,7 @@ function worktotal($offset, $totshare, $totdiff, $totinvalid, $totrate, $blockac
$row = 'even'; $row = 'even';
else else
$row = 'odd'; $row = 'odd';
$pg .= "<tr class=$row><td class=dl>Total:</td><td colspan=2 class=dl></td>"; $pg .= "<tr class=$row><td class=dl>Total: $offset</td><td colspan=2 class=dl></td>";
$shareacc = number_format($totshare, 0); $shareacc = number_format($totshare, 0);
$pg .= "<td class=dr>$shareacc</td>"; $pg .= "<td class=dr>$shareacc</td>";
$diffacc = number_format($totdiff, 0); $diffacc = number_format($totdiff, 0);
@ -187,6 +194,8 @@ function doworker($data, $user)
} }
$pg .= "</table>\n"; $pg .= "</table>\n";
$pg .= "<script type='text/javascript'>\n";
$pg .= "sotc('worksrt','srtrate');</script>\n";
return "<h1>Workers$title</h1>".$pg; return "<h1>Workers$title</h1>".$pg;
} }

14
src/ckdb.c

@ -561,7 +561,8 @@ void logmsg(int loglevel, const char *fmt, ...)
int logfd = 0; int logfd = 0;
char *buf = NULL; char *buf = NULL;
struct tm tm; struct tm tm;
time_t now_t; tv_t now_tv;
int ms;
va_list ap; va_list ap;
char stamp[128]; char stamp[128];
char *extra = EMPTY; char *extra = EMPTY;
@ -572,8 +573,9 @@ void logmsg(int loglevel, const char *fmt, ...)
if (loglevel > global_ckp->loglevel) if (loglevel > global_ckp->loglevel)
return; return;
now_t = time(NULL); tv_time(&now_tv);
localtime_r(&now_t, &tm); ms = (int)(now_tv.tv_usec / 1000);
localtime_r(&(now_tv.tv_sec), &tm);
minoff = tm.tm_gmtoff / 60; minoff = tm.tm_gmtoff / 60;
if (minoff < 0) { if (minoff < 0) {
tzch = '-'; tzch = '-';
@ -591,13 +593,13 @@ void logmsg(int loglevel, const char *fmt, ...)
tzch, hroff); tzch, hroff);
} }
snprintf(stamp, sizeof(stamp), snprintf(stamp, sizeof(stamp),
"[%d-%02d-%02d %02d:%02d:%02d%s]", "[%d-%02d-%02d %02d:%02d:%02d.%03d%s]",
tm.tm_year + 1900, tm.tm_year + 1900,
tm.tm_mon + 1, tm.tm_mon + 1,
tm.tm_mday, tm.tm_mday,
tm.tm_hour, tm.tm_hour,
tm.tm_min, tm.tm_min,
tm.tm_sec, tm.tm_sec, ms,
tzinfo); tzinfo);
if (!fmt) { if (!fmt) {
@ -3743,7 +3745,7 @@ static void *socketer(__maybe_unused void *arg)
cmdnum = CMD_UNSET; cmdnum = CMD_UNSET;
buf = recv_unix_msg(sockd); buf = recv_unix_msg_tmo2(sockd, RECV_UNIX_TIMEOUT1, RECV_UNIX_TIMEOUT2);
// Once we've read the message // Once we've read the message
setnow(&now); setnow(&now);
if (buf) { if (buf) {

41
src/ckpool.c

@ -65,7 +65,8 @@ void logmsg(int loglevel, const char *fmt, ...) {
int logfd = global_ckp->logfd; int logfd = global_ckp->logfd;
char *buf = NULL; char *buf = NULL;
struct tm tm; struct tm tm;
time_t now_t; tv_t now_tv;
int ms;
va_list ap; va_list ap;
char stamp[128]; char stamp[128];
@ -73,16 +74,17 @@ void logmsg(int loglevel, const char *fmt, ...) {
VASPRINTF(&buf, fmt, ap); VASPRINTF(&buf, fmt, ap);
va_end(ap); va_end(ap);
now_t = time(NULL); tv_time(&now_tv);
localtime_r(&now_t, &tm); ms = (int)(now_tv.tv_usec / 1000);
sprintf(stamp, "[%d-%02d-%02d %02d:%02d:%02d]", localtime_r(&(now_tv.tv_sec), &tm);
sprintf(stamp, "[%d-%02d-%02d %02d:%02d:%02d.%03d]",
tm.tm_year + 1900, tm.tm_year + 1900,
tm.tm_mon + 1, tm.tm_mon + 1,
tm.tm_mday, tm.tm_mday,
tm.tm_hour, tm.tm_hour,
tm.tm_min, tm.tm_min,
tm.tm_sec); tm.tm_sec, ms);
if (loglevel <= LOG_WARNING) {\ if (loglevel <= LOG_WARNING) {
if (loglevel <= LOG_ERR && errno != 0) if (loglevel <= LOG_ERR && errno != 0)
fprintf(stderr, "%s %s with errno %d: %s\n", stamp, buf, errno, strerror(errno)); fprintf(stderr, "%s %s with errno %d: %s\n", stamp, buf, errno, strerror(errno));
else else
@ -360,7 +362,7 @@ static int send_procmsg(proc_instance_t *pi, const char *buf)
} }
sockd = open_unix_client(path); sockd = open_unix_client(path);
if (unlikely(sockd < 0)) { if (unlikely(sockd < 0)) {
LOGWARNING("Failed to open socket %s in send_recv_proc", path); LOGWARNING("Failed to open socket %s in send_procmsg", path);
goto out; goto out;
} }
if (unlikely(!send_unix_msg(sockd, buf))) if (unlikely(!send_unix_msg(sockd, buf)))
@ -510,7 +512,7 @@ void empty_buffer(connsock_t *cs)
/* Read from a socket into cs->buf till we get an '\n', converting it to '\0' /* Read from a socket into cs->buf till we get an '\n', converting it to '\0'
* and storing how much extra data we've received, to be moved to the beginning * and storing how much extra data we've received, to be moved to the beginning
* of the buffer for use on the next receive. */ * of the buffer for use on the next receive. */
int read_socket_line(connsock_t *cs, float timeout) int read_socket_line(connsock_t *cs, float *timeout)
{ {
int fd = cs->fd, ret = -1; int fd = cs->fd, ret = -1;
char *eom = NULL; char *eom = NULL;
@ -534,7 +536,12 @@ int read_socket_line(connsock_t *cs, float timeout)
tv_time(&start); tv_time(&start);
rewait: rewait:
ret = wait_read_select(fd, eom ? 0 : timeout); if (*timeout <= 0) {
LOGDEBUG("Timed out in read_socket_line");
ret = 0;
goto out;
}
ret = wait_read_select(fd, eom ? 0 : *timeout);
if (ret < 1) { if (ret < 1) {
if (!ret) { if (!ret) {
if (eom) if (eom)
@ -550,7 +557,7 @@ rewait:
} }
tv_time(&now); tv_time(&now);
diff = tvdiff(&now, &start); diff = tvdiff(&now, &start);
timeout -= diff; *timeout -= diff;
while (42) { while (42) {
char readbuf[PAGESIZE] = {}; char readbuf[PAGESIZE] = {};
int backoff = 1; int backoff = 1;
@ -562,7 +569,7 @@ rewait:
if (eom) if (eom)
break; break;
/* Have we used up all the timeout yet? */ /* Have we used up all the timeout yet? */
if (timeout > 0 && (errno == EAGAIN || errno == EWOULDBLOCK || !ret)) if (*timeout > 0 && (errno == EAGAIN || errno == EWOULDBLOCK || !ret))
goto rewait; goto rewait;
if (cs->ckp->proxy) if (cs->ckp->proxy)
LOGINFO("Failed to recv in read_socket_line"); LOGINFO("Failed to recv in read_socket_line");
@ -657,7 +664,8 @@ out:
/* Send a single message to a process instance and retrieve the response, then /* Send a single message to a process instance and retrieve the response, then
* close the socket. */ * close the socket. */
char *_send_recv_proc(proc_instance_t *pi, const char *msg, const char *file, const char *func, const int line) char *_send_recv_proc(proc_instance_t *pi, const char *msg, int writetimeout, int readtimedout,
const char *file, const char *func, const int line)
{ {
char *path = pi->us.path, *buf = NULL; char *path = pi->us.path, *buf = NULL;
int sockd; int sockd;
@ -687,10 +695,10 @@ char *_send_recv_proc(proc_instance_t *pi, const char *msg, const char *file, co
LOGWARNING("Failed to open socket %s in send_recv_proc", path); LOGWARNING("Failed to open socket %s in send_recv_proc", path);
goto out; goto out;
} }
if (unlikely(!send_unix_msg(sockd, msg))) if (unlikely(!_send_unix_msg(sockd, msg, writetimeout, file, func, line)))
LOGWARNING("Failed to send %s to socket %s", msg, path); LOGWARNING("Failed to send %s to socket %s", msg, path);
else else
buf = recv_unix_msg(sockd); buf = _recv_unix_msg(sockd, readtimedout, readtimedout, file, func, line);
Close(sockd); Close(sockd);
out: out:
if (unlikely(!buf)) if (unlikely(!buf))
@ -743,6 +751,7 @@ char *_ckdb_msg_call(const ckpool_t *ckp, const char *msg, const char *file, co
json_t *json_rpc_call(connsock_t *cs, const char *rpc_req) json_t *json_rpc_call(connsock_t *cs, const char *rpc_req)
{ {
float timeout = RPC_TIMEOUT;
char *http_req = NULL; char *http_req = NULL;
json_error_t err_val; json_error_t err_val;
json_t *val = NULL; json_t *val = NULL;
@ -788,7 +797,7 @@ json_t *json_rpc_call(connsock_t *cs, const char *rpc_req)
LOGWARNING("Failed to write to socket in json_rpc_call"); LOGWARNING("Failed to write to socket in json_rpc_call");
goto out_empty; goto out_empty;
} }
ret = read_socket_line(cs, 5); ret = read_socket_line(cs, &timeout);
if (ret < 1) { if (ret < 1) {
LOGWARNING("Failed to read socket line in json_rpc_call"); LOGWARNING("Failed to read socket line in json_rpc_call");
goto out_empty; goto out_empty;
@ -798,7 +807,7 @@ json_t *json_rpc_call(connsock_t *cs, const char *rpc_req)
goto out_empty; goto out_empty;
} }
do { do {
ret = read_socket_line(cs, 5); ret = read_socket_line(cs, &timeout);
if (ret < 1) { if (ret < 1) {
LOGWARNING("Failed to read http socket lines in json_rpc_call"); LOGWARNING("Failed to read http socket lines in json_rpc_call");
goto out_empty; goto out_empty;

11
src/ckpool.h

@ -19,6 +19,10 @@
#include "libckpool.h" #include "libckpool.h"
#include "uthash.h" #include "uthash.h"
#define RPC_TIMEOUT 60
struct ckpool_instance;
typedef struct ckpool_instance ckpool_t; typedef struct ckpool_instance ckpool_t;
struct ckmsg { struct ckmsg {
@ -254,11 +258,12 @@ ckpool_t *global_ckp;
bool ping_main(ckpool_t *ckp); bool ping_main(ckpool_t *ckp);
void empty_buffer(connsock_t *cs); void empty_buffer(connsock_t *cs);
int read_socket_line(connsock_t *cs, float timeout); int read_socket_line(connsock_t *cs, float *timeout);
void _send_proc(proc_instance_t *pi, const char *msg, const char *file, const char *func, const int line); void _send_proc(proc_instance_t *pi, const char *msg, const char *file, const char *func, const int line);
#define send_proc(pi, msg) _send_proc(pi, msg, __FILE__, __func__, __LINE__) #define send_proc(pi, msg) _send_proc(pi, msg, __FILE__, __func__, __LINE__)
char *_send_recv_proc(proc_instance_t *pi, const char *msg, const char *file, const char *func, const int line); char *_send_recv_proc(proc_instance_t *pi, const char *msg, int writetimeout, int readtimedout,
#define send_recv_proc(pi, msg) _send_recv_proc(pi, msg, __FILE__, __func__, __LINE__) const char *file, const char *func, const int line);
#define send_recv_proc(pi, msg) _send_recv_proc(pi, msg, UNIX_WRITE_TIMEOUT, UNIX_READ_TIMEOUT, __FILE__, __func__, __LINE__)
char *_send_recv_ckdb(const ckpool_t *ckp, const char *msg, const char *file, const char *func, const int line); char *_send_recv_ckdb(const ckpool_t *ckp, const char *msg, const char *file, const char *func, const int line);
#define send_recv_ckdb(ckp, msg) _send_recv_ckdb(ckp, msg, __FILE__, __func__, __LINE__) #define send_recv_ckdb(ckp, msg) _send_recv_ckdb(ckp, msg, __FILE__, __func__, __LINE__)
char *_ckdb_msg_call(const ckpool_t *ckp, const char *msg, const char *file, const char *func, char *_ckdb_msg_call(const ckpool_t *ckp, const char *msg, const char *file, const char *func,

16
src/generator.c

@ -558,8 +558,9 @@ static char *cached_proxy_line(proxy_instance_t *proxi)
static char *next_proxy_line(connsock_t *cs, proxy_instance_t *proxi) static char *next_proxy_line(connsock_t *cs, proxy_instance_t *proxi)
{ {
char *buf = cached_proxy_line(proxi); char *buf = cached_proxy_line(proxi);
float timeout = 10;
if (!buf && read_socket_line(cs, 5) > 0) if (!buf && read_socket_line(cs, &timeout) > 0)
buf = strdup(cs->buf); buf = strdup(cs->buf);
return buf; return buf;
} }
@ -575,9 +576,10 @@ static void append_proxy_line(proxy_instance_t *proxi, const char *buf)
/* Get a new line from the connsock and return a copy of it */ /* Get a new line from the connsock and return a copy of it */
static char *new_proxy_line(connsock_t *cs) static char *new_proxy_line(connsock_t *cs)
{ {
float timeout = 10;
char *buf = NULL; char *buf = NULL;
if (read_socket_line(cs, 5) < 1) if (read_socket_line(cs, &timeout) < 1)
goto out; goto out;
buf = strdup(cs->buf); buf = strdup(cs->buf);
out: out:
@ -756,6 +758,7 @@ out:
static bool passthrough_stratum(connsock_t *cs, proxy_instance_t *proxi, const bool node) static bool passthrough_stratum(connsock_t *cs, proxy_instance_t *proxi, const bool node)
{ {
json_t *req, *val = NULL, *res_val, *err_val; json_t *req, *val = NULL, *res_val, *err_val;
float timeout = 10;
bool ret = false; bool ret = false;
JSON_CPACK(req, "{s:s,s:[sb]}", JSON_CPACK(req, "{s:s,s:[sb]}",
@ -767,7 +770,7 @@ static bool passthrough_stratum(connsock_t *cs, proxy_instance_t *proxi, const b
LOGWARNING("Failed to send message in passthrough_stratum"); LOGWARNING("Failed to send message in passthrough_stratum");
goto out; goto out;
} }
if (read_socket_line(cs, 5) < 1) { if (read_socket_line(cs, &timeout) < 1) {
LOGWARNING("Failed to receive line in passthrough_stratum"); LOGWARNING("Failed to receive line in passthrough_stratum");
goto out; goto out;
} }
@ -1900,6 +1903,7 @@ static void *passthrough_recv(void *arg)
alive = proxi->alive; alive = proxi->alive;
while (42) { while (42) {
float timeout = 90;
int ret; int ret;
while (!proxy_alive(ckp, proxi, cs, true)) { while (!proxy_alive(ckp, proxi, cs, true)) {
@ -1913,7 +1917,7 @@ static void *passthrough_recv(void *arg)
reconnect_generator(ckp); reconnect_generator(ckp);
/* Make sure we receive a line within 90 seconds */ /* Make sure we receive a line within 90 seconds */
ret = read_socket_line(cs, 90); ret = read_socket_line(cs, &timeout);
if (ret < 1) { if (ret < 1) {
LOGWARNING("Proxy %d:%s failed to read_socket_line in passthrough_recv, attempting reconnect", LOGWARNING("Proxy %d:%s failed to read_socket_line in passthrough_recv, attempting reconnect",
proxi->id, proxi->url); proxi->id, proxi->url);
@ -2025,12 +2029,14 @@ static void *proxy_recv(void *arg)
* has likely stopped responding. */ * has likely stopped responding. */
ret = epoll_wait(epfd, &event, 1, 600000); ret = epoll_wait(epfd, &event, 1, 600000);
if (likely(ret > 0)) { if (likely(ret > 0)) {
float timeout = 10;
subproxy = event.data.ptr; subproxy = event.data.ptr;
cs = &subproxy->cs; cs = &subproxy->cs;
if (event.events & (EPOLLHUP | EPOLLERR | EPOLLRDHUP)) if (event.events & (EPOLLHUP | EPOLLERR | EPOLLRDHUP))
ret = -1; ret = -1;
else else
ret = read_socket_line(cs, 5); ret = read_socket_line(cs, &timeout);
} }
if (ret < 1) { if (ret < 1) {
LOGNOTICE("Proxy %d:%d %s failed to epoll/read_socket_line in proxy_recv", LOGNOTICE("Proxy %d:%d %s failed to epoll/read_socket_line in proxy_recv",

35
src/libckpool.c

@ -1003,27 +1003,34 @@ out:
return ret; return ret;
} }
int write_length(int sockd, const void *buf, int len) int _write_length(int sockd, const void *buf, int len, const char *file, const char *func, const int line)
{ {
int ret, ofs = 0; int ret, ofs = 0;
if (unlikely(len < 1)) { if (unlikely(len < 1)) {
LOGWARNING("Invalid write length of %d requested in write_length", len); LOGWARNING("Invalid write length of %d requested in write_length from %s %s:%d",
len, file, func, line);
return -1; return -1;
} }
if (unlikely(sockd < 0)) if (unlikely(sockd < 0)) {
LOGWARNING("Attempt to write to invalidated sock in write_length from %s %s:%d",
file, func, line);
return -1; return -1;
}
while (len) { while (len) {
ret = write(sockd, buf + ofs, len); ret = write(sockd, buf + ofs, len);
if (unlikely(ret < 0)) if (unlikely(ret < 0)) {
LOGERR("Failed to write %d bytes in write_length from %s %s:%d",
len, file, func, line);
return -1; return -1;
}
ofs += ret; ofs += ret;
len -= ret; len -= ret;
} }
return ofs; return ofs;
} }
bool _send_unix_msg(int sockd, const char *buf, const char *file, const char *func, const int line) bool _send_unix_msg(int sockd, const char *buf, int timeout, const char *file, const char *func, const int line)
{ {
uint32_t msglen, len; uint32_t msglen, len;
bool retval = false; bool retval = false;
@ -1043,28 +1050,26 @@ bool _send_unix_msg(int sockd, const char *buf, const char *file, const char *fu
goto out; goto out;
} }
msglen = htole32(len); msglen = htole32(len);
ret = wait_write_select(sockd, 5); ret = wait_write_select(sockd, timeout);
if (unlikely(ret < 1)) { if (unlikely(ret < 1)) {
ern = errno; ern = errno;
LOGERR("Select1 failed in send_unix_msg (%d)", ern); LOGERR("Select1 failed in send_unix_msg (%d)", ern);
goto out; goto out;
} }
ret = write_length(sockd, &msglen, 4); ret = _write_length(sockd, &msglen, 4, file, func, line);
if (unlikely(ret < 4)) { if (unlikely(ret < 4)) {
ern = errno; LOGERR("Failed to write 4 byte length in send_unix_msg");
LOGERR("Failed to write 4 byte length in send_unix_msg (%d)", ern);
goto out; goto out;
} }
ret = wait_write_select(sockd, 5); ret = wait_write_select(sockd, timeout);
if (unlikely(ret < 1)) { if (unlikely(ret < 1)) {
ern = errno; ern = errno;
LOGERR("Select2 failed in send_unix_msg (%d)", ern); LOGERR("Select2 failed in send_unix_msg (%d)", ern);
goto out; goto out;
} }
ret = write_length(sockd, buf, len); ret = _write_length(sockd, buf, len, file, func, line);
if (unlikely(ret < 0)) { if (unlikely(ret < 0)) {
ern = errno; LOGERR("Failed to write %d bytes in send_unix_msg", len);
LOGERR("Failed to write %d bytes in send_unix_msg (%d)", len, ern);
goto out; goto out;
} }
retval = true; retval = true;
@ -1084,7 +1089,7 @@ bool _send_unix_data(int sockd, const struct msghdr *msg, const char *file, cons
LOGWARNING("Null message sent to send_unix_data"); LOGWARNING("Null message sent to send_unix_data");
goto out; goto out;
} }
ret = wait_write_select(sockd, 5); ret = wait_write_select(sockd, UNIX_WRITE_TIMEOUT);
if (unlikely(ret < 1)) { if (unlikely(ret < 1)) {
LOGERR("Select1 failed in send_unix_data"); LOGERR("Select1 failed in send_unix_data");
goto out; goto out;
@ -1107,7 +1112,7 @@ bool _recv_unix_data(int sockd, struct msghdr *msg, const char *file, const char
bool retval = false; bool retval = false;
int ret; int ret;
ret = wait_read_select(sockd, 5); ret = wait_read_select(sockd, UNIX_READ_TIMEOUT);
if (unlikely(ret < 1)) { if (unlikely(ret < 1)) {
LOGERR("Select1 failed in recv_unix_data"); LOGERR("Select1 failed in recv_unix_data");
goto out; goto out;

17
src/libckpool.h

@ -236,6 +236,12 @@ void logmsg(int loglevel, const char *fmt, ...);
#define PAGESIZE (4096) #define PAGESIZE (4096)
/* Default timeouts for unix socket reads and writes in seconds. Set write
* timeout to double the read timeout in case of one read blocking the next
* writer. */
#define UNIX_READ_TIMEOUT 5
#define UNIX_WRITE_TIMEOUT 10
/* Share error values */ /* Share error values */
enum share_err { enum share_err {
@ -495,13 +501,14 @@ int read_length(int sockd, void *buf, int len);
char *_recv_unix_msg(int sockd, int timeout1, int timeout2, const char *file, const char *func, const int line); char *_recv_unix_msg(int sockd, int timeout1, int timeout2, const char *file, const char *func, const int line);
#define RECV_UNIX_TIMEOUT1 30 #define RECV_UNIX_TIMEOUT1 30
#define RECV_UNIX_TIMEOUT2 5 #define RECV_UNIX_TIMEOUT2 5
#define recv_unix_msg(sockd) _recv_unix_msg(sockd, RECV_UNIX_TIMEOUT1, RECV_UNIX_TIMEOUT2, __FILE__, __func__, __LINE__) #define recv_unix_msg(sockd) _recv_unix_msg(sockd, UNIX_READ_TIMEOUT, UNIX_READ_TIMEOUT, __FILE__, __func__, __LINE__)
#define recv_unix_msg_tmo(sockd, tmo) _recv_unix_msg(sockd, tmo, RECV_UNIX_TIMEOUT2, __FILE__, __func__, __LINE__) #define recv_unix_msg_tmo(sockd, tmo) _recv_unix_msg(sockd, tmo, UNIX_READ_TIMEOUT, __FILE__, __func__, __LINE__)
#define recv_unix_msg_tmo2(sockd, tmo1, tmo2) _recv_unix_msg(sockd, tmo1, tmo2, __FILE__, __func__, __LINE__) #define recv_unix_msg_tmo2(sockd, tmo1, tmo2) _recv_unix_msg(sockd, tmo1, tmo2, __FILE__, __func__, __LINE__)
int wait_write_select(int sockd, float timeout); int wait_write_select(int sockd, float timeout);
int write_length(int sockd, const void *buf, int len); #define write_length(sockd, buf, len) _write_length(sockd, buf, len, __FILE__, __func__, __LINE__)
bool _send_unix_msg(int sockd, const char *buf, const char *file, const char *func, const int line); int _write_length(int sockd, const void *buf, int len, const char *file, const char *func, const int line);
#define send_unix_msg(sockd, buf) _send_unix_msg(sockd, buf, __FILE__, __func__, __LINE__) bool _send_unix_msg(int sockd, const char *buf, int timeout, const char *file, const char *func, const int line);
#define send_unix_msg(sockd, buf) _send_unix_msg(sockd, buf, UNIX_WRITE_TIMEOUT, __FILE__, __func__, __LINE__)
bool _send_unix_data(int sockd, const struct msghdr *msg, const char *file, const char *func, const int line); bool _send_unix_data(int sockd, const struct msghdr *msg, const char *file, const char *func, const int line);
#define send_unix_data(sockd, msg) _send_unix_data(sockd, msg, __FILE__, __func__, __LINE__) #define send_unix_data(sockd, msg) _send_unix_data(sockd, msg, __FILE__, __func__, __LINE__)
bool _recv_unix_data(int sockd, struct msghdr *msg, const char *file, const char *func, const int line); bool _recv_unix_data(int sockd, struct msghdr *msg, const char *file, const char *func, const int line);

2
src/stratifier.c

@ -892,7 +892,7 @@ static char *__send_recv_generator(ckpool_t *ckp, const char *msg, const int pri
set = true; set = true;
} else } else
set = false; set = false;
buf = send_recv_proc(ckp->generator, msg); buf = _send_recv_proc(ckp->generator, msg, UNIX_WRITE_TIMEOUT, RPC_TIMEOUT, __FILE__, __func__, __LINE__);
if (unlikely(!buf)) if (unlikely(!buf))
buf = strdup("failed"); buf = strdup("failed");
if (set) if (set)

Loading…
Cancel
Save