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
c13004f9
Commit
c13004f9
authored
Oct 15, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/curl/Multi: add Add(), Remove(), ...
parent
baba41e3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
10 deletions
+44
-10
Global.cxx
src/lib/curl/Global.cxx
+3
-8
Global.hxx
src/lib/curl/Global.hxx
+1
-1
Multi.hxx
src/lib/curl/Multi.hxx
+40
-1
No files found.
src/lib/curl/Global.cxx
View file @
c13004f9
...
@@ -158,10 +158,7 @@ CurlGlobal::Add(CurlRequest &r)
...
@@ -158,10 +158,7 @@ CurlGlobal::Add(CurlRequest &r)
{
{
assert
(
GetEventLoop
().
IsInside
());
assert
(
GetEventLoop
().
IsInside
());
CURLMcode
mcode
=
curl_multi_add_handle
(
multi
.
Get
(),
r
.
Get
());
multi
.
Add
(
r
.
Get
());
if
(
mcode
!=
CURLM_OK
)
throw
FormatRuntimeError
(
"curl_multi_add_handle() failed: %s"
,
curl_multi_strerror
(
mcode
));
InvalidateSockets
();
InvalidateSockets
();
}
}
...
@@ -171,7 +168,7 @@ CurlGlobal::Remove(CurlRequest &r) noexcept
...
@@ -171,7 +168,7 @@ CurlGlobal::Remove(CurlRequest &r) noexcept
{
{
assert
(
GetEventLoop
().
IsInside
());
assert
(
GetEventLoop
().
IsInside
());
curl_multi_remove_handle
(
multi
.
Get
(),
r
.
Get
());
multi
.
Remove
(
r
.
Get
());
}
}
/**
/**
...
@@ -195,10 +192,8 @@ CurlGlobal::ReadInfo() noexcept
...
@@ -195,10 +192,8 @@ CurlGlobal::ReadInfo() noexcept
assert
(
GetEventLoop
().
IsInside
());
assert
(
GetEventLoop
().
IsInside
());
CURLMsg
*
msg
;
CURLMsg
*
msg
;
int
msgs_in_queue
;
while
((
msg
=
curl_multi_info_read
(
multi
.
Get
(),
while
((
msg
=
multi
.
InfoRead
())
!=
nullptr
)
{
&
msgs_in_queue
))
!=
nullptr
)
{
if
(
msg
->
msg
==
CURLMSG_DONE
)
{
if
(
msg
->
msg
==
CURLMSG_DONE
)
{
auto
*
request
=
ToRequest
(
msg
->
easy_handle
);
auto
*
request
=
ToRequest
(
msg
->
easy_handle
);
if
(
request
!=
nullptr
)
if
(
request
!=
nullptr
)
...
...
src/lib/curl/Global.hxx
View file @
c13004f9
/*
/*
* Copyright 2008-20
19
Max Kellermann <max.kellermann@gmail.com>
* Copyright 2008-20
20
Max Kellermann <max.kellermann@gmail.com>
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
...
...
src/lib/curl/Multi.hxx
View file @
c13004f9
/*
/*
* Copyright 2016-20
18
Max Kellermann <max.kellermann@gmail.com>
* Copyright 2016-20
20
Max Kellermann <max.kellermann@gmail.com>
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
#include <curl/curl.h>
#include <curl/curl.h>
#include <chrono>
#include <utility>
#include <utility>
#include <stdexcept>
#include <stdexcept>
#include <cstddef>
#include <cstddef>
...
@@ -87,6 +88,44 @@ public:
...
@@ -87,6 +88,44 @@ public:
if
(
code
!=
CURLM_OK
)
if
(
code
!=
CURLM_OK
)
throw
std
::
runtime_error
(
curl_multi_strerror
(
code
));
throw
std
::
runtime_error
(
curl_multi_strerror
(
code
));
}
}
void
Add
(
CURL
*
easy_handle
)
{
auto
code
=
curl_multi_add_handle
(
handle
,
easy_handle
);
if
(
code
!=
CURLM_OK
)
throw
std
::
runtime_error
(
curl_multi_strerror
(
code
));
}
void
Remove
(
CURL
*
easy_handle
)
{
auto
code
=
curl_multi_remove_handle
(
handle
,
easy_handle
);
if
(
code
!=
CURLM_OK
)
throw
std
::
runtime_error
(
curl_multi_strerror
(
code
));
}
CURLMsg
*
InfoRead
()
{
int
msgs_in_queue
;
return
curl_multi_info_read
(
handle
,
&
msgs_in_queue
);
}
unsigned
Perform
()
{
int
running_handles
;
auto
code
=
curl_multi_perform
(
handle
,
&
running_handles
);
if
(
code
!=
CURLM_OK
)
throw
std
::
runtime_error
(
curl_multi_strerror
(
code
));
return
running_handles
;
}
unsigned
Wait
(
int
timeout
=-
1
)
{
int
numfds
;
auto
code
=
curl_multi_wait
(
handle
,
nullptr
,
0
,
timeout
,
&
numfds
);
if
(
code
!=
CURLM_OK
)
throw
std
::
runtime_error
(
curl_multi_strerror
(
code
));
return
numfds
;
}
unsigned
Wait
(
std
::
chrono
::
milliseconds
timeout
)
{
return
Wait
(
timeout
.
count
());
}
};
};
#endif
#endif
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