簡體   English   中英

貓鼬服務器回調循環

[英]Mongoose Server callback loop

在尋找實現Web服務器的C庫之后,我得到了有關Mongoose的知識。 我實際上已經通過幾個示例使它起作用,這些示例調用了實際上處理傳入和傳出數據的回調函數。 我在Windows上使用,使用Visual Studio 2008進行編譯和調試。

我將其稱為“會話”,它如下:

int CHttpsCom::Session( void )
{

  struct mg_context *ctx;

  const char *options[] = {
    "listening_ports", "443s",
#ifdef _DEBUG
    "ssl_certificate", "c:\\temp\\cert.pem",
#else
    "ssl_certificate", "cert.pem",
#endif
    NULL
  };

  ctx = mg_start( &callback, NULL, options );

  if( !ctx )
    return 1;

  //getchar();  // Wait until user hits "enter"
  while ( LeaveIt == false );

  Sleep(3500);// without this it won't work

  mg_stop( ctx ); 

  return 0;

}

我注意到,大多數示例中有100%的示例使用getchar來將會話的結尾與回調執行的結尾同步。 我有一個發布消息后設置的LeaveIt標志。 如果我不使用上面的“睡眠”,則會在庫內部出現死鎖。 有沒有更好的方法來處理此等待回調結束的事件?

謝謝。

更換

while ( LeaveIt == false );

Sleep(3500);// without this it won't work

這樣(在最壞的情況下,您將節省CPU消耗):

while (!LeaveIt)
{
    Sleep(500);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM