win32-clean-and-use-do-while

This commit is contained in:
Andy Green 2016-07-05 18:40:40 +08:00
parent 906006e21e
commit ae0d8d74f9
5 changed files with 302 additions and 38 deletions

View file

@ -0,0 +1,95 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>libwebsockets: Notes about generic-table</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
$(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="libwebsockets.org-logo.png"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">libwebsockets
</div>
<div id="projectbrief">Lightweight C library for HTML5 websockets</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;Page</span></a></li>
<li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('md_README.generic-table.html','');});
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle">
<div class="title">Notes about generic-table </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h2>What is generic-table? </h2>
<p>Generic-table is a JSON schema and client-side JS file that makes it easy to display live, table structured HTML over a ws link.</p>
<p>An example plugin and index.html using it are provided.</p>
<h2>Enabling for build </h2>
<p>Enable at CMake with -DLWS_WITH_PLUGINS=1</p>
<h2>Generic-table JSON </h2>
<h3>Column layout</h3>
<p>When the ws connection is established, the protocol should send a JSON message describing the table columns. For example</p>
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;msg = &quot;{\&quot;cols\&quot;:[&quot;</div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span>&#160; &quot; {\&quot;name\&quot;: \&quot;Date\&quot;},&quot;</div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span>&#160; &quot; {\&quot;name\&quot;: \&quot;Size\&quot;, \&quot;align\&quot;: \&quot;right\&quot;},&quot;</div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span>&#160; &quot; {\&quot;name\&quot;: \&quot;Icon\&quot;},&quot;</div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span>&#160; &quot; {\&quot;name\&quot;: \&quot;Name\&quot;, \&quot;href\&quot;: \&quot;uri\&quot;},&quot;</div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span>&#160; &quot; {\&quot;name\&quot;: \&quot;uri\&quot;, \&quot;hide\&quot;: \&quot;1\&quot; }&quot;</div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span>&#160; &quot; ]&quot;</div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span>&#160; &quot;}&quot;;</div></div><!-- fragment --><ul>
<li>This describes 5 columns</li>
<li>Only four columns (not "uri") should be visible</li>
<li>"Name" should be presented as a clickable link using "uri" as the destination, when a "uri" field is presented.</li>
<li>"Size" field should be presented aligned to the right</li>
</ul>
<h3>Table data</h3>
<p>The </p>
</div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
</ul>
</div>
</body>
</html>

View file

@ -0,0 +1,104 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>libwebsockets: Debugging problems</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
$(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="libwebsockets.org-logo.png"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">libwebsockets
</div>
<div id="projectbrief">Lightweight C library for HTML5 websockets</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;Page</span></a></li>
<li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('md_README.problems.html','');});
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle">
<div class="title">Debugging problems </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h2>Library is a component </h2>
<p>As a library, lws is just a component in a bigger application.</p>
<p>Many users are able to share their sources, but others decide not to, for "commerical advantage" or whatever.</p>
<p>This makes answering questions like "what is wrong with my code I am not
going to show you?" very difficult.</p>
<p>Even if it's clear there is a problem somewhere, it cannot be understood or reproduced by anyone else if it needs user code that isn't provided.</p>
<p>The biggest question is, "is this an lws problem actually"?</p>
<h2>Use the test apps as sanity checks </h2>
<p>The test server and client are extremely useful for sanity checks and debugging guidance.</p>
<ul>
<li>test apps work on your platform, then either<ul>
<li>your user code is broken, align it to how the test apps work, or,</li>
<li>something from your code is required to show an lws problem, provide a minimal patch on a test app so it can be reproduced</li>
</ul>
</li>
<li>test apps break on your platform, but work on, eg, x86_64, either<ul>
<li>toolchain or platform-specific (eg, OS) issue, or</li>
<li>lws platform support issue</li>
</ul>
</li>
<li>test apps break everywhere<ul>
<li>sounds like lws problem, info to reproduce and / or a patch is appreciated </li>
</ul>
</li>
</ul>
</div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
</ul>
</div>
</body>
</html>

View file

@ -0,0 +1,40 @@
\subsection*{What is generic-\/table? }
Generic-\/table is a J\+S\+ON schema and client-\/side JS file that makes it easy to display live, table structured H\+T\+ML over a ws link.
An example plugin and index.\+html using it are provided.
\subsection*{Enabling for build }
Enable at C\+Make with -\/\+D\+L\+W\+S\+\_\+\+W\+I\+T\+H\+\_\+\+P\+L\+U\+G\+I\+NS=1
\subsection*{Generic-\/table J\+S\+ON }
\subsubsection*{Column layout}
When the ws connection is established, the protocol should send a J\+S\+ON message describing the table columns. For example
\begin{DoxyCode}
1 msg = "\{\(\backslash\)"cols\(\backslash\)":["
2 " \{\(\backslash\)"name\(\backslash\)": \(\backslash\)"Date\(\backslash\)"\},"
3 " \{\(\backslash\)"name\(\backslash\)": \(\backslash\)"Size\(\backslash\)", \(\backslash\)"align\(\backslash\)": \(\backslash\)"right\(\backslash\)"\},"
4 " \{\(\backslash\)"name\(\backslash\)": \(\backslash\)"Icon\(\backslash\)"\},"
5 " \{\(\backslash\)"name\(\backslash\)": \(\backslash\)"Name\(\backslash\)", \(\backslash\)"href\(\backslash\)": \(\backslash\)"uri\(\backslash\)"\},"
6 " \{\(\backslash\)"name\(\backslash\)": \(\backslash\)"uri\(\backslash\)", \(\backslash\)"hide\(\backslash\)": \(\backslash\)"1\(\backslash\)" \}"
7 " ]"
8 "\}";
\end{DoxyCode}
\begin{DoxyItemize}
\item This describes 5 columns
\item Only four columns (not \char`\"{}uri\char`\"{}) should be visible
\item \char`\"{}\+Name\char`\"{} should be presented as a clickable link using \char`\"{}uri\char`\"{} as the destination, when a \char`\"{}uri\char`\"{} field is presented.
\item \char`\"{}\+Size\char`\"{} field should be presented aligned to the right
\end{DoxyItemize}
\subsubsection*{Table data}
The

View file

@ -0,0 +1,34 @@
\subsection*{Library is a component }
As a library, lws is just a component in a bigger application.
Many users are able to share their sources, but others decide not to, for \char`\"{}commerical advantage\char`\"{} or whatever.
This makes answering questions like \char`\"{}what is wrong with my code I am not
going to show you?\char`\"{} very difficult.
Even if it\textquotesingle{}s clear there is a problem somewhere, it cannot be understood or reproduced by anyone else if it needs user code that isn\textquotesingle{}t provided.
The biggest question is, \char`\"{}is this an lws problem actually\char`\"{}?
\subsection*{Use the test apps as sanity checks }
The test server and client are extremely useful for sanity checks and debugging guidance.
\begin{DoxyItemize}
\item test apps work on your platform, then either
\begin{DoxyItemize}
\item your user code is broken, align it to how the test apps work, or,
\item something from your code is required to show an lws problem, provide a minimal patch on a test app so it can be reproduced
\end{DoxyItemize}
\item test apps break on your platform, but work on, eg, x86\+\_\+64, either
\begin{DoxyItemize}
\item toolchain or platform-\/specific (eg, OS) issue, or
\item lws platform support issue
\end{DoxyItemize}
\item test apps break everywhere
\begin{DoxyItemize}
\item sounds like lws problem, info to reproduce and / or a patch is appreciated
\end{DoxyItemize}
\end{DoxyItemize}

View file

@ -150,56 +150,47 @@ LWS_VISIBLE DWORD
lws_plat_wait_event(struct lws_context_per_thread* pt, int timeout)
{
int event_count = pt->fds_count + 1;
HANDLE* events = pt->events;
HANDLE *events = pt->events;
DWORD ev;
// the WSAWaitForMultipleEvents can wait for maximum of 64 handles
if(event_count <= WSA_MAXIMUM_WAIT_EVENTS)
{
return ev = WSAWaitForMultipleEvents(event_count, events,
FALSE, timeout, FALSE);
}
else
{
// back-up solution
// this is really ugly and introduces unneeded latency / unfairness
// but still better than the current crash
int timeout_left = timeout;
if (event_count <= WSA_MAXIMUM_WAIT_EVENTS)
return WSAWaitForMultipleEvents(event_count, events, FALSE,
timeout, FALSE);
// the smaller the step the closer we get to the valid solution
// and the more CPU we will use
int timeout_step = (timeout > 20) ? 20 : timeout;
/* you should use libuv instead of this */
int timeout_left = timeout;
while(timeout_left > 0)
{
int events_left = event_count;
int events_handled = 0;
timeout = 0;
// the smaller the step the closer we get to the valid solution
// and the more CPU we will use
int timeout_step = (timeout > 20) ? 20 : timeout;
while(events_left > 0)
{
// split to groups to size of max 64
int events_to_handle = (events_left > WSA_MAXIMUM_WAIT_EVENTS) ?
WSA_MAXIMUM_WAIT_EVENTS :
events_left;
do {
int events_left = event_count;
int events_handled = 0;
timeout = 0;
// wait only on the last group
if(events_left == events_to_handle)
timeout = timeout_step;
while (events_left > 0) {
// split to groups to size of max 64
int rem = (events_left > WSA_MAXIMUM_WAIT_EVENTS) ?
WSA_MAXIMUM_WAIT_EVENTS : events_left;
ev = WSAWaitForMultipleEvents(events_to_handle, &events[events_handled],
FALSE, timeout, FALSE);
// wait only on the last group
if (events_left == rem)
timeout = timeout_step;
if(ev != WSA_WAIT_TIMEOUT)
return ev + events_handled;
ev = WSAWaitForMultipleEvents(rem, &events[events_handled],
FALSE, timeout, FALSE);
events_handled += events_to_handle;
events_left -= events_to_handle;
}
if (ev != WSA_WAIT_TIMEOUT)
return ev + events_handled;
timeout_left -= timeout_step;
events_handled += rem;
events_left -= rem;
}
}
timeout_left -= timeout_step;
} while (timeout_left > 0);
return WSA_WAIT_TIMEOUT;
}