Flutter Engine
The Flutter Engine
Macros | Functions | Variables
fake_http.cc File Reference
#include <atomic>
#include <chrono>
#include <cstring>
#include <thread>

Go to the source code of this file.

Macros

#define DART_EXPORT    extern "C" __attribute__((visibility("default"))) __attribute((used))
 

Functions

DART_EXPORT void http_get (const char *uri, void(*onResponse)(const char *))
 
DART_EXPORT void http_serve (void(*onRequest)(const char *))
 

Variables

constexpr char kExampleRequest []
 
constexpr char kExampleResponse []
 

Macro Definition Documentation

◆ DART_EXPORT

#define DART_EXPORT    extern "C" __attribute__((visibility("default"))) __attribute((used))

Definition at line 13 of file fake_http.cc.

Function Documentation

◆ http_get()

DART_EXPORT void http_get ( const char *  uri,
void(*)(const char *)  onResponse 
)

Definition at line 34 of file fake_http.cc.

34 {
35 std::thread([onResponse]() {
36 std::this_thread::sleep_for(std::chrono::seconds(3));
37 onResponse(strdup(kExampleResponse));
38 }).detach();
39}
constexpr char kExampleResponse[]
Definition: fake_http.cc:22
char * strdup(const char *str1)

◆ http_serve()

DART_EXPORT void http_serve ( void(*)(const char *)  onRequest)

Definition at line 41 of file fake_http.cc.

41 {
42 std::thread([onRequest]() {
43 while (true) {
44 std::this_thread::sleep_for(std::chrono::seconds(1));
45 onRequest(strdup(kExampleRequest));
46 }
47 }).detach();
48}
constexpr char kExampleRequest[]
Definition: fake_http.cc:17

Variable Documentation

◆ kExampleRequest

constexpr char kExampleRequest[]
constexpr
Initial value:
= R"(
GET / HTTP/1.1
Host: www.example.com
)"

Definition at line 17 of file fake_http.cc.

◆ kExampleResponse

constexpr char kExampleResponse[]
constexpr
Initial value:
= R"(
HTTP/1.1 200 OK
Content-Length: 54
Content-Type: text/html; charset=UTF-8
<html>
<body>
Hello world!
</body>
</html>
)"

Definition at line 22 of file fake_http.cc.