Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
1f312b2e
Commit
1f312b2e
authored
Dec 11, 2020
by
Max Kellermann
Committed by
Max Kellermann
Dec 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
curl/Handler: disallow OnData() to throw
This eliminates some complexity from class CurlRequest.
parent
1e3089ff
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
8 additions
and
37 deletions
+8
-37
Handler.hxx
src/lib/curl/Handler.hxx
+1
-1
Request.cxx
src/lib/curl/Request.cxx
+1
-18
Request.hxx
src/lib/curl/Request.hxx
+0
-16
RunCurl.cxx
test/RunCurl.cxx
+6
-2
No files found.
src/lib/curl/Handler.hxx
View file @
1f312b2e
...
...
@@ -59,7 +59,7 @@ public:
/**
* Response body data has been received.
*
* May throw #Pause.
* May throw #Pause
(but nothing else)
.
*/
virtual
void
OnData
(
ConstBuffer
<
void
>
data
)
=
0
;
...
...
src/lib/curl/Request.cxx
View file @
1f312b2e
...
...
@@ -47,9 +47,7 @@
CurlRequest
::
CurlRequest
(
CurlGlobal
&
_global
,
CurlResponseHandler
&
_handler
)
:
global
(
_global
),
handler
(
_handler
),
postpone_error_event
(
global
.
GetEventLoop
(),
BIND_THIS_METHOD
(
OnPostponeError
))
:
global
(
_global
),
handler
(
_handler
)
{
error_buffer
[
0
]
=
0
;
...
...
@@ -243,13 +241,6 @@ CurlRequest::DataReceived(const void *ptr, size_t received_size) noexcept
return
received_size
;
}
catch
(
CurlResponseHandler
::
Pause
)
{
return
CURL_WRITEFUNC_PAUSE
;
}
catch
(...)
{
state
=
State
::
CLOSED
;
/* move the CurlResponseHandler::OnError() call into a
"safe" stack frame */
postponed_error
=
std
::
current_exception
();
postpone_error_event
.
Schedule
();
return
CURL_WRITEFUNC_PAUSE
;
}
}
...
...
@@ -266,11 +257,3 @@ CurlRequest::WriteFunction(char *ptr, size_t size, size_t nmemb,
return
c
.
DataReceived
(
ptr
,
size
);
}
void
CurlRequest
::
OnPostponeError
()
noexcept
{
assert
(
postponed_error
);
handler
.
OnError
(
postponed_error
);
}
src/lib/curl/Request.hxx
View file @
1f312b2e
...
...
@@ -31,11 +31,9 @@
#define CURL_REQUEST_HXX
#include "Easy.hxx"
#include "event/DeferEvent.hxx"
#include <map>
#include <string>
#include <exception>
struct
StringView
;
class
CurlGlobal
;
...
...
@@ -57,18 +55,6 @@ class CurlRequest final {
std
::
multimap
<
std
::
string
,
std
::
string
>
headers
;
/**
* An exception caught by DataReceived(), which will be
* forwarded into a "safe" stack frame by
* #postpone_error_event. This works around the
* problem that libcurl crashes if you call
* curl_multi_remove_handle() from within the WRITEFUNCTION
* (i.e. DataReceived()).
*/
std
::
exception_ptr
postponed_error
;
DeferEvent
postpone_error_event
;
/** error message provided by libcurl */
char
error_buffer
[
CURL_ERROR_SIZE
];
...
...
@@ -167,8 +153,6 @@ private:
void
HeaderFunction
(
StringView
s
)
noexcept
;
void
OnPostponeError
()
noexcept
;
/** called by curl when new data is available */
static
size_t
_HeaderFunction
(
char
*
ptr
,
size_t
size
,
size_t
nmemb
,
void
*
stream
)
noexcept
;
...
...
test/RunCurl.cxx
View file @
1f312b2e
...
...
@@ -50,8 +50,12 @@ public:
}
void
OnData
(
ConstBuffer
<
void
>
data
)
override
{
if
(
fwrite
(
data
.
data
,
data
.
size
,
1
,
stdout
)
!=
1
)
throw
std
::
runtime_error
(
"Failed to write"
);
try
{
if
(
fwrite
(
data
.
data
,
data
.
size
,
1
,
stdout
)
!=
1
)
throw
std
::
runtime_error
(
"Failed to write"
);
}
catch
(...)
{
OnError
(
std
::
current_exception
());
}
}
void
OnEnd
()
override
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment