Flutter Engine
The Flutter Engine
Classes | Functions | Variables
skiaserve.cpp File Reference
#include "tools/skiaserve/Request.h"
#include "tools/skiaserve/Response.h"
#include "include/core/SkGraphics.h"
#include "tools/flags/CommandLineFlags.h"
#include "tools/skiaserve/urlhandlers/UrlHandler.h"
#include "microhttpd.h"
#include <errno.h>
#include <sys/socket.h>
#include <arpa/inet.h>

Go to the source code of this file.

Classes

class  UrlManager
 

Functions

static DEFINE_int (port, 8888, "The port to listen on.")
 
static DEFINE_string (address, "127.0.0.1", "The address to bind to.")
 
static DEFINE_bool (hosted, false, "Running in hosted mode on debugger.skia.org.")
 
int answer_to_connection (void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls)
 
int skiaserve_main ()
 
int main (int argc, char **argv)
 

Variables

const UrlManager kUrlManager
 

Function Documentation

◆ answer_to_connection()

int answer_to_connection ( void *  cls,
struct MHD_Connection *  connection,
const char *  url,
const char *  method,
const char *  version,
const char *  upload_data,
size_t *  upload_data_size,
void **  con_cls 
)

Definition at line 74 of file skiaserve.cpp.

77 {
78 SkDebugf("New %s request for %s using version %s\n", method, url, version);
79
80 Request* request = reinterpret_cast<Request*>(cls);
81 int result = kUrlManager.invoke(request, connection, url, method, upload_data,
82 upload_data_size);
83 if (MHD_NO == result) {
84 fprintf(stderr, "Invalid method and / or url: %s %s\n", method, url);
85 }
86 return result;
87}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
int invoke(Request *request, MHD_Connection *connection, const char *url, const char *method, const char *upload_data, size_t *upload_data_size) const
Definition: skiaserve.cpp:57
GAsyncResult * result
const UrlManager kUrlManager
Definition: skiaserve.cpp:72

◆ DEFINE_bool()

static DEFINE_bool ( hosted  ,
false  ,
"Running in hosted mode on debugger.skia.org."   
)
static

◆ DEFINE_int()

static DEFINE_int ( port  ,
8888  ,
"The port to listen on."   
)
static

◆ DEFINE_string()

static DEFINE_string ( address  ,
"127.0.0.1"  ,
"The address to bind to."   
)
static

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 136 of file skiaserve.cpp.

136 {
138 return skiaserve_main();
139}
static void Parse(int argc, const char *const *argv)
char ** argv
Definition: library.h:9
int skiaserve_main()
Definition: skiaserve.cpp:89

◆ skiaserve_main()

int skiaserve_main ( )

Definition at line 89 of file skiaserve.cpp.

89 {
91 Request request(SkString("/data")); // This simple server has one request
92
93 struct sockaddr_in address;
94 address.sin_family = AF_INET;
95 address.sin_port = htons(FLAGS_port);
96 int result = inet_pton(AF_INET, FLAGS_address[0], &address.sin_addr);
97 if (result != 1) {
98 printf("inet_pton for %s:%d failed with return %d %s\n",
99 FLAGS_address[0], FLAGS_port, result, strerror(errno));
100 return 1;
101 }
102
103 printf("Visit http://%s:%d in your browser.\n", FLAGS_address[0], FLAGS_port);
104
105 struct MHD_Daemon* daemon;
106 daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY
107#ifdef SK_DEBUG
108 | MHD_USE_DEBUG
109#endif
110 , FLAGS_port, nullptr, nullptr,
111 &answer_to_connection, &request,
112 MHD_OPTION_SOCK_ADDR, &address,
113 MHD_OPTION_END);
114 if (nullptr == daemon) {
115 SkDebugf("Could not initialize daemon\n");
116 return 1;
117 }
118
119 if (FLAGS_hosted) {
120 while (1) {
121 SkDebugf("loop\n");
122 #if defined(SK_BUILD_FOR_WIN)
123 Sleep(60 * 1000);
124 #else
125 sleep(60);
126 #endif
127 }
128 } else {
129 getchar();
130 }
131 MHD_stop_daemon(daemon);
132 return 0;
133}
#define SK_DEBUG
static void Init()
Definition: SkGraphics.cpp:22
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: SkSLString.cpp:83
int answer_to_connection(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls)
Definition: skiaserve.cpp:74

Variable Documentation

◆ kUrlManager

const UrlManager kUrlManager

Definition at line 72 of file skiaserve.cpp.