git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] Refactor winsock initialization into a separate function

From
Johannes Sixt <j.sixt@viscovery.net>
Date
Nov 24, 2009, 07:36 UTC
Message-ID
<4B0B8CF5.6080208@viscovery.net>
In-Reply-To
<alpine.DEB.2.00.0911240054420.14228@cone.home.martin.st>
Martin Storsjö schrieb:
> Signed-off-by: Martin Storsjo <martin@martin.st>

I have used this series in my tree for 6 weeks without negative sideffects. I haven't tested IPv6, though.

Here's an updated commit message with my ACK:

--- >8 --- Refactor winsock initialization into a separate function

The winsock library must be initialized. Since gethostbyname() is the first function that calls into winsock, it was overridden to do the initialization. This refactoring helps the next patch, where other functions can be called earlier.

Signed-off-by: Martin Storsjo <martin@martin.st>
Acked-by: Johannes Sixt <j6t@kdbg.org>
--- >8 ---
Show 37 quoted lines
> ---
>  compat/mingw.c |   15 ++++++++++++---
>  1 files changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/compat/mingw.c b/compat/mingw.c
> index 15fe33e..f9d82ff 100644
> --- a/compat/mingw.c
> +++ b/compat/mingw.c
> @@ -903,16 +903,25 @@ char **make_augmented_environ(const char *const *vars)
>  	return env;
>  }
>  
> -/* this is the first function to call into WS_32; initialize it */
> -#undef gethostbyname
> -struct hostent *mingw_gethostbyname(const char *host)
> +static void ensure_socket_initialization(void)
>  {
>  	WSADATA wsa;
> +	static int initialized = 0;
> +
> +	if (initialized)
> +		return;
>  
>  	if (WSAStartup(MAKEWORD(2,2), &wsa))
>  		die("unable to initialize winsock subsystem, error %d",
>  			WSAGetLastError());
>  	atexit((void(*)(void)) WSACleanup);
> +	initialized = 1;
> +}
> +
> +#undef gethostbyname
> +struct hostent *mingw_gethostbyname(const char *host)
> +{
> +	ensure_socket_initialization();
>  	return gethostbyname(host);
>  }
>  
Previous: Martin StorsjöNext: Martin Storsjö
Message 3 of 7 in “Add support for IPv6 on MinGW”
  1. 0/2 Add support for IPv6 on MinGWMartin Storsjö, Nov 23, 2009
  2. 1/2 Refactor winsock initialization into a separate functionMartin Storsjö, Nov 23, 2009
  3. Johannes SixtNov 24, 2009
  4. 2/2 Enable support for IPv6 on MinGWMartin Storsjö, Nov 23, 2009
  5. Johannes SixtNov 24, 2009
  6. Junio C HamanoNov 24, 2009
  7. Martin StorsjöNov 24, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.