Add a flags argument to json_rpc_call()
This commit is contained in:
parent
6b2e46d4ac
commit
9aa776cf94
3 changed files with 16 additions and 12 deletions
|
@ -392,7 +392,7 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
|
||||||
str);
|
str);
|
||||||
|
|
||||||
/* issue JSON-RPC request */
|
/* issue JSON-RPC request */
|
||||||
val = json_rpc_call(curl, rpc_url, rpc_userpass, s, false, false, NULL);
|
val = json_rpc_call(curl, rpc_url, rpc_userpass, s, NULL, 0);
|
||||||
if (unlikely(!val)) {
|
if (unlikely(!val)) {
|
||||||
applog(LOG_ERR, "submit_upstream_work json_rpc_call failed");
|
applog(LOG_ERR, "submit_upstream_work json_rpc_call failed");
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -422,8 +422,7 @@ static bool get_upstream_work(CURL *curl, struct work *work)
|
||||||
struct timeval tv_start, tv_end, diff;
|
struct timeval tv_start, tv_end, diff;
|
||||||
|
|
||||||
gettimeofday(&tv_start, NULL);
|
gettimeofday(&tv_start, NULL);
|
||||||
val = json_rpc_call(curl, rpc_url, rpc_userpass, rpc_req,
|
val = json_rpc_call(curl, rpc_url, rpc_userpass, rpc_req, NULL, 0);
|
||||||
want_longpoll, false, NULL);
|
|
||||||
gettimeofday(&tv_end, NULL);
|
gettimeofday(&tv_end, NULL);
|
||||||
|
|
||||||
if (have_stratum) {
|
if (have_stratum) {
|
||||||
|
@ -874,8 +873,8 @@ start:
|
||||||
json_t *val, *soval;
|
json_t *val, *soval;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
val = json_rpc_call(curl, lp_url, rpc_userpass, rpc_req,
|
val = json_rpc_call(curl, lp_url, rpc_userpass, rpc_req, &err,
|
||||||
false, true, &err);
|
JSON_RPC_LONGPOLL);
|
||||||
if (have_stratum) {
|
if (have_stratum) {
|
||||||
if (val)
|
if (val)
|
||||||
json_decref(val);
|
json_decref(val);
|
||||||
|
|
5
miner.h
5
miner.h
|
@ -184,9 +184,12 @@ extern int longpoll_thr_id;
|
||||||
extern int stratum_thr_id;
|
extern int stratum_thr_id;
|
||||||
extern struct work_restart *work_restart;
|
extern struct work_restart *work_restart;
|
||||||
|
|
||||||
|
#define JSON_RPC_LONGPOLL (1 << 0)
|
||||||
|
#define JSON_RPC_QUIET_404 (1 << 1)
|
||||||
|
|
||||||
extern void applog(int prio, const char *fmt, ...);
|
extern void applog(int prio, const char *fmt, ...);
|
||||||
extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
|
extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
|
||||||
const char *rpc_req, bool, bool, int *);
|
const char *rpc_req, int *curl_err, int flags);
|
||||||
extern char *bin2hex(const unsigned char *p, size_t len);
|
extern char *bin2hex(const unsigned char *p, size_t len);
|
||||||
extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
|
extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
|
||||||
extern int timeval_subtract(struct timeval *result, struct timeval *x,
|
extern int timeval_subtract(struct timeval *result, struct timeval *x,
|
||||||
|
|
14
util.c
14
util.c
|
@ -296,19 +296,19 @@ static int sockopt_keepalive_cb(void *userdata, curl_socket_t fd,
|
||||||
|
|
||||||
json_t *json_rpc_call(CURL *curl, const char *url,
|
json_t *json_rpc_call(CURL *curl, const char *url,
|
||||||
const char *userpass, const char *rpc_req,
|
const char *userpass, const char *rpc_req,
|
||||||
bool longpoll_scan, bool longpoll, int *curl_err)
|
int *curl_err, int flags)
|
||||||
{
|
{
|
||||||
json_t *val, *err_val, *res_val;
|
json_t *val, *err_val, *res_val;
|
||||||
int rc;
|
int rc;
|
||||||
|
long http_rc;
|
||||||
struct data_buffer all_data = {0};
|
struct data_buffer all_data = {0};
|
||||||
struct upload_buffer upload_data;
|
struct upload_buffer upload_data;
|
||||||
json_error_t err;
|
json_error_t err;
|
||||||
struct curl_slist *headers = NULL;
|
struct curl_slist *headers = NULL;
|
||||||
char len_hdr[64];
|
char len_hdr[64];
|
||||||
char curl_err_str[CURL_ERROR_SIZE];
|
char curl_err_str[CURL_ERROR_SIZE];
|
||||||
long timeout = longpoll ? opt_timeout : 30;
|
long timeout = (flags & JSON_RPC_LONGPOLL) ? opt_timeout : 30;
|
||||||
struct header_info hi = {0};
|
struct header_info hi = {0};
|
||||||
bool lp_scanning = longpoll_scan && !have_longpoll;
|
|
||||||
|
|
||||||
/* it is assumed that 'curl' is freshly [re]initialized at this pt */
|
/* it is assumed that 'curl' is freshly [re]initialized at this pt */
|
||||||
|
|
||||||
|
@ -343,7 +343,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
|
||||||
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||||
}
|
}
|
||||||
#if LIBCURL_VERSION_NUM >= 0x070f06
|
#if LIBCURL_VERSION_NUM >= 0x070f06
|
||||||
if (longpoll)
|
if (flags & JSON_RPC_LONGPOLL)
|
||||||
curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_keepalive_cb);
|
curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_keepalive_cb);
|
||||||
#endif
|
#endif
|
||||||
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
||||||
|
@ -370,7 +370,9 @@ json_t *json_rpc_call(CURL *curl, const char *url,
|
||||||
if (curl_err != NULL)
|
if (curl_err != NULL)
|
||||||
*curl_err = rc;
|
*curl_err = rc;
|
||||||
if (rc) {
|
if (rc) {
|
||||||
if (!(longpoll && rc == CURLE_OPERATION_TIMEDOUT))
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_rc);
|
||||||
|
if (!((flags & JSON_RPC_LONGPOLL) && rc == CURLE_OPERATION_TIMEDOUT) &&
|
||||||
|
!((flags & JSON_RPC_QUIET_404) && http_rc == 404))
|
||||||
applog(LOG_ERR, "HTTP request failed: %s", curl_err_str);
|
applog(LOG_ERR, "HTTP request failed: %s", curl_err_str);
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
|
@ -385,7 +387,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If X-Long-Polling was found, activate long polling */
|
/* If X-Long-Polling was found, activate long polling */
|
||||||
if (lp_scanning && hi.lp_path && !have_stratum) {
|
if (!have_longpoll && want_longpoll && hi.lp_path && !have_stratum) {
|
||||||
have_longpoll = true;
|
have_longpoll = true;
|
||||||
tq_push(thr_info[longpoll_thr_id].q, hi.lp_path);
|
tq_push(thr_info[longpoll_thr_id].q, hi.lp_path);
|
||||||
hi.lp_path = NULL;
|
hi.lp_path = NULL;
|
||||||
|
|
Loading…
Reference in a new issue