当前位置: 首页>>代码示例>>C++>>正文


C++ MHD_run函数代码示例

本文整理汇总了C++中MHD_run函数的典型用法代码示例。如果您正苦于以下问题:C++ MHD_run函数的具体用法?C++ MHD_run怎么用?C++ MHD_run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了MHD_run函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testExternalGet

static int
testExternalGet ()
{
  struct MHD_Daemon *d;
  fd_set rs;
  fd_set ws;
  fd_set es;
  MHD_socket max;
  time_t start;
  struct timeval tv;
  pid_t curl;

  d = MHD_start_daemon (MHD_USE_DEBUG,
                        1082, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
  if (d == NULL)
    return 256;
  curl = fork_curl ("http://127.0.0.1:1082/");
  
  start = time (NULL);
  while ((time (NULL) - start < 2))
    {
      max = 0;
      FD_ZERO (&rs);
      FD_ZERO (&ws);
      FD_ZERO (&es);
      if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
        {
          MHD_stop_daemon (d);
          return 4096;
        }
      tv.tv_sec = 0;
      tv.tv_usec = 1000;
      select (max + 1, &rs, &ws, &es, &tv);
      MHD_run (d);
    }
  kill_curl (curl);
  start = time (NULL);
  while ((time (NULL) - start < 2))
    {
      max = 0;
      FD_ZERO (&rs);
      FD_ZERO (&ws);
      FD_ZERO (&es);
      if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
        {
          MHD_stop_daemon (d);
          return 4096;
        }
      tv.tv_sec = 0;
      tv.tv_usec = 1000;
      select (max + 1, &rs, &ws, &es, &tv);
      MHD_run (d);
    }
  // fprintf (stderr, "Stopping daemon!\n");
  MHD_stop_daemon (d);
  if (ok != 0)
    return 1024;
  return 0;
}
开发者ID:Paxxi,项目名称:libmicrohttpd,代码行数:59,代码来源:test_get_response_cleanup.c

示例2: mhd_task

static void
mhd_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  mhd_task_id = NULL;
  MHD_run (mhd);
  mhd_main ();
}
开发者ID:tg-x,项目名称:gnunet,代码行数:7,代码来源:test_gnunet_vpn.c

示例3: testExternalRun

static int
testExternalRun ()
{
  struct MHD_Daemon *d;
  fd_set rs;
  int maxfd;
  int i;

  d = MHD_start_daemon (MHD_USE_DEBUG,
                        1081,
                        &apc_all, NULL, &ahc_nothing, NULL, MHD_OPTION_END);

  if (d == NULL)
    return 4;
  i = 0;
  while (i < 15)
    {
      maxfd = 0;
      FD_ZERO (&rs);
      if (MHD_YES != MHD_get_fdset (d, &rs, &rs, &rs, &maxfd))
	{
	  MHD_stop_daemon (d);
	  return 256;
	}
      if (MHD_run (d) == MHD_NO)
        {
          MHD_stop_daemon (d);
          return 8;
        }
      i++;
    }
  MHD_stop_daemon (d);
  return 0;
}
开发者ID:1c0n,项目名称:xbmc,代码行数:34,代码来源:daemon_test.c

示例4: main

/**
 * Call with the port number as the only argument.
 * Never terminates (other than by signals, such as CTRL-C).
 */
int
main (int argc, char *const *argv)
{
  struct MHD_Daemon *d;
  struct timeval tv;
  struct timeval *tvp;
  fd_set rs;
  fd_set ws;
  fd_set es;
  int max;
  MHD_UNSIGNED_LONG_LONG mhd_timeout;

  if (argc != 2)
    {
      printf ("%s PORT\n", argv[0]);
      return 1;
    }
  /* initialize PRNG */
  srand ((unsigned int) time (NULL));
  d = MHD_start_daemon (MHD_USE_DEBUG,
                        atoi (argv[1]),
                        NULL, NULL, 
			&create_response, NULL, 
			MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 15,
			MHD_OPTION_NOTIFY_COMPLETED, &request_completed_callback, NULL,
			MHD_OPTION_END);
  if (NULL == d)
    return 1;
  while (1)
    {
      expire_sessions ();
      max = 0;
      FD_ZERO (&rs);
      FD_ZERO (&ws);
      FD_ZERO (&es);
      if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
	break; /* fatal internal error */
      if (MHD_get_timeout (d, &mhd_timeout) == MHD_YES)	
	{
	  tv.tv_sec = mhd_timeout / 1000;
	  tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000)) * 1000;
	  tvp = &tv;	  
	}
      else
	tvp = NULL;
      if (-1 == select (max + 1, &rs, &ws, &es, tvp))
	{
	  if (EINTR != errno)
	    fprintf (stderr, 
		     "Aborting due to error during select: %s\n",
		     strerror (errno));
	  break;
	}
      MHD_run (d);
    }
  MHD_stop_daemon (d);
  return 0;
}
开发者ID:uplusplus,项目名称:libmicrohttpd,代码行数:62,代码来源:sessions.c

示例5: run_daemon

/**
 * Call MHD to process pending requests and then go back
 * and schedule the next run.
 */
static void
run_daemon (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct MHD_Daemon *daemon_handle = cls;

  http_task = NULL;
  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
    return;
  GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
  http_task = prepare_daemon (daemon_handle);
}
开发者ID:muggenhor,项目名称:GNUnet,代码行数:15,代码来源:gnunet-bcd.c

示例6: FD_ZERO

/** Process requests.
 * This method waits for new requests and processes them when received.
 */
void
WebServer::process()
{
  fd_set read_fd, write_fd, except_fd;
  int max_fd = 0;
  FD_ZERO(&read_fd); FD_ZERO(&write_fd); FD_ZERO(&except_fd);
  if ( MHD_get_fdset(__daemon, &read_fd, &write_fd, &except_fd, &max_fd) != MHD_YES ) {
    if (__logger)
      __logger->log_warn("WebviewThread", "Could not get microhttpd fdsets");
    return;
  }
  select(max_fd + 1, &read_fd, &write_fd, &except_fd, NULL);
  MHD_run(__daemon);
}
开发者ID:sanyaade-teachings,项目名称:fawkes,代码行数:17,代码来源:server.cpp

示例7: testExternalGet

static int
testExternalGet (int port)
{
  struct MHD_Daemon *d;
  pid_t pid;
  fd_set rs;
  fd_set ws;
  fd_set es;
  MHD_socket max;
  struct timeval tv;
  MHD_UNSIGNED_LONG_LONG tt;
  int tret;

  d = MHD_start_daemon (MHD_USE_DEBUG,
                        port, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END);
  if (d == NULL)
    return 256;
  start_timer ();
  pid = do_gets (port);
  while (0 == waitpid (pid, NULL, WNOHANG))
    {
      max = 0;
      FD_ZERO (&rs);
      FD_ZERO (&ws);
      FD_ZERO (&es);
      if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
	{
	  MHD_stop_daemon (d);
	  return 4096;
	}
      tret = MHD_get_timeout (d, &tt);
      if (MHD_YES != tret) tt = 1;
      tv.tv_sec = tt / 1000;
      tv.tv_usec = 1000 * (tt % 1000);
      if (-1 == select (max + 1, &rs, &ws, &es, &tv))
	{
	  if (EINTR == errno)
	    continue;
	  fprintf (stderr,
		   "select failed: %s\n",
		   strerror (errno));
	  break;	      	  
	}
      MHD_run (d);
    }
  stop ("external select");
  MHD_stop_daemon (d);
  return 0;
}
开发者ID:zombie9080,项目名称:libmicrohttpd-test,代码行数:49,代码来源:perf_get_concurrent.c

示例8: main

int
main (int argc, char *const *argv)
{
  struct MHD_Daemon *d;
  time_t end;
  time_t t;
  struct timeval tv;
  fd_set rs;
  fd_set ws;
  fd_set es;
  int max;
  unsigned MHD_LONG_LONG mhd_timeout;

  if (argc != 3)
    {
      printf ("%s PORT SECONDS-TO-RUN\n", argv[0]);
      return 1;
    }
  d = MHD_start_daemon (MHD_USE_DEBUG,
                        atoi (argv[1]),
                        NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END);
  if (d == NULL)
    return 1;
  end = time (NULL) + atoi (argv[2]);
  while ((t = time (NULL)) < end)
    {
      tv.tv_sec = end - t;
      tv.tv_usec = 0;
      max = 0;
      FD_ZERO (&rs);
      FD_ZERO (&ws);
      FD_ZERO (&es);
      if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
	break; /* fatal internal error */
      if (MHD_get_timeout (d, &mhd_timeout) == MHD_YES)

        {
          if (tv.tv_sec * 1000 < mhd_timeout)
            {
              tv.tv_sec = mhd_timeout / 1000;
              tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000)) * 1000;
            }
        }
      select (max + 1, &rs, &ws, &es, &tv);
      MHD_run (d);
    }
  MHD_stop_daemon (d);
  return 0;
}
开发者ID:AkramAlomainy,项目名称:tinyos-main,代码行数:49,代码来源:fileserver_example_external_select.c

示例9: testThread

static int
testThread ()
{
  struct MHD_Daemon *d;
  d = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SELECT_INTERNALLY,
                        1082,
                        &apc_all, NULL, &ahc_nothing, NULL, MHD_OPTION_END);

  if (d == NULL)
    return 16;
  if (MHD_run (d) != MHD_NO)
    return 32;
  MHD_stop_daemon (d);
  return 0;
}
开发者ID:1c0n,项目名称:xbmc,代码行数:15,代码来源:daemon_test.c

示例10: testMultithread

static int
testMultithread ()
{
  struct MHD_Daemon *d;
  d = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_THREAD_PER_CONNECTION,
                        1083,
                        &apc_all, NULL, &ahc_nothing, NULL, MHD_OPTION_END);

  if (d == NULL)
    return 64;
  if (MHD_run (d) != MHD_NO)
    return 128;
  MHD_stop_daemon (d);
  return 0;
}
开发者ID:1c0n,项目名称:xbmc,代码行数:15,代码来源:daemon_test.c

示例11: ServeOneRequest

static void *
ServeOneRequest(void *param)
{
    struct MHD_Daemon *d;
    fd_set rs;
    fd_set ws;
    fd_set es;
    MHD_socket fd, max;
    time_t start;
    struct timeval tv;
    int done = 0;

    fd = (MHD_socket) (intptr_t) param;

    d = MHD_start_daemon (MHD_USE_DEBUG,
                          1082, NULL, NULL, &ahc_echo, "GET",
                          MHD_OPTION_LISTEN_SOCKET, fd,
                          MHD_OPTION_NOTIFY_COMPLETED, &request_completed, &done,
                          MHD_OPTION_END);
    if (d == NULL)
        return "MHD_start_daemon() failed";

    start = time (NULL);
    while ((time (NULL) - start < 5) && done == 0)
    {
        max = 0;
        FD_ZERO (&rs);
        FD_ZERO (&ws);
        FD_ZERO (&es);
        if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
        {
            MHD_stop_daemon (d);
            MHD_socket_close_(fd);
            return "MHD_get_fdset() failed";
        }
        tv.tv_sec = 0;
        tv.tv_usec = 1000;
        MHD_SYS_select_ (max + 1, &rs, &ws, &es, &tv);
        MHD_run (d);
    }
    MHD_stop_daemon (d);
    MHD_socket_close_(fd);
    return NULL;
}
开发者ID:Paxxi,项目名称:xbmc-deps,代码行数:44,代码来源:test_quiesce.c

示例12: run_daemon

/**
 * Call MHD to process pending requests and then go back
 * and schedule the next run.
 *
 * @param cls the `struct MHD_Daemon` of the HTTP server to run
 * @param tc scheduler context
 */
static void
run_daemon (void *cls,
            const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct MHD_Daemon *daemon_handle = cls;

  if (daemon_handle == daemon_handle_v4)
    hostlist_task_v4 = NULL;
  else
    hostlist_task_v6 = NULL;

  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
    return;
  GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
  if (daemon_handle == daemon_handle_v4)
    hostlist_task_v4 = prepare_daemon (daemon_handle);
  else
    hostlist_task_v6 = prepare_daemon (daemon_handle);
}
开发者ID:muggenhor,项目名称:GNUnet,代码行数:26,代码来源:gnunet-daemon-hostlist_server.c

示例13: expireSessions

void WebServer::run()
{
    expireSessions ();
    max = 0;
    FD_ZERO (&rs);
    FD_ZERO (&ws);
    FD_ZERO (&es);
    if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
        return; /* fatal internal error */
    if (MHD_get_timeout (d, &mhd_timeout) == MHD_YES)
    {
        tv.tv_sec = mhd_timeout / 1000;
        tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000)) * 1000;
        tvp = &tv;
    }
    else
        tvp = NULL;
    select (max + 1, &rs, &ws, &es, tvp);
    MHD_run (d);
}
开发者ID:mrmarss,项目名称:ScareBear,代码行数:20,代码来源:WebServer.cpp

示例14: testExternalGet


//.........这里部分代码省略.........
  c = curl_easy_init ();
  curl_easy_setopt (c, CURLOPT_URL, "https://localhost:1082/hello_world");
  curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
  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, 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)
            {
              if (msg->data.result != CURLE_OK)
                printf ("%s failed at %s:%d: `%s'\n",
                        "curl_multi_perform",
                        __FILE__,
                        __LINE__, curl_easy_strerror (msg->data.result));
              curl_multi_remove_handle (multi, c);
              curl_multi_cleanup (multi);
              curl_easy_cleanup (c);
              c = NULL;
              multi = NULL;
            }
        }
      MHD_run (d);
    }
  if (multi != NULL)
    {
      curl_multi_remove_handle (multi, c);
      curl_easy_cleanup (c);
      curl_multi_cleanup (multi);
    }
  MHD_stop_daemon (d);
  if (cbc.pos != strlen ("/hello_world"))
    return 8192;
  if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
    return 16384;
  return 0;
}
开发者ID:dcolish,项目名称:restpose,代码行数:101,代码来源:mhds_get_test_select.c

示例15: httpd_proc

void httpd_proc(int rank)
{
#ifdef LIBMICROHTTPD
	int status;
	fd_set rs;
	fd_set ws;
	fd_set es;
	int max;
#endif
	struct httpd_cb *cb = httpd_cb_list;

	/*child's initial settings*/
	if (init_mi_child()!=0) {
		LM_ERR("failed to init the mi child process\n");
		return;
	}

	/* Allocating http response buffer */
	buffer.s = (char*)pkg_malloc(sizeof(char)*buffer.len);
	if (buffer.s==NULL) {
		LM_ERR("oom\n");
		return;
	}

	while(cb) {
		if (cb->init_proc_callback)
			cb->init_proc_callback();
		cb = cb->next;
	}

#ifdef LIBMICROHTTPD
	struct timeval tv;
	struct sockaddr_in saddr_in;

	memset(&saddr_in, 0, sizeof(saddr_in));
	if (ip.s)
		saddr_in.sin_addr.s_addr = inet_addr(ip.s);
	else
		saddr_in.sin_addr.s_addr = INADDR_ANY;
	saddr_in.sin_family = AF_INET;
	saddr_in.sin_port = htons(port);

	LM_DBG("init_child [%d] - [%d] HTTP Server init [%s:%d]\n",
		rank, getpid(), (ip.s?ip.s:"INADDR_ANY"), port);
	set_proc_attrs("HTTPD %s:%d", (ip.s?ip.s:"INADDR_ANY"), port);
	dmn = MHD_start_daemon(MHD_NO_FLAG|MHD_USE_DEBUG, port, NULL, NULL,
			&(answer_to_connection), NULL,
			MHD_OPTION_SOCK_ADDR, &saddr_in,
			MHD_OPTION_END);

	if (NULL == dmn) {
		LM_ERR("unable to start http daemon\n");
		return;
	}

	while(1) {
		max = 0;
		FD_ZERO (&rs);
		FD_ZERO (&ws);
		FD_ZERO (&es);
		if (MHD_YES != MHD_get_fdset (dmn, &rs, &ws, &es, &max)) {
			LM_ERR("unable to get file descriptors\n");
			return;
		}
		tv.tv_sec = 1;
		tv.tv_usec = 0;
		//LM_DBG("select(%d,%p,%p,%p,%p)\n",max+1, &rs, &ws, &es, &tv);
		status = select(max+1, &rs, &ws, &es, &tv);
		if (status < 0) {
			switch(errno){
				case EINTR:
					LM_DBG("error returned by select:"
							" [%d] [%d][%s]\n",
							status, errno, strerror(errno));
					break;
				default:
					LM_WARN("error returned by select:"
							" [%d] [%d][%s]\n",
							status, errno, strerror(errno));
					return;
			}
		}
		//LM_DBG("select returned %d\n", status);
		status = MHD_run(dmn);
		if (status == MHD_NO) {
			LM_ERR("unable to run http daemon\n");
			return;
		}
	}
#endif
	LM_DBG("HTTP Server stopped!\n");
}
开发者ID:ZRouter,项目名称:ZRouter,代码行数:92,代码来源:httpd_proc.c


注:本文中的MHD_run函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。