lib/curl/Multi: add Add(), Remove(), ...
This commit is contained in:
@@ -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
|
|||||||
{
|
{
|
||||||
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
|
|||||||
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)
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2008-2019 Max Kellermann <max.kellermann@gmail.com>
|
* Copyright 2008-2020 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
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016-2018 Max Kellermann <max.kellermann@gmail.com>
|
* Copyright 2016-2020 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 @@
|
|||||||
|
|
||||||
#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:
|
|||||||
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
|
||||||
|
Reference in New Issue
Block a user