OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Request.h" | 8 #include "Request.h" |
9 #include "Response.h" | 9 #include "Response.h" |
10 | 10 |
11 #include "SkCommandLineFlags.h" | 11 #include "SkCommandLineFlags.h" |
12 | 12 |
13 #include "microhttpd.h" | 13 #include "microhttpd.h" |
14 | 14 |
15 #include "urlhandlers/UrlHandler.h" | 15 #include "urlhandlers/UrlHandler.h" |
| 16 |
| 17 #include <errno.h> |
16 #include <sys/socket.h> | 18 #include <sys/socket.h> |
17 #include <arpa/inet.h> | 19 #include <arpa/inet.h> |
18 | 20 |
19 using namespace Response; | 21 using namespace Response; |
20 | 22 |
21 DEFINE_int32(port, 8888, "The port to listen on."); | 23 DEFINE_int32(port, 8888, "The port to listen on."); |
22 DEFINE_string(address, "localhost", "The address to bind to."); | 24 DEFINE_string(address, "127.0.0.1", "The address to bind to."); |
23 | 25 |
24 class UrlManager { | 26 class UrlManager { |
25 public: | 27 public: |
26 UrlManager() { | 28 UrlManager() { |
27 // Register handlers | 29 // Register handlers |
28 fHandlers.push_back(new RootHandler); | 30 fHandlers.push_back(new RootHandler); |
29 fHandlers.push_back(new PostHandler); | 31 fHandlers.push_back(new PostHandler); |
30 fHandlers.push_back(new ImgHandler); | 32 fHandlers.push_back(new ImgHandler); |
31 fHandlers.push_back(new ClipAlphaHandler); | 33 fHandlers.push_back(new ClipAlphaHandler); |
32 fHandlers.push_back(new EnableGPUHandler); | 34 fHandlers.push_back(new EnableGPUHandler); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } | 77 } |
76 return result; | 78 return result; |
77 } | 79 } |
78 | 80 |
79 int skiaserve_main() { | 81 int skiaserve_main() { |
80 Request request(SkString("/data")); // This simple server has one request | 82 Request request(SkString("/data")); // This simple server has one request |
81 | 83 |
82 struct sockaddr_in address; | 84 struct sockaddr_in address; |
83 address.sin_family = AF_INET; | 85 address.sin_family = AF_INET; |
84 address.sin_port = htons(FLAGS_port); | 86 address.sin_port = htons(FLAGS_port); |
85 inet_pton(AF_INET, FLAGS_address[0], &address.sin_addr); | 87 int result = inet_pton(AF_INET, FLAGS_address[0], &address.sin_addr); |
| 88 if (result != 1) { |
| 89 printf("inet_pton for %s:%d failed with return %d %s\n", |
| 90 FLAGS_address[0], FLAGS_port, result, strerror(errno)); |
| 91 return 1; |
| 92 } |
86 | 93 |
87 printf("Visit http://%s:%d in your browser.\n", FLAGS_address[0], FLAGS_port
); | 94 printf("Visit http://%s:%d in your browser.\n", FLAGS_address[0], FLAGS_port
); |
88 | 95 |
89 struct MHD_Daemon* daemon; | 96 struct MHD_Daemon* daemon; |
90 daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY | 97 daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY |
91 #ifdef SK_DEBUG | 98 #ifdef SK_DEBUG |
92 | MHD_USE_DEBUG | 99 | MHD_USE_DEBUG |
93 #endif | 100 #endif |
94 , FLAGS_port, nullptr, nullptr, | 101 , FLAGS_port, nullptr, nullptr, |
95 &answer_to_connection, &request, | 102 &answer_to_connection, &request, |
96 MHD_OPTION_SOCK_ADDR, &address, | 103 MHD_OPTION_SOCK_ADDR, &address, |
97 MHD_OPTION_END); | 104 MHD_OPTION_END); |
98 if (NULL == daemon) { | 105 if (NULL == daemon) { |
99 SkDebugf("Could not initialize daemon\n"); | 106 SkDebugf("Could not initialize daemon\n"); |
100 return 1; | 107 return 1; |
101 } | 108 } |
102 | 109 |
103 getchar(); | 110 getchar(); |
104 MHD_stop_daemon(daemon); | 111 MHD_stop_daemon(daemon); |
105 return 0; | 112 return 0; |
106 } | 113 } |
107 | 114 |
108 #if !defined SK_BUILD_FOR_IOS | 115 #if !defined SK_BUILD_FOR_IOS |
109 int main(int argc, char** argv) { | 116 int main(int argc, char** argv) { |
110 SkCommandLineFlags::Parse(argc, argv); | 117 SkCommandLineFlags::Parse(argc, argv); |
111 return skiaserve_main(); | 118 return skiaserve_main(); |
112 } | 119 } |
113 #endif | 120 #endif |
OLD | NEW |