本文整理汇总了C++中MHD_start_daemon函数的典型用法代码示例。如果您正苦于以下问题:C++ MHD_start_daemon函数的具体用法?C++ MHD_start_daemon怎么用?C++ MHD_start_daemon使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MHD_start_daemon函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[]) {
// Parse any command-line options.
namespace po = boost::program_options;
po::options_description desc("Allowed options");
desc.add_options()
("help", "show help")
("debug-httpd", po::value<bool>(&mp3d_debug_httpd), "show httpd debug output")
("root", po::value<std::string>(&mp3d_music_root), "root of file system mp3 tree")
("port", po::value<int>(&mp3d_port), "httpd port number")
;
po::variables_map args;
po::store(po::parse_command_line(argc, argv, desc), args);
po::notify(args);
if (args.count("help")) {
std::cout << desc << std::endl;
return 1;
}
// Index all the mp3s.
Paths paths;
find_mp3_files(mp3d_music_root, paths);
std::cerr << ".mp3 files found: " << paths.size() << std::endl;
int old_percentage = -1;
size_t id = 0;
for (Paths::const_iterator it = paths.begin(); it != paths.end(); ++it) {
Mp3Info mp3;
mp3.filename = (*it).string();
const ID3_Tag tag(mp3.filename.c_str());
ID3_Tag::ConstIterator* it = tag.CreateIterator();
for (size_t i = 0; i < tag.NumFrames(); ++i) {
const ID3_Frame* frame = it->GetNext();
if (frame != 0) {
std::string* dst;
switch (frame->GetID()) {
case ID3FID_ALBUM: dst = &mp3.album; break;
case ID3FID_LEADARTIST: dst = &mp3.artist; break;
case ID3FID_TITLE: dst = &mp3.title; break;
default: continue;
}
char* text = ID3_GetString(frame, ID3FN_TEXT);
dst->assign(text);
ID3_FreeString(text);
}
}
// FIXME: maybe a hash, to enable bookmarks?
mp3.id = id++;
all_mp3s.push_back(mp3);
// Show progress. Not really useful when we're not debugging.
// FIXME: start the web server straight away, and say "Indexing..." there.
const int new_percentage = (100*all_mp3s.size())/paths.size();
if (new_percentage != old_percentage) {
std::cout << "\rScanned: " << new_percentage << "%" << std::flush;
old_percentage = new_percentage;
}
}
std::cout << "\r.mp3 files scanned: " << all_mp3s.size() << std::endl;
// Set up the static files we need to serve.
read_static_file("/static/add.png",
"/usr/share/icons/gnome/16x16/actions/gtk-add.png");
read_static_file("/static/play.png",
"/usr/share/icons/gnome/16x16/actions/gtk-media-play-ltr.png");
read_static_file("/static/remove.png",
"/usr/share/icons/gnome/16x16/actions/gtk-remove.png");
static_file_map["/static/site.css"] = make_css();
// Start the mp3 player thread.
boost::thread mp3_player_thread(mp3_play_loop);
// Start the HTTP server.
std::cerr << "Starting HTTP server on port " << mp3d_port << "..." << std::endl;
const int mhd_flags = MHD_USE_SELECT_INTERNALLY;
MHD_Daemon* daemon = MHD_start_daemon(mhd_flags, mp3d_port, 0, 0, &handle_request, 0, MHD_OPTION_END);
if (daemon == 0) {
fail("MHD_start_daemon failed!");
}
getchar(); // Wait for the user to hit enter.
MHD_stop_daemon(daemon);
//mp3_player_thread.join();
return 0;
}
开发者ID:JoeBargo,项目名称:enh,代码行数:89,代码来源:mp3d.cpp
示例2: testExternalGet
static int
testExternalGet ()
{
struct MHD_Daemon *d;
CURL *c;
char buf[2048];
struct CBC cbc;
CURLM *multi;
CURLMcode mret;
fd_set rs;
fd_set ws;
fd_set es;
MHD_socket maxsock;
#ifdef MHD_WINSOCK_SOCKETS
int maxposixs; /* Max socket number unused on W32 */
#else /* MHD_POSIX_SOCKETS */
#define maxposixs maxsock
#endif /* MHD_POSIX_SOCKETS */
int running;
struct CURLMsg *msg;
time_t start;
struct timeval tv;
int i;
MHD_socket fd;
multi = NULL;
cbc.buf = buf;
cbc.size = 2048;
cbc.pos = 0;
d = MHD_start_daemon (MHD_USE_DEBUG,
11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
if (d == NULL)
return 256;
c = setupCURL(&cbc);
multi = curl_multi_init ();
if (multi == NULL)
{
curl_easy_cleanup (c);
MHD_stop_daemon (d);
return 512;
}
mret = curl_multi_add_handle (multi, c);
if (mret != CURLM_OK)
{
curl_multi_cleanup (multi);
curl_easy_cleanup (c);
MHD_stop_daemon (d);
return 1024;
}
for (i = 0; i < 2; i++) {
start = time (NULL);
while ((time (NULL) - start < 5) && (multi != NULL))
{
maxsock = MHD_INVALID_SOCKET;
maxposixs = -1;
FD_ZERO (&rs);
FD_ZERO (&ws);
FD_ZERO (&es);
curl_multi_perform (multi, &running);
mret = curl_multi_fdset (multi, &rs, &ws, &es, &maxposixs);
if (mret != CURLM_OK)
{
curl_multi_remove_handle (multi, c);
curl_multi_cleanup (multi);
curl_easy_cleanup (c);
MHD_stop_daemon (d);
return 2048;
}
if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &maxsock))
{
curl_multi_remove_handle (multi, c);
curl_multi_cleanup (multi);
curl_easy_cleanup (c);
MHD_stop_daemon (d);
return 4096;
}
tv.tv_sec = 0;
tv.tv_usec = 1000;
select (maxposixs + 1, &rs, &ws, &es, &tv);
curl_multi_perform (multi, &running);
if (running == 0)
{
msg = curl_multi_info_read (multi, &running);
if (msg == NULL)
break;
if (msg->msg == CURLMSG_DONE)
{
if (i == 0 && msg->data.result != CURLE_OK)
printf ("%s failed at %s:%d: `%s'\n",
"curl_multi_perform",
__FILE__,
__LINE__, curl_easy_strerror (msg->data.result));
else if (i == 1 && msg->data.result == CURLE_OK)
printf ("%s should have failed at %s:%d\n",
"curl_multi_perform",
__FILE__,
__LINE__);
curl_multi_remove_handle (multi, c);
//.........这里部分代码省略.........
开发者ID:Paxxi,项目名称:libmicrohttpd,代码行数:101,代码来源:test_quiesce.c
示例3: testExternalGet
static int
testExternalGet ()
{
struct MHD_Daemon *d;
CURL *c;
char buf[2048];
struct CBC cbc;
CURLM *multi;
CURLMcode mret;
fd_set rs;
fd_set ws;
fd_set es;
int max;
int running;
time_t start;
struct timeval tv;
int i;
multi = NULL;
cbc.buf = buf;
cbc.size = 2048;
cbc.pos = 0;
d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_DEBUG */ ,
11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
if (d == NULL)
return 256;
multi = curl_multi_init ();
if (multi == NULL)
{
MHD_stop_daemon (d);
return 512;
}
zzuf_socat_start ();
for (i = 0; i < LOOP_COUNT; i++)
{
fprintf (stderr, ".");
c = curl_easy_init ();
curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world");
curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT);
// NOTE: use of CONNECTTIMEOUT without also
// setting NOSIGNAL results in really weird
// crashes on my system!
curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
mret = curl_multi_add_handle (multi, c);
if (mret != CURLM_OK)
{
curl_multi_cleanup (multi);
curl_easy_cleanup (c);
zzuf_socat_stop ();
MHD_stop_daemon (d);
return 1024;
}
start = time (NULL);
while ((time (NULL) - start < 5) && (c != NULL))
{
max = 0;
FD_ZERO (&rs);
FD_ZERO (&ws);
FD_ZERO (&es);
curl_multi_perform (multi, &running);
mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
if (mret != CURLM_OK)
{
curl_multi_remove_handle (multi, c);
curl_multi_cleanup (multi);
curl_easy_cleanup (c);
zzuf_socat_stop ();
MHD_stop_daemon (d);
return 2048;
}
if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
{
curl_multi_remove_handle (multi, c);
curl_multi_cleanup (multi);
curl_easy_cleanup (c);
zzuf_socat_stop ();
MHD_stop_daemon (d);
return 4096;
}
tv.tv_sec = 0;
tv.tv_usec = 1000;
select (max + 1, &rs, &ws, &es, &tv);
curl_multi_perform (multi, &running);
if (running == 0)
{
curl_multi_info_read (multi, &running);
curl_multi_remove_handle (multi, c);
curl_easy_cleanup (c);
c = NULL;
}
MHD_run (d);
}
if (c != NULL)
{
curl_multi_remove_handle (multi, c);
//.........这里部分代码省略.........
开发者ID:dreamsxin,项目名称:golf,代码行数:101,代码来源:daemontest_get_chunked.c
示例4: testLongUrlGet
static int
testLongUrlGet ()
{
struct MHD_Daemon *d;
CURL *c;
char buf[2048];
struct CBC cbc;
char *url;
long code;
cbc.buf = buf;
cbc.size = 2048;
cbc.pos = 0;
d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ ,
1080,
&apc_all,
NULL,
&ahc_echo,
"GET",
MHD_OPTION_CONNECTION_MEMORY_LIMIT,
VERY_LONG / 2, MHD_OPTION_END);
if (d == NULL)
return 1;
c = curl_easy_init ();
url = malloc (VERY_LONG);
memset (url, 'a', VERY_LONG);
url[VERY_LONG - 1] = '\0';
memcpy (url, "http://localhost:1080/", strlen ("http://localhost:1080/"));
curl_easy_setopt (c, CURLOPT_URL, url);
curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
if (oneone)
curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
else
curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
// NOTE: use of CONNECTTIMEOUT without also
// setting NOSIGNAL results in really weird
// crashes on my system!
curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
if (CURLE_OK == curl_easy_perform (c))
{
curl_easy_cleanup (c);
MHD_stop_daemon (d);
free (url);
return 2;
}
if (CURLE_OK != curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, &code))
{
curl_easy_cleanup (c);
MHD_stop_daemon (d);
free (url);
return 4;
}
curl_easy_cleanup (c);
MHD_stop_daemon (d);
free (url);
if (code != MHD_HTTP_REQUEST_URI_TOO_LONG)
return 8;
return 0;
}
开发者ID:dreamsxin,项目名称:golf,代码行数:63,代码来源:daemontest_long_header.c
示例5: restStart
/* ****************************************************************************
*
* restStart -
*/
static int restStart(IpVersion ipVersion, const char* httpsKey = NULL, const char* httpsCertificate = NULL)
{
if (port == 0)
LM_RE(1, ("Please call restInit before starting the REST service"));
if ((ipVersion == IPV4) || (ipVersion == IPDUAL))
{
memset(&sad, 0, sizeof(sad));
if (inet_pton(AF_INET, bindIp, &(sad.sin_addr.s_addr)) != 1)
LM_RE(2, ("V4 inet_pton fail for %s", bindIp));
sad.sin_family = AF_INET;
sad.sin_port = htons(port);
if ((httpsKey != NULL) && (httpsCertificate != NULL))
{
mhdDaemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL, // MHD_USE_SELECT_INTERNALLY
htons(port),
NULL,
NULL,
connectionTreat, NULL,
MHD_OPTION_HTTPS_MEM_KEY, httpsKey,
MHD_OPTION_HTTPS_MEM_CERT, httpsCertificate,
MHD_OPTION_NOTIFY_COMPLETED, requestCompleted, NULL,
MHD_OPTION_CONNECTION_MEMORY_LIMIT, 2 * PAYLOAD_SIZE,
MHD_OPTION_SOCK_ADDR, (struct sockaddr*) &sad,
MHD_OPTION_END);
}
else
{
LM_V(("Starting HTTP daemon on IPv4 %s port %d", bindIp, port));
mhdDaemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION, // MHD_USE_SELECT_INTERNALLY
htons(port),
NULL,
NULL,
connectionTreat, NULL,
MHD_OPTION_NOTIFY_COMPLETED, requestCompleted, NULL,
MHD_OPTION_CONNECTION_MEMORY_LIMIT, 2 * PAYLOAD_SIZE,
MHD_OPTION_SOCK_ADDR, (struct sockaddr*) &sad,
MHD_OPTION_END);
}
if (mhdDaemon == NULL)
LM_RE(3, ("MHD_start_daemon failed"));
}
if ((ipVersion == IPV6) || (ipVersion == IPDUAL))
{
memset(&sad_v6, 0, sizeof(sad_v6));
if (inet_pton(AF_INET6, bindIPv6, &(sad_v6.sin6_addr.s6_addr)) != 1)
LM_RE(1, ("V6 inet_pton fail for %s", bindIPv6));
sad_v6.sin6_family = AF_INET6;
sad_v6.sin6_port = htons(port);
if ((httpsKey != NULL) && (httpsCertificate != NULL))
{
LM_V(("Starting HTTPS daemon on IPv6 %s port %d", bindIPv6, port));
mhdDaemon_v6 = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_IPv6 | MHD_USE_SSL,
htons(port),
NULL,
NULL,
connectionTreat, NULL,
MHD_OPTION_HTTPS_MEM_KEY, httpsKey,
MHD_OPTION_HTTPS_MEM_CERT, httpsCertificate,
MHD_OPTION_NOTIFY_COMPLETED, requestCompleted, NULL,
MHD_OPTION_CONNECTION_MEMORY_LIMIT, 2 * PAYLOAD_SIZE,
MHD_OPTION_SOCK_ADDR, (struct sockaddr*) &sad_v6,
MHD_OPTION_END);
}
else
{
LM_V(("Starting HTTP daemon on IPv6 %s port %d", bindIPv6, port));
mhdDaemon_v6 = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_IPv6,
htons(port),
NULL,
NULL,
connectionTreat, NULL,
MHD_OPTION_NOTIFY_COMPLETED, requestCompleted, NULL,
MHD_OPTION_CONNECTION_MEMORY_LIMIT, 2 * PAYLOAD_SIZE,
MHD_OPTION_SOCK_ADDR, (struct sockaddr*) &sad_v6,
MHD_OPTION_END);
}
if (mhdDaemon_v6 == NULL)
LM_RE(1, ("MHD_start_daemon_v6 failed"));
}
return 0;
}
开发者ID:agallegoc,项目名称:fiware-orion,代码行数:94,代码来源:rest.cpp
示例6: testExternalPut
static int
testExternalPut ()
{
struct MHD_Daemon *d;
CURL *c;
char buf[2048];
struct CBC cbc;
CURLM *multi;
CURLMcode mret;
fd_set rs;
fd_set ws;
fd_set es;
int max;
int running;
struct CURLMsg *msg;
time_t start;
struct timeval tv;
unsigned int pos = 0;
int done_flag = 0;
multi = NULL;
cbc.buf = buf;
cbc.size = 2048;
cbc.pos = 0;
d = MHD_start_daemon (MHD_USE_DEBUG,
11082,
NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END);
if (d == NULL)
return 256;
c = curl_easy_init ();
curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11082/hello_world");
curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
curl_easy_setopt (c, CURLOPT_READDATA, &pos);
curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
/*
// by not giving the file size, we force chunking!
curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L);
*/
curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
// NOTE: use of CONNECTTIMEOUT without also
// setting NOSIGNAL results in really weird
// crashes on my system!
curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
multi = curl_multi_init ();
if (multi == NULL)
{
curl_easy_cleanup (c);
MHD_stop_daemon (d);
return 512;
}
mret = curl_multi_add_handle (multi, c);
if (mret != CURLM_OK)
{
curl_multi_cleanup (multi);
curl_easy_cleanup (c);
MHD_stop_daemon (d);
return 1024;
}
start = time (NULL);
while ((time (NULL) - start < 5) && (multi != NULL))
{
max = 0;
FD_ZERO (&rs);
FD_ZERO (&ws);
FD_ZERO (&es);
curl_multi_perform (multi, &running);
mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
if (mret != CURLM_OK)
{
curl_multi_remove_handle (multi, c);
curl_multi_cleanup (multi);
curl_easy_cleanup (c);
MHD_stop_daemon (d);
return 2048;
}
if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
{
curl_multi_remove_handle (multi, c);
curl_multi_cleanup (multi);
curl_easy_cleanup (c);
MHD_stop_daemon (d);
return 4096;
}
tv.tv_sec = 0;
tv.tv_usec = 1000;
select (max + 1, &rs, &ws, &es, &tv);
curl_multi_perform (multi, &running);
if (running == 0)
{
msg = curl_multi_info_read (multi, &running);
if (msg == NULL)
break;
if (msg->msg == CURLMSG_DONE)
//.........这里部分代码省略.........
开发者ID:dcolish,项目名称:restpose,代码行数:101,代码来源:daemontest_put_chunked.c
示例7: main_loop
/**@internal
* Main execution loop
*/
static void
main_loop(void)
{
int result = 0;
pthread_t tid;
s_config *config;
config = config_get_config();
/* Set the time when nodogsplash started */
if (!started_time) {
debug(LOG_INFO, "Setting started_time");
started_time = time(NULL);
} else if (started_time < MINIMUM_STARTED_TIME) {
debug(LOG_WARNING, "Detected possible clock skew - re-setting started_time");
started_time = time(NULL);
}
/* If we don't have the Gateway IP address, get it. Exit on failure. */
if (!config->gw_address) {
debug(LOG_DEBUG, "Finding IP address of %s", config->gw_interface);
if ((config->gw_address = get_iface_ip(config->gw_interface)) == NULL) {
debug(LOG_ERR, "Could not get IP address information of %s, exiting...", config->gw_interface);
exit(1);
}
}
if ((config->gw_mac = get_iface_mac(config->gw_interface)) == NULL) {
debug(LOG_ERR, "Could not get MAC address information of %s, exiting...", config->gw_interface);
exit(1);
}
debug(LOG_NOTICE, "Detected gateway %s at %s (%s)", config->gw_interface, config->gw_address, config->gw_mac);
/* Initializes the web server */
if ((webserver = MHD_start_daemon(
MHD_USE_EPOLL_INTERNALLY,
config->gw_port,
NULL, NULL,
libmicrohttpd_cb, NULL,
MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
MHD_OPTION_LISTENING_ADDRESS_REUSE, 1,
MHD_OPTION_END)) == NULL) {
debug(LOG_ERR, "Could not create web server: %s", strerror(errno));
exit(1);
}
/* TODO: set listening socket */
debug(LOG_NOTICE, "Created web server on %s:%d", config->gw_address, config->gw_port);
/*
httpdAddCContent(webserver, "/", "", 0, NULL, http_nodogsplash_callback_index);
httpdAddCWildcardContent(webserver, config->authdir, NULL, http_nodogsplash_callback_auth);
httpdAddCWildcardContent(webserver, config->denydir, NULL, http_nodogsplash_callback_deny);
httpdAddC404Content(webserver, http_nodogsplash_callback_404);
*/
/* Reset the firewall (cleans it, in case we are restarting after nodogsplash crash) */
fw_destroy();
/* Then initialize it */
debug(LOG_NOTICE, "Initializing firewall rules");
if (fw_init() != 0) {
debug(LOG_ERR, "Error initializing firewall rules! Cleaning up");
fw_destroy();
debug(LOG_ERR, "Exiting because of error initializing firewall rules");
exit(1);
}
/* Start client statistics and timeout clean-up thread */
result = pthread_create(&tid_client_check, NULL, thread_client_timeout_check, NULL);
if (result != 0) {
debug(LOG_ERR, "FATAL: Failed to create thread_client_timeout_check - exiting");
termination_handler(0);
}
pthread_detach(tid_client_check);
/* Start control thread */
result = pthread_create(&tid, NULL, thread_ndsctl, (void *)(config->ndsctl_sock));
if (result != 0) {
debug(LOG_ERR, "FATAL: Failed to create thread_ndsctl - exiting");
termination_handler(1);
}
result = pthread_join(tid, NULL);
if (result) {
debug(LOG_INFO, "Failed to wait for nodogsplash thread.");
}
MHD_stop_daemon(webserver);
termination_handler(result);
}
开发者ID:lynxis,项目名称:nodogsplash,代码行数:89,代码来源:gateway.c
示例8: restStart
/* ****************************************************************************
*
* restStart -
*/
static int restStart(IpVersion ipVersion, const char* httpsKey = NULL, const char* httpsCertificate = NULL)
{
bool mhdStartError = true;
size_t memoryLimit = 2 * PAYLOAD_SIZE;
if (port == 0)
{
LM_X(1, ("Fatal Error (please call restInit before starting the REST service)"));
}
if ((ipVersion == IPV4) || (ipVersion == IPDUAL))
{
memset(&sad, 0, sizeof(sad));
if (inet_pton(AF_INET, bindIp, &(sad.sin_addr.s_addr)) != 1)
{
LM_X(2, ("Fatal Error (V4 inet_pton fail for %s)", bindIp));
}
sad.sin_family = AF_INET;
sad.sin_port = htons(port);
if ((httpsKey != NULL) && (httpsCertificate != NULL))
{
LM_T(LmtMhd, ("Starting HTTPS daemon on IPv4 %s port %d", bindIp, port));
mhdDaemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL, // MHD_USE_SELECT_INTERNALLY
htons(port),
NULL,
NULL,
connectionTreat, NULL,
MHD_OPTION_HTTPS_MEM_KEY, httpsKey,
MHD_OPTION_HTTPS_MEM_CERT, httpsCertificate,
MHD_OPTION_CONNECTION_MEMORY_LIMIT, memoryLimit,
MHD_OPTION_SOCK_ADDR, (struct sockaddr*) &sad,
MHD_OPTION_NOTIFY_COMPLETED, requestCompleted, NULL,
MHD_OPTION_END);
}
else
{
LM_T(LmtMhd, ("Starting HTTP daemon on IPv4 %s port %d", bindIp, port));
mhdDaemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION, // MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG
htons(port),
NULL,
NULL,
connectionTreat, NULL,
MHD_OPTION_CONNECTION_MEMORY_LIMIT, memoryLimit,
MHD_OPTION_SOCK_ADDR, (struct sockaddr*) &sad,
MHD_OPTION_NOTIFY_COMPLETED, requestCompleted, NULL,
MHD_OPTION_END);
}
if (mhdDaemon != NULL)
{
mhdStartError = false;
}
}
if ((ipVersion == IPV6) || (ipVersion == IPDUAL))
{
memset(&sad_v6, 0, sizeof(sad_v6));
if (inet_pton(AF_INET6, bindIPv6, &(sad_v6.sin6_addr.s6_addr)) != 1)
{
LM_X(4, ("Fatal Error (V6 inet_pton fail for %s)", bindIPv6));
}
sad_v6.sin6_family = AF_INET6;
sad_v6.sin6_port = htons(port);
if ((httpsKey != NULL) && (httpsCertificate != NULL))
{
LM_T(LmtMhd, ("Starting HTTPS daemon on IPv6 %s port %d", bindIPv6, port));
mhdDaemon_v6 = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_IPv6 | MHD_USE_SSL,
htons(port),
NULL,
NULL,
connectionTreat, NULL,
MHD_OPTION_HTTPS_MEM_KEY, httpsKey,
MHD_OPTION_HTTPS_MEM_CERT, httpsCertificate,
MHD_OPTION_CONNECTION_MEMORY_LIMIT, memoryLimit,
MHD_OPTION_SOCK_ADDR, (struct sockaddr*) &sad_v6,
MHD_OPTION_NOTIFY_COMPLETED, requestCompleted, NULL,
MHD_OPTION_END);
}
else
{
LM_T(LmtMhd, ("Starting HTTP daemon on IPv6 %s port %d", bindIPv6, port));
mhdDaemon_v6 = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_IPv6,
htons(port),
NULL,
NULL,
connectionTreat, NULL,
MHD_OPTION_CONNECTION_MEMORY_LIMIT, memoryLimit,
MHD_OPTION_SOCK_ADDR, (struct sockaddr*) &sad_v6,
MHD_OPTION_NOTIFY_COMPLETED, requestCompleted, NULL,
MHD_OPTION_END);
//.........这里部分代码省略.........
开发者ID:holographix,项目名称:fiware-orion,代码行数:101,代码来源:rest.cpp
示例9: testMultithreadedPoolPost
static int
testMultithreadedPoolPost ()
{
struct MHD_Daemon *d;
CURL *c;
char buf[2048];
struct CBC cbc;
CURLcode errornum;
int i;
char url[1024];
int port;
if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
port = 0;
else
{
port = 1352;
if (oneone)
port += 10;
}
cbc.buf = buf;
cbc.size = 2048;
d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
port, NULL, NULL, &ahc_echo, NULL,
MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END);
if (d == NULL)
return 16;
if (0 == port)
{
const union MHD_DaemonInfo *dinfo;
dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
if (NULL == dinfo || 0 == dinfo->port)
{ MHD_stop_daemon (d); return 32; }
port = (int)dinfo->port;
}
for (i = 0; i < LOOPCOUNT; i++)
{
if (99 == i % 100)
fprintf (stderr, ".");
c = curl_easy_init ();
cbc.pos = 0;
buf[0] = '\0';
snprintf (url,
sizeof (url),
"http://127.0.0.1:%d/hw%d",
port,
i);
curl_easy_setopt (c, CURLOPT_URL, url);
curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
curl_easy_setopt (c, CURLOPT_POST, 1L);
curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
if (oneone)
curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
else
curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
/* NOTE: use of CONNECTTIMEOUT without also
* setting NOSIGNAL results in really weird
* crashes on my system! */
curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
if (CURLE_OK != (errornum = curl_easy_perform (c)))
{
fprintf (stderr,
"curl_easy_perform failed: `%s'\n",
curl_easy_strerror (errornum));
curl_easy_cleanup (c);
MHD_stop_daemon (d);
return 32;
}
curl_easy_cleanup (c);
if ((buf[0] != 'O') || (buf[1] != 'K'))
{
MHD_stop_daemon (d);
return 64;
}
}
MHD_stop_daemon (d);
if (LOOPCOUNT >= 99)
fprintf (stderr, "\n");
return 0;
}
开发者ID:Karlson2k,项目名称:libmicrohttpd,代码行数:86,代码来源:test_post_loop.c
示例10: testExternalPost
static int
testExternalPost ()
{
struct MHD_Daemon *d;
CURL *c;
char buf[2048];
struct CBC cbc;
CURLM *multi;
CURLMcode mret;
fd_set rs;
fd_set ws;
fd_set es;
MHD_socket maxsock;
#ifdef MHD_WINSOCK_SOCKETS
int maxposixs; /* Max socket number unused on W32 */
#else /* MHD_POSIX_SOCKETS */
#define maxposixs maxsock
#endif /* MHD_POSIX_SOCKETS */
int running;
struct CURLMsg *msg;
time_t start;
struct timeval tv;
int i;
unsigned long long timeout;
long ctimeout;
char url[1024];
int port;
if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT))
port = 0;
else
{
port = 1353;
if (oneone)
port += 10;
}
multi = NULL;
cbc.buf = buf;
cbc.size = 2048;
cbc.pos = 0;
d = MHD_start_daemon (MHD_USE_ERROR_LOG,
port, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_END);
if (d == NULL)
return 256;
if (0 == port)
{
const union MHD_DaemonInfo *dinfo;
dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT);
if (NULL == dinfo || 0 == dinfo->port)
{ MHD_stop_daemon (d); return 32; }
port = (int)dinfo->port;
}
multi = curl_multi_init ();
if (multi == NULL)
{
MHD_stop_daemon (d);
return 512;
}
for (i = 0; i < LOOPCOUNT; i++)
{
if (99 == i % 100)
fprintf (stderr, ".");
c = curl_easy_init ();
cbc.pos = 0;
buf[0] = '\0';
snprintf (url,
sizeof (url),
"http://127.0.0.1:%d/hw%d",
port,
i);
curl_easy_setopt (c, CURLOPT_URL, url);
curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
curl_easy_setopt (c, CURLOPT_POSTFIELDS, POST_DATA);
curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE, strlen (POST_DATA));
curl_easy_setopt (c, CURLOPT_POST, 1L);
curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
if (oneone)
curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
else
curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
/* NOTE: use of CONNECTTIMEOUT without also
* setting NOSIGNAL results in really weird
* crashes on my system! */
curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
mret = curl_multi_add_handle (multi, c);
if (mret != CURLM_OK)
{
curl_multi_cleanup (multi);
curl_easy_cleanup (c);
MHD_stop_daemon (d);
return 1024;
}
start = time (NULL);
while ((time (NULL) - start < 5) && (multi != NULL))
{
maxsock = MHD_INVALID_SOCKET;
//.........这里部分代码省略.........
开发者ID:Karlson2k,项目名称:libmicrohttpd,代码行数:101,代码来源:test_post_loop.c
示例11: main
/**
* Main function
* @param argc : number of arguments given on the command line.
* @param argv : an array of strings that contains command line arguments.
* @returns always 0
*/
int main(int argc, char **argv)
{
server_struct_t *server_struct = NULL; /** main structure for 'server' program. */
guint id_int = 0;
guint id_term = 0;
#if !GLIB_CHECK_VERSION(2, 36, 0)
g_type_init(); /** g_type_init() is deprecated since glib 2.36 */
#endif
ignore_sigpipe(); /** into order to get libmicrohttpd portable */
init_international_languages();
server_struct = init_server_main_structure(argc, argv);
if (server_struct != NULL && server_struct->opt != NULL && server_struct->backend != NULL)
{
server_struct->loop = g_main_loop_new(g_main_context_default(), FALSE);
id_int = g_unix_signal_add(SIGINT, int_signal_handler, server_struct);
id_term = g_unix_signal_add(SIGTERM, int_signal_handler, server_struct);
if (id_int <= 0 || id_term <= 0)
{
print_error(__FILE__, __LINE__, _("Unable to add signal handler\n"));
}
/* Initializing the choosen backend by calling it's function */
if (server_struct->backend->init_backend != NULL)
{
server_struct->backend->init_backend(server_struct);
}
/* Before starting anything else, start the threads */
server_struct->meta_thread = g_thread_new("meta-data", meta_data_thread, server_struct);
server_struct->data_thread = g_thread_new("data", data_thread, server_struct);
/* Starting the libmicrohttpd daemon */
server_struct->d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, server_struct->opt->port, NULL, NULL, &ahc, server_struct, MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) 131070 , MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, MHD_OPTION_END);
if (server_struct->d == NULL)
{
print_error(__FILE__, __LINE__, _("Error while spawning libmicrohttpd daemon\n"));
return 1;
}
/* Unless on error we will never join the threads as they
* contain a while (TRUE) loop !
*/
g_main_loop_run(server_struct->loop);
/* g_thread_join(server_struct->meta_thread); */
/* g_thread_join(server_struct->data_thread); */
}
else
{
print_error(__FILE__, __LINE__, _("Error: initialization failed.\n"));
}
return 0;
}
开发者ID:DarkDare,项目名称:sauvegarde,代码行数:69,代码来源:server.c
示例12: testExternalGet
static int
testExternalGet (int port)
{
struct MHD_Daemon *d;
CURL *c;
char buf[2048];
struct CBC cbc;
CURLM *multi;
CURLMcode mret;
fd_set rs;
fd_set ws;
fd_set es;
MHD_socket max;
int running;
struct CURLMsg *msg;
time_t start;
struct timeval tv;
unsigned int i;
char url[64];
sprintf(url, "http://127.0.0.1:%d/hello_world", port);
multi = NULL;
cbc.buf = buf;
cbc.size = 2048;
d = MHD_start_daemon (MHD_USE_DEBUG,
port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
if (d == NULL)
return 256;
start_timer ();
multi = curl_multi_init ();
if (multi == NULL)
{
MHD_stop_daemon (d);
return 512;
}
for (i=0;i<ROUNDS;i++)
{
cbc.pos = 0;
c = curl_easy_init ();
curl_easy_setopt (c, CURLOPT_URL, url);
curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
if (oneone)
curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
else
curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
/* NOTE: use of CONNECTTIMEOUT without also
setting NOSIGNAL results in really weird
crashes on my system! */
curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
mret = curl_multi_add_handle (multi, c);
if (mret != CURLM_OK)
{
curl_multi_cleanup (multi);
curl_easy_cleanup (c);
MHD_stop_daemon (d);
return 1024;
}
start = time (NULL);
while ((time (NULL) - start < 5) && (c != NULL))
{
max = 0;
FD_ZERO (&rs);
FD_ZERO (&ws);
FD_ZERO (&es);
curl_multi_perform (multi, &running);
mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
if (mret != CURLM_OK)
{
curl_multi_remove_handle (multi, c);
curl_multi_cleanup (multi);
curl_easy_cleanup (c);
MHD_stop_daemon (d);
return 2048;
}
if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
{
curl_multi_remove_handle (multi, c);
curl_multi_cleanup (multi);
curl_easy_cleanup (c);
MHD_stop_daemon (d);
return 4096;
}
tv.tv_sec = 0;
tv.tv_usec = 1000;
select (max + 1, &rs, &ws, &es, &tv);
curl_multi_perform (multi, &running);
if (running == 0)
{
msg = curl_multi_info_read (multi, &running);
if (msg == NULL)
break;
if (msg->msg == CURLMSG_DONE)
{
if (msg->data.result != CURLE_OK)
printf ("%s failed at %s:%d: `%s'\n",
//.........这里部分代码省略.........
开发者ID:Metaswitch,项目名称:libmicrohttpd,代码行数:101,代码来源:perf_get.c
示例13: testInternalSelectGet
static int
testInternalSelectGet ()
{
struct MHD_Daemon *d;
CURL *c;
char buf[2048];
struct CBC cbc;
CURLM *multi;
CURLMcode mret;
fd_set rs;
fd_set ws;
fd_set es;
MHD_socket max;
int running;
struct CURLMsg *msg;
time_t start;
struct timeval tv;
multi = NULL;
cbc.buf = buf;
cbc.size = 2048;
cbc.pos = 0;
d = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SSL | MHD_USE_SELECT_INTERNALLY,
1082, NULL, NULL, &ahc_echo, "GET",
MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
MHD_OPTION_END);
if (d == NULL)
return 256;
char *aes256_sha = "AES256-SHA";
if (curl_uses_nss_ssl() == 0)
{
aes256_sha = "rsa_aes_256_sha";
}
c = curl_easy_init ();
curl_easy_setopt (c, CURLOPT_URL, "https://127.0.0.1:1082/hello_world");
curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
/* TLS options */
curl_easy_setopt (c, CURLOPT_SSLVERSION, CURL_SSLVERSION_SSLv3);
curl_easy_setopt (c, CURLOPT_SSL_CIPHER_LIST, aes256_sha);
curl_easy_setopt (c, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt (c, CURLOPT_SSL_VERIFYHOST, 0);
curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
if (oneone)
curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
else
curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
/* NOTE: use of CONNECTTIMEOUT without also
setting NOSIGNAL results in really weird
crashes on my system! */
curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
multi = curl_multi_init ();
if (multi == NULL)
{
curl_easy_cleanup (c);
MHD_stop_daemon (d);
return 512;
}
mret = curl_multi_add_handle (multi, c);
if (mret != CURLM_OK)
{
curl_multi_cleanup (multi);
curl_easy_cleanup (c);
MHD_stop_daemon (d);
return 1024;
}
start = time (NULL);
while ((time (NULL) - start < 5) && (multi != NULL))
{
max = 0;
FD_ZERO (&rs);
FD_ZERO (&ws);
FD_ZERO (&es);
mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
if (mret != CURLM_OK)
{
curl_multi_remove_handle (multi, c);
curl_multi_cleanup (multi);
curl_easy_cleanup (c);
MHD_stop_daemon (d);
return 2048;
}
tv.tv_sec = 0;
tv.tv_usec = 1000;
select (max + 1, &rs, &ws, &es, &tv);
curl_multi_perform (multi, &running);
if (running == 0)
{
msg = curl_multi_info_read (multi, &running);
if (msg == NULL)
break;
if (msg->msg == CURLMSG_DONE)
{
//.........这里部分代码省略.........
开发者ID:Paxxi,项目名称:xbmc-deps,代码行数:101,代码来源:test_empty_response.c
示例14: testLongHeaderGet
static int
testLongHeaderGet ()
{
struct MHD_Daemon *d;
CURL *c;
char buf[2048];
struct CBC cbc;
char *url;
long code;
struct curl_slist *header = NULL;
cbc.buf = buf;
cbc.size = 2048;
cbc.pos = 0;
d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ ,
1080,
&apc_all,
NULL,
&ahc_echo,
"GET",
MHD_OPTION_CONNECTION_MEMORY_LIMIT,
(size_t) (VERY_LONG / 2), MHD_OPTION_END);
if (d == NULL)
return 16;
c = curl_easy_init ();
url = malloc (VERY_LONG);
if (url == NULL)
{
MHD_stop_daemon (d);
return 16;
}
memset (url, 'a', VERY_LONG);
url[VERY_LONG - 1] = '\0';
url[VERY_LONG / 2] = ':';
url[VERY_LONG / 2 + 1] = ' ';
header = curl_slist_append (header, url);
curl_easy_setopt (c, CURLOPT_HTTPHEADER, header);
curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1080/hello_world");
curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
if (oneone)
curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
else
curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
/* NOTE: use of CONNECTTIMEOUT without also
setting NOSIGNAL results in really weird
crashes on my system! */
curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
if (CURLE_OK == curl_easy_perform (c))
{
curl_easy_cleanup (c);
MHD_stop_daemon (d);
curl_slist_free_all (header);
free (url);
return 32;
}
if (CURLE_OK != curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, &code))
{
curl_slist_free_all (header);
curl_easy_cleanup (c);
MHD_stop_daemon (d);
free (url);
return 64;
}
curl_slist_free_all (header);
curl_easy_cleanup (c);
MHD_stop_daemon (d);
free (url);
if (code != MHD_HTTP_REQUEST_ENTITY_TOO_LARGE)
return 128;
return 0;
}
开发者ID:morria,项目名称:CoffeeD,代码行数:76,代码来源:daemontest_long_header.c
示例15: testMultithreadedPoolPost
|
请发表评论