Ross incorrectly assumed you were talking about multithreading.<br>If you look at the source, win32.c, you see:<br><br>---<br>int enet_initialize (void)<br>{<br>    WORD versionRequested = MAKEWORD (1, 1);<br>    WSADATA wsaData;<br>
   <br>    if (WSAStartup (versionRequested, & wsaData))<br>       return -1;<br><br>    if (LOBYTE (wsaData.wVersion) != 1||<br>        HIBYTE (wsaData.wVersion) != 1)<br>    {<br>       WSACleanup ();<br>       <br>
       return -1;<br>    }<br><br>    timeBeginPeriod (1);<br><br>    return 0;<br>}<br><br>void<br>enet_deinitialize (void)<br>{<br>    timeEndPeriod (1);<br><br>    WSACleanup ();<br>}<br>---<br><br>I'm not sure what the behavior of WSAStartup and WSACleanup() is with respect to reference counting, but googling that will give you the answer.<br>
I know that timeBeginPeriod() is really reference counted, but I think these days the timer is always at 1 ms resolution, so it doesn't really harm no matter how many calls you make.<br><br>As for a definite answer, I'd just wrap ENet's initialize and use your own guard:<br>
<br>static bool setup;<br>
void InitEnet()<br>{<br>  if(!setup)<br>  {<br>    enet_initialize();<br>    setup=true;<br>  }<br>}<br>void CloseENet()<br>{<br>  if(setup)<br>  { enet_deinitialize();<br>   setup=false;<br>  }<br>}<br><br>That will always be safe (just the ugly global var which you might tuck away) and safeguard you from future changes in ENet wrt to the reference counted behavior.<br>
<br>Cheers,<br>Ruud<br><br><div class="gmail_quote">On Wed, Jul 27, 2011 at 7:12 AM, Soren Dreijer <span dir="ltr"><<a href="mailto:dreijer@echobit.net">dreijer@echobit.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I don't see how that answers the question. As the FAQ states, enet doesn't<br>
use any significant global variables, but it definitely uses 'some' or else<br>
we wouldn't be required to call a global initialize function. The question<br>
is whether a second call will reset anything that existing ENetHost<br>
structures rely on.<br>
<div class="im"><br>
> So my assumption would be NO, but you could try .. but why you would want<br>
> to call this multiple times is a mystery, maybe rethink your application<br>
> design ..<br>
<br>
</div>As I said in my original post, most APIs on Windows let you call initialize<br>
functions multiple times in case you want to be absolutely sure something is<br>
initialized before using it. What if you happen to use two (unrelated)<br>
libraries in your project that both use enet internally? Unless those two<br>
libraries defer to the caller to initialize enet (which might not be<br>
intended at all if the library is supposed to hide away such details) then<br>
there's no way for me to guarantee that enet_initialize() won't be called<br>
twice in the same process.<br>
<br>
I already worked around this 'issue' in my own code, but I'm mostly just<br>
being proactive here and trying to determine if it'd be possible or not.<br>
<br>
> -----Original Message-----<br>
> From: <a href="mailto:enet-discuss-bounces@cubik.org">enet-discuss-bounces@cubik.org</a> [mailto:<a href="mailto:enet-discuss-">enet-discuss-</a><br>
> <a href="mailto:bounces@cubik.org">bounces@cubik.org</a>] On Behalf Of Ross Linder<br>
> Sent: Tuesday, July 26, 2011 11:39 PM<br>
> To: Discussion of the ENet library<br>
> Subject: Re: [ENet-discuss] Calling enet_initialise() more than once<br>
<div><div></div><div class="h5">><br>
> I think the FAQ answers this pretty much ..<br>
><br>
> --><br>
> Is ENet thread safe?<br>
><br>
> ENet does not use any significant global variables, the vast majority of<br>
state<br>
> is encapsulated in the ENetHost structure. As such, as long as the<br>
> application guards access to this structure, then ENet should operate fine<br>
in<br>
> a multithreaded environment.<br>
> <--<br>
><br>
> So my assumption would be NO, but you could try .. but why you would want<br>
> to<br>
> call this multiple times is a mystery, maybe rethink your application<br>
> design ..<br>
> --<br>
><br>
> On Tuesday 26 July 2011 20:09:09 Soren Dreijer wrote:<br>
> > Am I allowed to call enet_initialize() more than once in my application?<br>
> > I'm coming from the world of Windows where most APIs, such as<br>
> WSAStartup()<br>
> > or CoInitializeEx(), can be called multiple times as long as their<br>
cleanup<br>
> > counterparts are called the same number of times.<br>
> ><br>
> ><br>
> ><br>
> > Is that true for enet as well or will enet_initialize() reset any<br>
already<br>
> > initialized global state thereby potentially messing up other parts of<br>
my<br>
> > application that currently use enet?<br>
><br>
><br>
> _______________________________________________<br>
> ENet-discuss mailing list<br>
> <a href="mailto:ENet-discuss@cubik.org">ENet-discuss@cubik.org</a><br>
> <a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><br>
<br>
_______________________________________________<br>
ENet-discuss mailing list<br>
<a href="mailto:ENet-discuss@cubik.org">ENet-discuss@cubik.org</a><br>
<a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><br>
</div></div></blockquote></div><br>