<div dir="ltr"><br><br>Am Sonntag, 22. Mai 2016 23:26:07 UTC+2 schrieb bel:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir="ltr"><br><br>On Sunday, May 22, 2016 at 11:04:44 AM UTC+2, Christian Mauderer wrote:<blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">I created a draft for a callback. It's not worked out and only thought as a basis for further discussions:</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">  <a href="https://github.com/c-mauderer/civetweb/commit/380db13ad3c6c504002ba508605ced6d8ab7d550" rel="nofollow" target="_blank" onmousedown="this.href='https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fc-mauderer%2Fcivetweb%2Fcommit%2F380db13ad3c6c504002ba508605ced6d8ab7d550\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFJX_xgyb0yZc44ap_jZbWdZ8jUrQ';return true;" onclick="this.href='https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fc-mauderer%2Fcivetweb%2Fcommit%2F380db13ad3c6c504002ba508605ced6d8ab7d550\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFJX_xgyb0yZc44ap_jZbWdZ8jUrQ';return true;">https://github.com/c-mauderer/<wbr>civetweb/commit/<wbr>380db13ad3c6c504002ba508605ced<wbr>6d8ab7d550</a></p></div></blockquote><div><br>I just had a look at the interface (civetweb.h), but not the implementation yet:<br><ul><li>Please do not change the typedef for <span><span>mg_thread_func_t, this is a compatibility issue (see also below).</span></span></li></ul></div></div></blockquote><div>OK. Like I said: It was only quickly hacked together change as a basis for further discussion so this one slipped.</div><blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir="ltr"><div><ul><li><span><span></span></span></li><li><span><span>You should not use enum types (like you did in your change to </span></span><span><span><span>init_thread) </span>but only enum constants (like in your </span></span><span><span><span>start_thread</span>) in the interface.<br>So you should remove the name, like<br><span style="font-family:courier new,monospace">enum <i>/* no name here */</i> { TIMEOUT_INFINITE = -1 };</span><br></span></span></li></ul></div></div></blockquote><div>I'll change that. Is there any special reason for that (like C standard compatibility issues) or is it just the coding style? <br></div><blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir="ltr"><div><ul><li><span><span></span></span></li><li><span><span>Since we need to replace <span style="font-family:courier new,monospace"><b>mg_start_thread_with_id</b></span>, there must be an additional output parameter </span></span><span><span style="font-family:courier new,monospace"><b>thread_id</b></span> in the <span style="font-family:courier new,monospace"><b>start_thread</b></span> callback. This parameter is later used in <span style="font-family:courier new,monospace"><b>mg_join_thread</b></span>, to wait for the thread to terminate. I think an additional callback for that is required as well. If thread creation is "outsourced", the code that took responsibility for thread creation should be able to handle termination as well, if this is required for a non-Windows-non-pthread threading system. In theory it could be done internally using an additional waitable object (event, mutex, ..), but I think this is a rare case that should not make the Windows and Linux code more complicated, so let's allow to handle it externally.<br></span></li></ul><br></div></div></blockquote><div>I assume you think of the <span style="font-family: courier new,monospace;"><b>pthread_t *threadidptr</b><font face="arial,sans-serif">. I have overseen this one. Should this be a generic pointer (<b>void *</b>) or can we use the <b>pthread_t *</b> pointer?</font></span> I think <b>pthread_t</b> is problematic on windows?<br></div><div> </div><blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir="ltr"><div> </div><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">I had the following problems:</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">- The thread has a different return type for windows and for POSIX. It seems that no thread is really using the possibility to return anything. Currently I removed the return and just set it to void. I would expect that this leads to warnings when compiling the code. How could we handle this?<br></p></div></blockquote><div><br>We already have a definition in civetweb.h:<br><b><span style="font-family:courier new,monospace"><span><span>typedef</span> <span>void</span> *(*<span>mg_thread_func_t</span>)(<span>void</span> *);</span></span></b><br>This is already a part of the public interface, so it must not be changed unless there are compelling reasons - style preferences are not compelling reasons.<br><br></div></div></blockquote><div>I didn't change it due to style preferences. I changed it due to the different return type on windows. The <b>_beginthreadex</b> call used on windows returns an unsigned while the POSIX functions return a void pointer. Both results haven't been used and just needed some extra #ifdefs. But like I said, it is quite likely a problem anyway so I will look into another solution.<br> </div><blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir="ltr"><div><br></div><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"></p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">- The <span style="font-family:courier new,monospace"><b>struct mg_context</b></span> is declared in the civetweb.h but defined in civetweb.c file. So It could be tricky to access any context fields from inside a callback (e.g. for getting parameters). How is this handled in other callbacks? Did I overlook something?<br></p></div></blockquote><div><br>See civetweb.h:<br><br><span style="font-family:courier new,monospace">CIVETWEB_API const char *<b>mg_get_option</b>(const struct mg_context *ctx, const char *name);<br> <br>CIVETWEB_API void *<b>mg_get_user_data</b>(const struct mg_context *ctx);<br></span><br></div></div></blockquote><div><br>Thanks for the hint. Rather than using the context directly some helper functions are used. It's definitively a better solution than some exposed internal structures would be. I just thought into a wrong direction.<br><br>I'll try to update the patch in the next few days and will report back with an improved version.<br></div></div>