Browse Source

Merge branch 'cg_merges_20140322' into bfgminer

Luke Dashjr 12 years ago
parent
commit
ae335a2338
7 changed files with 164 additions and 33 deletions
  1. 9 0
      README
  2. 31 2
      README.RPC
  3. 2 2
      api.c
  4. 6 1
      miner.c
  5. 100 25
      miner.php
  6. 5 2
      util.c
  7. 11 1
      util.h

+ 9 - 0
README

@@ -649,6 +649,15 @@ Q: BFGMiner segfaults when I change my shell window size.
 A: Older versions of libncurses have a bug to do with refreshing a window
 A: Older versions of libncurses have a bug to do with refreshing a window
 after a size change. Upgrading to a new version of curses will fix it.
 after a size change. Upgrading to a new version of curses will fix it.
 
 
+Q: I have multiple USB stick devices but I can't get them all to work at once?
+A: Very few USB hubs deliver the promised power required to run as many devices
+as they fit if all of them draw power from USB.
+
+Q: I've plugged my devices into my USB hub but nothing shows up?
+A: RPis and Windows have incomplete or non-standard USB3 support so they may
+never work. It may be possible to get a USB3 hub to work by plugging it into a
+USB2 hub.
+
 Q: Can I mine on servers from different networks (eg smartcoin and bitcoin) at
 Q: Can I mine on servers from different networks (eg smartcoin and bitcoin) at
 the same time?
 the same time?
 A: No, BFGMiner keeps a database of the block it's working on to ensure it does
 A: No, BFGMiner keeps a database of the block it's working on to ensure it does

+ 31 - 2
README.RPC

@@ -1250,19 +1250,48 @@ However, if $readonly is true, it will not display them.
 
 
 ---------
 ---------
 
 
+Default:
+ $rigport = 4028;
+
+Default port to use if any $rigs entries don't specify the port number
+
+---------
+
 Default:
 Default:
  $rigs = array('127.0.0.1:4028');
  $rigs = array('127.0.0.1:4028');
 
 
-Set $rigs to an array of your BFGMiner rigs that are running format: 'IP:Port'
- or 'Host:Port' or 'Host:Port:Name'.
+Set $rigs to an array of your BFGMiner rigs that are running format: 'IP' or
+ 'Host' or 'IP:Port' or 'Host:Port' or 'Host:Port:Name'.
 If you only have one rig, it will just show the detail of that rig.
 If you only have one rig, it will just show the detail of that rig.
 If you have more than one rig it will show a summary of all the rigs with
 If you have more than one rig it will show a summary of all the rigs with
  buttons to show the details of each rig - the button contents will be 'Name'
  buttons to show the details of each rig - the button contents will be 'Name'
  rather than rig number, if you specify 'Name'.
  rather than rig number, if you specify 'Name'.
+If Port is missing or blank, it will try $rigport
 e.g. $rigs = array('127.0.0.1:4028','myrig.com:4028:Sugoi');
 e.g. $rigs = array('127.0.0.1:4028','myrig.com:4028:Sugoi');
 
 
 ---------
 ---------
 
 
+Default:
+ $rignames = false;
+
+Set $rignames to false to not affect the display.
+Set $rignames to one of 'ip' or 'ipx' to alter the name displayed
+if the rig doesn't have a 'name' in $rigs
+Currently:
+ 'ip' means use the 4th byte of the rig IP address as an integer
+ 'ipx' means use the 4th byte of the rig IP address as 2 hex bytes
+
+---------
+
+Default:
+ $rigbuttons = true;
+
+Set $rigbuttons to false to display a link rather than a button on
+the left of any summary table with rig buttons, in order to reduce
+the height of the table cells
+
+---------
+
 Default:
 Default:
  $mcast = false;
  $mcast = false;
 
 

+ 2 - 2
api.c

@@ -4226,8 +4226,8 @@ void api(int api_thr_id)
 				if (!did) {
 				if (!did) {
 					if (strchr(cmd, CMDJOIN)) {
 					if (strchr(cmd, CMDJOIN)) {
 						firstjoin = isjoin = true;
 						firstjoin = isjoin = true;
-						// cmd + leading '|' + '\0'
-						cmdsbuf = malloc(strlen(cmd) + 2);
+						// cmd + leading+tailing '|' + '\0'
+						cmdsbuf = malloc(strlen(cmd) + 3);
 						if (!cmdsbuf)
 						if (!cmdsbuf)
 							quithere(1, "OOM cmdsbuf");
 							quithere(1, "OOM cmdsbuf");
 						strcpy(cmdsbuf, "|");
 						strcpy(cmdsbuf, "|");

+ 6 - 1
miner.c

@@ -9110,7 +9110,12 @@ struct work *get_queued(struct cgpu_info *cgpu)
 	wr_lock(&cgpu->qlock);
 	wr_lock(&cgpu->qlock);
 	if (cgpu->unqueued_work) {
 	if (cgpu->unqueued_work) {
 		work = cgpu->unqueued_work;
 		work = cgpu->unqueued_work;
-		__add_queued(cgpu, work);
+		if (unlikely(stale_work(work, false))) {
+			discard_work(work);
+			work = NULL;
+			wake_gws();
+		} else
+			__add_queued(cgpu, work);
 		cgpu->unqueued_work = NULL;
 		cgpu->unqueued_work = NULL;
 	}
 	}
 	wr_unlock(&cgpu->qlock);
 	wr_unlock(&cgpu->qlock);

+ 100 - 25
miner.php

@@ -2,7 +2,8 @@
 session_start();
 session_start();
 date_default_timezone_set(@date_default_timezone_get());
 date_default_timezone_set(@date_default_timezone_get());
 #
 #
-global $doctype, $title, $miner, $port, $readonly, $notify, $rigs;
+global $doctype, $title, $miner, $port, $readonly, $notify;
+global $rigport, $rigs, $rignames, $rigbuttons;
 global $mcast, $mcastexpect, $mcastaddr, $mcastport, $mcastcode;
 global $mcast, $mcastexpect, $mcastaddr, $mcastport, $mcastcode;
 global $mcastlistport, $mcasttimeout, $mcastretries, $allowgen;
 global $mcastlistport, $mcasttimeout, $mcastretries, $allowgen;
 global $rigipsecurity, $rigtotals, $forcerigtotals;
 global $rigipsecurity, $rigtotals, $forcerigtotals;
@@ -49,10 +50,20 @@ $checklastshare = true;
 # N.B. also if $readonly is true, it will not display the fields
 # N.B. also if $readonly is true, it will not display the fields
 $poolinputs = false;
 $poolinputs = false;
 #
 #
+# Default port to use if any $rigs entries don't specify the port number
+$rigport = 4028;
+#
 # Set $rigs to an array of your BFGMiner rigs that are running
 # Set $rigs to an array of your BFGMiner rigs that are running
-#  format: 'IP:Port' or 'Host:Port' or 'Host:Port:Name'
+#  format: 'IP' or 'Host' or 'IP:Port' or 'Host:Port' or 'Host:Port:Name'
 $rigs = array('127.0.0.1:4028');
 $rigs = array('127.0.0.1:4028');
 #
 #
+# Set $rignames to false, or one of 'ip' or 'ipx'
+#  this says what to use if $rigs doesn't have a 'name'
+$rignames = false;
+#
+# Set $rigbuttons to false to display a link rather than a button
+$rigbuttons = true;
+#
 # Set $mcast to true to look for your rigs and ignore $rigs
 # Set $mcast to true to look for your rigs and ignore $rigs
 $mcast = false;
 $mcast = false;
 #
 #
@@ -247,6 +258,9 @@ $colourtable = array(
 $miner = null;
 $miner = null;
 $port = null;
 $port = null;
 #
 #
+global $rigips;
+$rigips = array();
+#
 # Ensure it is only ever shown once
 # Ensure it is only ever shown once
 global $showndate;
 global $showndate;
 $showndate = false;
 $showndate = false;
@@ -289,6 +303,14 @@ function getdom($domname)
  return getcss($domname, true);
  return getcss($domname, true);
 }
 }
 #
 #
+# N.B. don't call this before calling htmlhead()
+function php_pr($cmd)
+{
+ global $here, $autorefresh;
+
+ return "$here?ref=$autorefresh$cmd";
+}
+#
 function htmlhead($mcerr, $checkapi, $rig, $pg = null, $noscript = false)
 function htmlhead($mcerr, $checkapi, $rig, $pg = null, $noscript = false)
 {
 {
  global $doctype, $title, $miner_font_family, $miner_font_size;
  global $doctype, $title, $miner_font_family, $miner_font_size;
@@ -491,9 +513,12 @@ function getrigs()
 #
 #
 function getsock($rig, $addr, $port)
 function getsock($rig, $addr, $port)
 {
 {
- global $rigipsecurity;
+ global $rigport, $rigips, $rignames, $rigipsecurity;
  global $haderror, $error, $socksndtimeoutsec, $sockrcvtimeoutsec;
  global $haderror, $error, $socksndtimeoutsec, $sockrcvtimeoutsec;
 
 
+ $port = trim($port);
+ if (strlen($port) == 0)
+	$port = $rigport;
  $error = null;
  $error = null;
  $socket = null;
  $socket = null;
  $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
@@ -534,6 +559,9 @@ function getsock($rig, $addr, $port)
 	socket_close($socket);
 	socket_close($socket);
 	return null;
 	return null;
  }
  }
+ if ($rignames !== false && !isset($rigips[$addr]))
+	if (socket_getpeername($socket, $ip) == true)
+		$rigips[$addr] = $ip;
  return $socket;
  return $socket;
 }
 }
 #
 #
@@ -1567,39 +1595,67 @@ function process($cmds, $rig)
 #
 #
 function rigname($rig, $rigname)
 function rigname($rig, $rigname)
 {
 {
- global $rigs;
+ global $rigs, $rignames, $rigips;
 
 
  if (isset($rigs[$rig]))
  if (isset($rigs[$rig]))
  {
  {
 	$parts = explode(':', $rigs[$rig], 3);
 	$parts = explode(':', $rigs[$rig], 3);
 	if (count($parts) == 3)
 	if (count($parts) == 3)
 		$rigname = $parts[2];
 		$rigname = $parts[2];
+	else
+		if ($rignames !== false)
+		{
+			switch ($rignames)
+			{
+			case 'ip':
+				if (isset($parts[0]) && isset($rigips[$parts[0]]))
+				{
+					$ip = explode('.', $rigips[$parts[0]]);
+					if (count($ip) == 4)
+						$rigname = intval($ip[3]);
+				}
+				break;
+			case 'ipx':
+				if (isset($parts[0]) && isset($rigips[$parts[0]]))
+				{
+					$ip = explode('.', $rigips[$parts[0]]);
+					if (count($ip) == 4)
+						$rigname = intval($ip[3], 16);
+				}
+				break;
+			}
+		}
  }
  }
 
 
  return $rigname;
  return $rigname;
 }
 }
 #
 #
-function riginput($rig, $rigname)
+function riginput($rig, $rigname, $usebuttons)
 {
 {
  $rigname = rigname($rig, $rigname);
  $rigname = rigname($rig, $rigname);
 
 
- return "<input type=button value='$rigname' onclick='pr(\"&rig=$rig\",null)'>";
+ if ($usebuttons === true)
+	return "<input type=button value='$rigname' onclick='pr(\"&rig=$rig\",null)'>";
+ else
+	return "<a href='".php_pr("&rig=$rig")."'>$rigname</a>";
 }
 }
 #
 #
-function rigbutton($rig, $rigname, $when, $row)
+function rigbutton($rig, $rigname, $when, $row, $usebuttons)
 {
 {
  list($value, $class) = fmt('BUTTON', 'Rig', '', $when, $row);
  list($value, $class) = fmt('BUTTON', 'Rig', '', $when, $row);
 
 
  if ($rig === '')
  if ($rig === '')
 	$ri = '&nbsp;';
 	$ri = '&nbsp;';
  else
  else
-	$ri = riginput($rig, $rigname);
+	$ri = riginput($rig, $rigname, $usebuttons);
 
 
  return "<td align=middle$class>$ri</td>";
  return "<td align=middle$class>$ri</td>";
 }
 }
 #
 #
 function showrigs($anss, $headname, $rigname)
 function showrigs($anss, $headname, $rigname)
 {
 {
+ global $rigbuttons;
+
  $dthead = array($headname => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1, 'API' => 1, 'CGMiner' => 1);
  $dthead = array($headname => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1, 'API' => 1, 'CGMiner' => 1);
  showhead('', $dthead);
  showhead('', $dthead);
 
 
@@ -1622,7 +1678,7 @@ function showrigs($anss, $headname, $rigname)
 		foreach ($dthead as $name => $x)
 		foreach ($dthead as $name => $x)
 		{
 		{
 			if ($item == 'STATUS' && $name == $headname)
 			if ($item == 'STATUS' && $name == $headname)
-				echo rigbutton($rig, $rigname.$rig, $when, null);
+				echo rigbutton($rig, $rigname.$rig, $when, null, $rigbuttons);
 			else
 			else
 			{
 			{
 				if (isset($row[$name]))
 				if (isset($row[$name]))
@@ -1641,7 +1697,7 @@ function showrigs($anss, $headname, $rigname)
 function doforeach($cmd, $des, $sum, $head, $datetime)
 function doforeach($cmd, $des, $sum, $head, $datetime)
 {
 {
  global $miner, $port;
  global $miner, $port;
- global $error, $readonly, $notify, $rigs;
+ global $error, $readonly, $notify, $rigs, $rigbuttons;
  global $warnfont, $warnoff, $dfmt;
  global $warnfont, $warnoff, $dfmt;
  global $rigerror;
  global $rigerror;
 
 
@@ -1660,10 +1716,13 @@ function doforeach($cmd, $des, $sum, $head, $datetime)
 		continue;
 		continue;
 
 
 	$parts = explode(':', $rig, 3);
 	$parts = explode(':', $rig, 3);
-	if (count($parts) >= 2)
+	if (count($parts) >= 1)
 	{
 	{
 		$miner = $parts[0];
 		$miner = $parts[0];
-		$port = $parts[1];
+		if (count($parts) >= 2)
+			$port = $parts[1];
+		else
+			$port = '';
 
 
 		if (count($parts) > 2)
 		if (count($parts) > 2)
 			$name = $parts[2];
 			$name = $parts[2];
@@ -1778,7 +1837,7 @@ function doforeach($cmd, $des, $sum, $head, $datetime)
 					echo "<td align=right$class>Total:</td>";
 					echo "<td align=right$class>Total:</td>";
 				}
 				}
 				else
 				else
-					echo rigbutton($rig, "Rig $rig", $when, $row);
+					echo rigbutton($rig, "Rig $rig", $when, $row, $rigbuttons);
 			}
 			}
 			else
 			else
 			{
 			{
@@ -1811,7 +1870,7 @@ function refreshbuttons()
 #
 #
 function pagebuttons($rig, $pg)
 function pagebuttons($rig, $pg)
 {
 {
- global $readonly, $rigs, $userlist, $ses;
+ global $readonly, $rigs, $rigbuttons, $userlist, $ses;
  global $allowcustompages, $customsummarypages;
  global $allowcustompages, $customsummarypages;
 
 
  if ($rig === null)
  if ($rig === null)
@@ -1850,10 +1909,12 @@ function pagebuttons($rig, $pg)
  if ($userlist === null || isset($_SESSION[$ses]))
  if ($userlist === null || isset($_SESSION[$ses]))
  {
  {
 	if ($prev !== null)
 	if ($prev !== null)
-		echo riginput($prev, 'Prev').'&nbsp;';
+		echo riginput($prev, 'Prev', true).'&nbsp;';
+
 	echo "<input type=button value='Refresh' onclick='pr(\"$refresh\",null)'>&nbsp;";
 	echo "<input type=button value='Refresh' onclick='pr(\"$refresh\",null)'>&nbsp;";
+
 	if ($next !== null)
 	if ($next !== null)
-		echo riginput($next, 'Next').'&nbsp;';
+		echo riginput($next, 'Next', true).'&nbsp;';
 	echo '&nbsp;';
 	echo '&nbsp;';
 	if (count($rigs) > 1)
 	if (count($rigs) > 1)
 		echo "<input type=button value='Summary' onclick='pr(\"\",null)'>&nbsp;";
 		echo "<input type=button value='Summary' onclick='pr(\"\",null)'>&nbsp;";
@@ -2215,6 +2276,8 @@ function secmatch($section, $field)
 #
 #
 function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total)
 function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total)
 {
 {
+ global $rigbuttons;
+
  foreach ($result as $sec => $row)
  foreach ($result as $sec => $row)
  {
  {
 	$secname = preg_replace('/\d/', '', $sec);
 	$secname = preg_replace('/\d/', '', $sec);
@@ -2231,7 +2294,7 @@ function customset($showfields, $sum, $section, $rig, $isbutton, $result, $total
 
 
 
 
 	if ($isbutton)
 	if ($isbutton)
-		echo rigbutton($rig, $rig, $when, $row);
+		echo rigbutton($rig, $rig, $when, $row, $rigbuttons);
 	else
 	else
 	{
 	{
 		list($ignore, $class) = fmt('total', '', '', $when, $row);
 		list($ignore, $class) = fmt('total', '', '', $when, $row);
@@ -2566,10 +2629,13 @@ function processcustompage($pagename, $sections, $sum, $ext, $namemap)
  foreach ($rigs as $num => $rig)
  foreach ($rigs as $num => $rig)
  {
  {
 	$parts = explode(':', $rig, 3);
 	$parts = explode(':', $rig, 3);
-	if (count($parts) >= 2)
+	if (count($parts) >= 1)
 	{
 	{
 		$miner = $parts[0];
 		$miner = $parts[0];
-		$port = $parts[1];
+		if (count($parts) >= 2)
+			$port = $parts[1];
+		else
+			$port = '';
 
 
 		if (count($parts) > 2)
 		if (count($parts) > 2)
 			$name = $parts[2];
 			$name = $parts[2];
@@ -2927,10 +2993,13 @@ function display()
 		if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
 		if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
 		{
 		{
 			$parts = explode(':', $rigs[$rig], 3);
 			$parts = explode(':', $rigs[$rig], 3);
-			if (count($parts) >= 2)
+			if (count($parts) >= 1)
 			{
 			{
 				$miner = $parts[0];
 				$miner = $parts[0];
-				$port = $parts[1];
+				if (count($parts) >= 2)
+					$port = $parts[1];
+				else
+					$port = '';
 
 
 				if ($readonly !== true)
 				if ($readonly !== true)
 					$preprocess = $arg;
 					$preprocess = $arg;
@@ -2979,10 +3048,13 @@ function display()
  if (count($rigs) == 1)
  if (count($rigs) == 1)
  {
  {
 	$parts = explode(':', $rigs[0], 3);
 	$parts = explode(':', $rigs[0], 3);
-	if (count($parts) >= 2)
+	if (count($parts) >= 1)
 	{
 	{
 		$miner = $parts[0];
 		$miner = $parts[0];
-		$port = $parts[1];
+		if (count($parts) >= 2)
+			$port = $parts[1];
+		else
+			$port = '';
 
 
 		htmlhead($mcerr, true, 0);
 		htmlhead($mcerr, true, 0);
 		doOne(0, $preprocess);
 		doOne(0, $preprocess);
@@ -2999,10 +3071,13 @@ function display()
  if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
  if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs))
  {
  {
 	$parts = explode(':', $rigs[$rig], 3);
 	$parts = explode(':', $rigs[$rig], 3);
-	if (count($parts) >= 2)
+	if (count($parts) >= 1)
 	{
 	{
 		$miner = $parts[0];
 		$miner = $parts[0];
-		$port = $parts[1];
+		if (count($parts) >= 2)
+			$port = $parts[1];
+		else
+			$port = '';
 
 
 		htmlhead($mcerr, true, 0);
 		htmlhead($mcerr, true, 0);
 		doOne($rig, $preprocess);
 		doOne($rig, $preprocess);

+ 5 - 2
util.c

@@ -1565,11 +1565,14 @@ static enum send_ret __stratum_send(struct pool *pool, char *s, ssize_t len)
 		struct timeval timeout = {1, 0};
 		struct timeval timeout = {1, 0};
 		ssize_t sent;
 		ssize_t sent;
 		fd_set wd;
 		fd_set wd;
-
+retry:
 		FD_ZERO(&wd);
 		FD_ZERO(&wd);
 		FD_SET(sock, &wd);
 		FD_SET(sock, &wd);
-		if (select(sock + 1, NULL, &wd, NULL, &timeout) < 1)
+		if (select(sock + 1, NULL, &wd, NULL, &timeout) < 1) {
+			if (interrupted())
+				goto retry;
 			return SEND_SELECTFAIL;
 			return SEND_SELECTFAIL;
+		}
 #ifdef __APPLE__
 #ifdef __APPLE__
 		sent = send(pool->sock, s + ssent, len, SO_NOSIGPIPE);
 		sent = send(pool->sock, s + ssent, len, SO_NOSIGPIPE);
 #elif WIN32
 #elif WIN32

+ 11 - 1
util.h

@@ -43,6 +43,10 @@
 	{
 	{
 		return (errno == EAGAIN || errno == EWOULDBLOCK);
 		return (errno == EAGAIN || errno == EWOULDBLOCK);
 	}
 	}
+	static inline bool interrupted(void)
+	{
+		return (errno == EINTR);
+	}
 #elif defined WIN32
 #elif defined WIN32
 	#include <ws2tcpip.h>
 	#include <ws2tcpip.h>
 	#include <winsock2.h>
 	#include <winsock2.h>
@@ -56,9 +60,15 @@
 	#define SOCKERR (WSAGetLastError())
 	#define SOCKERR (WSAGetLastError())
 	#define SOCKERRMSG bfg_strerror(WSAGetLastError(), BST_SOCKET)
 	#define SOCKERRMSG bfg_strerror(WSAGetLastError(), BST_SOCKET)
 
 
+	/* Check for windows variants of the errors as well as when ming
+	 * decides to wrap the error into the errno equivalent. */
 	static inline bool sock_blocks(void)
 	static inline bool sock_blocks(void)
 	{
 	{
-		return (WSAGetLastError() == WSAEWOULDBLOCK);
+		return (WSAGetLastError() == WSAEWOULDBLOCK || errno == EAGAIN);
+	}
+	static inline bool interrupted(void)
+	{
+		return (WSAGetLastError() == WSAEINTR || errno == EINTR);
 	}
 	}
 	#ifndef SHUT_RDWR
 	#ifndef SHUT_RDWR
 	#define SHUT_RDWR SD_BOTH
 	#define SHUT_RDWR SD_BOTH