Skip to content

Commit

Permalink
add file descriptor counts to status line
Browse files Browse the repository at this point in the history
  • Loading branch information
TrimmingFool committed Feb 20, 2022
1 parent 6b51ff7 commit d9701d5
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 3 deletions.
2 changes: 2 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ div#tadd select { width: 220px }
.optionColumn input[type=number],.optionColumn select { padding: 1px; margin: 0.1em 0.5em; width: 6em; }
.optionColumn div { padding-left: 0; }
.statuscell td { padding: 0 }
#st_fd .sthdr { padding-left: 8px; }
#st_fd .stval { text-align: center; width: 4.3em; }
#st_system .sthdr { padding-left: 8px }

.ie fieldset {padding: 5px}
Expand Down
7 changes: 7 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@
</tr>
</table>
</td>
<td>
<table id="st_fd" class="statuscell" cellpadding="0" cellspacing="0">
<tr>
<td><div class="sthdr"><script type="text/javascript"> document.write(theUILang.Open_label); </script>:</div></td><td><div class="stval" id="stopen_http_count"></div></td><td><div class="stval" id="stopen_sock_count"></div></td><td><div class="stval" id="stopen_fd_count"></div></td>
</tr>
</table>
</td>
<td>
<table id="st_system" class="statuscell" cellpadding="0" cellspacing="0">
<tr>
Expand Down
1 change: 1 addition & 0 deletions js/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ function makeContent()
['webui.labelsize_rightalign', theUILang.labelSizeRightAlign],
['webui.show_label_path_tree', theUILang.showCustomLabelTree],
['webui.show_empty_path_labels', theUILang.showEmptyPathLabel],
['webui.show_open_status', theUILang.showOpenStatus],
].map(([id, label]) =>
$('<div>').append(
$('<input>').attr({ type: 'checkbox', id, checked: 'true' }),
Expand Down
50 changes: 49 additions & 1 deletion js/rtorrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ var theRequestManager =
],
handlers: []
},
opn:
{
commands:
[
"network.http.current_open", "network.open_sockets"
],
handlers: []
},
prp:
{
commands:
Expand Down Expand Up @@ -97,7 +105,7 @@ var theRequestManager =
init: function()
{
var self = this;
$.each( ["trt","trk", "fls", "prs", "ttl", "prp", "stg"], function(ndx,cmd)
$.each( ["trt","trk", "fls", "prs", "ttl", "opn", "prp", "stg"], function(ndx,cmd)
{
self[cmd].count = self[cmd].commands.length;
});
Expand All @@ -109,6 +117,14 @@ var theRequestManager =
this[system].commands.push(command);
return(this[system].handlers.length-1);
},
onResponse: function(reqType, values, ...args)
{
// call all handlers for the response type with response data
for (const handler of this[reqType].handlers) {
if (handler)
handler.response(...args, (handler.ndx===null) ? null : values[handler.ndx]);
}
},
removeRequest: function( system, id )
{
this[system].handlers[id] = null;
Expand Down Expand Up @@ -524,6 +540,15 @@ rTorrentStub.prototype.gettotal = function()
this.commands.push( new rXMLRPCCommand(theRequestManager.ttl.commands[i]) );
}

rTorrentStub.prototype.getopen = function()
{
this.commands = this.commands.concat(
theRequestManager.opn.commands.map(cmd => new rXMLRPCCommand(cmd))
);
if (theWebUI.systemInfo.rTorrent.apiVersion >= 11)
this.commands.push(new rXMLRPCCommand('network.open_files'));
}

rTorrentStub.prototype.getprops = function()
{
for(var i in theRequestManager.prp.commands)
Expand Down Expand Up @@ -747,6 +772,18 @@ rTorrentStub.prototype.getResponse = function(data)
return(ret);
}

rTorrentStub.prototype.getXMLValues = function(xml)
{
const datas = xml.getElementsByTagName('data');
const data = datas[0];
const xmlValues = data.getElementsByTagName('value');
const values = [];
for (let i = 0; i < xmlValues.length; i++) {
values.push(this.getValue(xmlValues, i*2+1));
}
return values;
}

rTorrentStub.prototype.setprioResponse = function(xml)
{
return(this.hashes[0]);
Expand Down Expand Up @@ -797,6 +834,17 @@ rTorrentStub.prototype.gettotalResponse = function(xml)
return( ret );
}

rTorrentStub.prototype.getopenResponse = function(xml)
{
const values = this.getXMLValues(xml);
const ret = {
http: iv(values[0]), sock: iv(values[1]),
fd: this.commands.length < 3 ? -1 : iv(values[2])
};
theRequestManager.onResponse('opn', values, ret);
return( ret );
}

rTorrentStub.prototype.getsettingsResponse = function(xml)
{
var datas = xml.getElementsByTagName('data');
Expand Down
35 changes: 34 additions & 1 deletion js/webui.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ var theWebUI =
"webui.show_statelabelsize": 0,
"webui.show_label_path_tree": 1,
"webui.show_empty_path_labels": 0,
"webui.show_open_status": 1,
"webui.register_magnet": 0,
...(() => {
const defaults = {};
Expand All @@ -192,6 +193,12 @@ var theWebUI =
DL: 0,
UL: 0
},
stopen:
{
http: -1,
sock: -1,
fd: -1,
},
sTimer: null,
updTimer: null,
configured: false,
Expand Down Expand Up @@ -1816,10 +1823,13 @@ var theWebUI =
this.updateTegs(Object.values(this.tegs));
this.updateTegLabels(Object.keys(this.tegs));
this.loadTorrents();
this.getTotal();

this.updateViewRows(table)

this.getTotal();
if (this.settings['webui.show_open_status'])
this.getOpenStatus();

// Cleanup memory leaks
tArray = null;
table = null;
Expand Down Expand Up @@ -1878,6 +1888,16 @@ var theWebUI =
$.extend(this.total,d);
},

getOpenStatus: function()
{
this.request("?action=getopen", [this.addOpenStatus, this]);
},

addOpenStatus: function(stopen)
{
Object.assign(this.stopen, stopen);
},

/**
* @typedef {array.<string>} StatusIcon
* first element: icon name
Expand Down Expand Up @@ -2577,6 +2597,19 @@ var theWebUI =
$("#stdown_speed").text(dl);
$("#stdown_limit").text((self.total.rateDL>0 && self.total.rateDL<327625*1024) ? theConverter.speed(self.total.rateDL) : theUILang.no);
$("#stdown_total").text(theConverter.bytes(self.total.DL));

if (self.settings['webui.show_open_status']) {
for (const opnType of ['http', 'sock', 'fd']) {
const ele = $($$('stopen_'+opnType+'_count'));
if (self.stopen[opnType] > -1)
ele.text(self.stopen[opnType] + ' ' + opnType).show();
else
ele.hide()
}
$("#st_fd").show();
} else {
$("#st_fd").hide();
}
},

setDLRate: function(spd)
Expand Down
1 change: 1 addition & 0 deletions lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ var theUILang =
scrapeUpdate : "Last Updated",
trkInterval : "Interval",
logAutoSwitch : "Autoswitch to 'Log' tab",
showOpenStatus : "Show open status in status bar",
showStateLabelSize : "Show state size",
showLabelSize : "Show label size",
showSearchLabelSize : "Show search size",
Expand Down
19 changes: 18 additions & 1 deletion plugins/httprpc/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,23 @@ function makeSimpleCall($cmds,$hash)
$result = $req->val;
break;
}
case "opn": /**/
{
$cmds = array(
"network.http.current_open", "network.open_sockets"
);
if (rTorrentSettings::get()->apiVersion >= 11)
$cmds[] = "network.open_files";
$req = new rXMLRPCRequest();
foreach( $cmds as $cmd )
$req->addCommand( new rXMLRPCCommand( $cmd ) );
if($req->success(false)) {
$result = $req->val;
if (count($cmds) < 3)
$result[] = -1;
}
break;
}
case "prp": /**/
{
$cmds = array(
Expand Down Expand Up @@ -476,7 +493,7 @@ function makeSimpleCall($cmds,$hash)
if(is_null($result))
{
header("HTTP/1.0 500 Server Error");
CachedEcho::send( (isset($req) && $req->fault) ? "Warning: XMLRPC call is failed." : "Link to XMLRPC failed. May be, rTorrent is down?","text/html");
CachedEcho::send( (isset($req) && $req->fault) ? "Warning: XMLRPC call is failed." : "Link to XMLRPC failed. Maybe, rTorrent is down?","text/html");
}
else
CachedEcho::send(JSON::safeEncode($result),"application/json");
18 changes: 18 additions & 0 deletions plugins/httprpc/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ rTorrentStub.prototype.gettotal = function()
this.getCommon("ttl");
}

plugin.origopn = rTorrentStub.prototype.getopen;
rTorrentStub.prototype.getopen = function()
{
this.getCommon("opn");
}

plugin.origprp = rTorrentStub.prototype.getprops;
rTorrentStub.prototype.getprops = function()
{
Expand Down Expand Up @@ -365,6 +371,18 @@ rTorrentStub.prototype.gettotalResponse = function(values)
return(plugin.origgettotalResponse.call(this,values));
}

plugin.origgetopenResponse = rTorrentStub.prototype.getopenResponse;
rTorrentStub.prototype.getopenResponse = function(values)
{
if(this.dataType == "json")
{
const ret = { http: iv(values[0]), sock: iv(values[1]), fd: iv(values[2]) };
theRequestManager.onResponse('opn', values, ret);
return( ret );
}
return(plugin.origgetopenResponse.call(this,values));
}

plugin.origgetsettingsResponse = rTorrentStub.prototype.getsettingsResponse;
rTorrentStub.prototype.getsettingsResponse = function(values)
{
Expand Down

4 comments on commit d9701d5

@ChriZathens
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello
After this commit I constantly get in the log:

Bad response from server: (500 [error,getopen]) Warning: XMLRPC call is failed.

In my error log I get this:
`[2022-02-21 11:48:37] system.multicall
methodNamenetwork.http.current_openparams

methodNamenetwork.open_socketsparams


[2022-02-21 11:48:37] Status: 200 OK
Content-Type: text/xml
Content-Length: 465

faultCode -506 faultString Method 'network.http.current_open' not defined 25 `

Any help appreciated

@ChriZathens
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found out that unchecking "show open status in status bar" stops giving the error.
Is this an rtorrent/libtorrent limitation (I have 0.9.6/0.13.6) and needs a later version or is it something else?

@stickz
Copy link
Collaborator

@stickz stickz commented on d9701d5 Feb 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an rtorrent/libtorrent limitation (I have 0.9.6/0.13.6) and needs a later version or is it something else?

Yes network.http.current_open requires rTorrent 0.9.7 or later. This needs to be fixed, so it doesn't throw an error for earlier versions of rTorrent.

@ChriZathens
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an rtorrent/libtorrent limitation (I have 0.9.6/0.13.6) and needs a later version or is it something else?

Yes network.http.current_open requires rTorrent 0.9.7 or later. This needs to be fixed, so it doesn't throw an error for earlier versions of rTorrent.

Great! Thanks for the information. For the time being I keep the above setting disabled and I will consider updating my rtorrent/libtorrent instances.
However, yes, this needs to be fixed because according to the wiki, rutorrent supports rtorrent 0.8.2 or later, so it will cause a lot of reports from people. Or to have the setting disabled by default with a note that rtorrent 0.9.7 or later is required

Please sign in to comment.