mirror of
https://github.com/owntone/owntone-server.git
synced 2025-04-23 03:55:42 -04:00
Drop async mode from http client, not needed and probably not working
This commit is contained in:
parent
e49c941a00
commit
19ba8fba67
@ -721,7 +721,6 @@ artwork_get_player_image(char *path, int max_w, int max_h, struct evbuffer *evbu
|
|||||||
|
|
||||||
memset(&ctx, 0, sizeof(ctx));
|
memset(&ctx, 0, sizeof(ctx));
|
||||||
ctx.url = url;
|
ctx.url = url;
|
||||||
ctx.async = 0;
|
|
||||||
ctx.headers = kv;
|
ctx.headers = kv;
|
||||||
ctx.body = evbuf;
|
ctx.body = evbuf;
|
||||||
|
|
||||||
|
72
src/http.c
72
src/http.c
@ -31,8 +31,6 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
#include <libavutil/opt.h>
|
#include <libavutil/opt.h>
|
||||||
|
|
||||||
#include <event2/event.h>
|
#include <event2/event.h>
|
||||||
@ -94,9 +92,6 @@ request_cb(struct evhttp_request *req, void *arg)
|
|||||||
|
|
||||||
event_base_loopbreak(ctx->evbase);
|
event_base_loopbreak(ctx->evbase);
|
||||||
|
|
||||||
if (ctx->async)
|
|
||||||
free(ctx);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,24 +119,15 @@ request_cb(struct evhttp_request *req, void *arg)
|
|||||||
goto connection_error;
|
goto connection_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Async: we make a callback to caller, Sync: we move the body into the callers evbuf */
|
|
||||||
ctx->ret = 0;
|
ctx->ret = 0;
|
||||||
|
|
||||||
if (!ctx->async)
|
|
||||||
{
|
|
||||||
if (ctx->headers)
|
if (ctx->headers)
|
||||||
headers_save(ctx->headers, evhttp_request_get_input_headers(req));
|
headers_save(ctx->headers, evhttp_request_get_input_headers(req));
|
||||||
if (ctx->body)
|
if (ctx->body)
|
||||||
evbuffer_add_buffer(ctx->body, evhttp_request_get_input_buffer(req));
|
evbuffer_add_buffer(ctx->body, evhttp_request_get_input_buffer(req));
|
||||||
}
|
|
||||||
else
|
|
||||||
ctx->cb(req, arg);
|
|
||||||
|
|
||||||
event_base_loopbreak(ctx->evbase);
|
event_base_loopbreak(ctx->evbase);
|
||||||
|
|
||||||
if (ctx->async)
|
|
||||||
free(ctx);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
connection_error:
|
connection_error:
|
||||||
@ -150,9 +136,6 @@ request_cb(struct evhttp_request *req, void *arg)
|
|||||||
|
|
||||||
event_base_loopbreak(ctx->evbase);
|
event_base_loopbreak(ctx->evbase);
|
||||||
|
|
||||||
if (ctx->async)
|
|
||||||
free(ctx);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,10 +164,9 @@ request_header_cb(struct evhttp_request *req, void *arg)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void *
|
int
|
||||||
request_make(void *arg)
|
http_client_request(struct http_client_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct http_client_ctx *ctx;
|
|
||||||
struct evhttp_connection *evcon;
|
struct evhttp_connection *evcon;
|
||||||
struct evhttp_request *req;
|
struct evhttp_request *req;
|
||||||
struct evkeyvalq *headers;
|
struct evkeyvalq *headers;
|
||||||
@ -194,8 +176,6 @@ request_make(void *arg)
|
|||||||
int port;
|
int port;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ctx = (struct http_client_ctx *)arg;
|
|
||||||
|
|
||||||
ctx->ret = -1;
|
ctx->ret = -1;
|
||||||
|
|
||||||
av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, path, sizeof(path), ctx->url);
|
av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, path, sizeof(path), ctx->url);
|
||||||
@ -203,7 +183,7 @@ request_make(void *arg)
|
|||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_HTTP, "Error extracting hostname from URL: %s\n", ctx->url);
|
DPRINTF(E_LOG, L_HTTP, "Error extracting hostname from URL: %s\n", ctx->url);
|
||||||
|
|
||||||
return NULL;
|
return ctx->ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (port <= 0)
|
if (port <= 0)
|
||||||
@ -220,7 +200,7 @@ request_make(void *arg)
|
|||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_HTTP, "Could not create or find http client event base\n");
|
DPRINTF(E_LOG, L_HTTP, "Could not create or find http client event base\n");
|
||||||
|
|
||||||
return NULL;
|
return ctx->ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
evcon = evhttp_connection_base_new(ctx->evbase, NULL, hostname, (unsigned short)port);
|
evcon = evhttp_connection_base_new(ctx->evbase, NULL, hostname, (unsigned short)port);
|
||||||
@ -229,7 +209,7 @@ request_make(void *arg)
|
|||||||
DPRINTF(E_LOG, L_HTTP, "Could not create connection to %s\n", hostname);
|
DPRINTF(E_LOG, L_HTTP, "Could not create connection to %s\n", hostname);
|
||||||
|
|
||||||
event_base_free(ctx->evbase);
|
event_base_free(ctx->evbase);
|
||||||
return NULL;
|
return ctx->ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
evhttp_connection_set_timeout(evcon, HTTP_CLIENT_TIMEOUT);
|
evhttp_connection_set_timeout(evcon, HTTP_CLIENT_TIMEOUT);
|
||||||
@ -242,7 +222,7 @@ request_make(void *arg)
|
|||||||
|
|
||||||
evhttp_connection_free(evcon);
|
evhttp_connection_free(evcon);
|
||||||
event_base_free(ctx->evbase);
|
event_base_free(ctx->evbase);
|
||||||
return NULL;
|
return ctx->ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef HAVE_LIBEVENT2_OLD
|
#ifndef HAVE_LIBEVENT2_OLD
|
||||||
@ -267,7 +247,7 @@ request_make(void *arg)
|
|||||||
|
|
||||||
evhttp_connection_free(evcon);
|
evhttp_connection_free(evcon);
|
||||||
event_base_free(ctx->evbase);
|
event_base_free(ctx->evbase);
|
||||||
return NULL;
|
return ctx->ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
event_base_dispatch(ctx->evbase);
|
event_base_dispatch(ctx->evbase);
|
||||||
@ -275,41 +255,7 @@ request_make(void *arg)
|
|||||||
evhttp_connection_free(evcon);
|
evhttp_connection_free(evcon);
|
||||||
event_base_free(ctx->evbase);
|
event_base_free(ctx->evbase);
|
||||||
|
|
||||||
return NULL;
|
return ctx->ret;
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
http_client_request(struct http_client_ctx *ctx)
|
|
||||||
{
|
|
||||||
pthread_t tid;
|
|
||||||
pthread_attr_t attr;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* If async make the request in a spawned thread, otherwise just make it */
|
|
||||||
if (ctx->async)
|
|
||||||
{
|
|
||||||
ret = pthread_attr_init(&attr);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_HTTP, "Error in http_client_request: Could not init attributes\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
|
||||||
ret = pthread_create(&tid, &attr, request_make, ctx);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_HTTP, "Error in http_client_request: Could not create thread\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
request_make(ctx);
|
|
||||||
ret = ctx->ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -338,7 +284,6 @@ http_stream_setup(char **stream, const char *url)
|
|||||||
if (!evbuf)
|
if (!evbuf)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ctx.async = 0;
|
|
||||||
ctx.url = url;
|
ctx.url = url;
|
||||||
ctx.body = evbuf;
|
ctx.body = evbuf;
|
||||||
|
|
||||||
@ -560,7 +505,6 @@ http_icy_metadata_get(AVFormatContext *fmtctx, int packet_only)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
memset(&ctx, 0, sizeof(struct http_client_ctx));
|
memset(&ctx, 0, sizeof(struct http_client_ctx));
|
||||||
ctx.async = 0;
|
|
||||||
ctx.url = fmtctx->filename;
|
ctx.url = fmtctx->filename;
|
||||||
ctx.headers = kv;
|
ctx.headers = kv;
|
||||||
ctx.headers_only = 1;
|
ctx.headers_only = 1;
|
||||||
|
11
src/http.h
11
src/http.h
@ -10,11 +10,10 @@
|
|||||||
|
|
||||||
struct http_client_ctx
|
struct http_client_ctx
|
||||||
{
|
{
|
||||||
int async;
|
|
||||||
const char *url;
|
const char *url;
|
||||||
|
|
||||||
/* For sync mode, a keyval/evbuf to store response headers and body
|
/* A keyval/evbuf to store response headers and body.
|
||||||
* Can be set to NULL to ignore that part of the response
|
* Can be set to NULL to ignore that part of the response.
|
||||||
*/
|
*/
|
||||||
struct keyval *headers;
|
struct keyval *headers;
|
||||||
struct evbuffer *body;
|
struct evbuffer *body;
|
||||||
@ -25,9 +24,6 @@ struct http_client_ctx
|
|||||||
*/
|
*/
|
||||||
int headers_only;
|
int headers_only;
|
||||||
|
|
||||||
/* For async mode */
|
|
||||||
void (*cb)(struct evhttp_request *, void *);
|
|
||||||
|
|
||||||
/* Private */
|
/* Private */
|
||||||
int ret;
|
int ret;
|
||||||
void *evbase;
|
void *evbase;
|
||||||
@ -51,8 +47,7 @@ struct http_icy_metadata
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* Generic HTTP client
|
/* Generic HTTP client. No support for https.
|
||||||
* Can be called blocking or non-blocking. No support for https.
|
|
||||||
*
|
*
|
||||||
* @param ctx HTTP request params, see above
|
* @param ctx HTTP request params, see above
|
||||||
* @return 0 if successful, -1 if an error occurred
|
* @return 0 if successful, -1 if an error occurred
|
||||||
|
Loading…
x
Reference in New Issue
Block a user