lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LYNX-DEV Re: _WINDOWS patch for doing NSL_FORK


From: afn06760
Subject: LYNX-DEV Re: _WINDOWS patch for doing NSL_FORK
Date: Fri, 13 Mar 1998 19:24:57 GMT

>     * From: address@hidden
>     * Date: Fri, 13 Mar 1998 06:16:10 GMT
>>     * From: address@hidden
>>     * Date: Fri, 13 Mar 1998 03:44:38 GMT
>
>The following is a test program compiled with MINGW32 gcc2.8 to
>demonstrate a simple, but effective, use of subthreads to implement
>NSL_FORK for _WINDOWS in HTTCP.c.  Note that the text at the bottom
>of this note is copied from a Dos window while running Windows 95 and
>after connecting to an internet server.  Note also how the selective
>use of global variables simplifies the code.
>
>======================================================================
>socktest.c:
>======================================================================
>
>#define Win32_Winsock /* Needed for cygwin/mingw32 gcc */
>#include <windows.h>
>#include <stdio.h>
>#include <stdlib.h>
>#include <conio.h>
>
>struct hostent FAR *phost;
>const char FAR *host = "www.mit.edu";
>
>void _fork_func (void *arglist)
>{
>        phost = gethostbyname(host);
>}
>
>int main (int argc, char **argv)
>{
> HANDLE hThread;
> WSADATA buffer;
> WORD wVerReq;
>
>        wVerReq = MAKEWORD(1,1);
>
>        if (WSAStartup(wVerReq, &buffer))
>         {printf("Unable to start wsock32.dll\n"); return 1; };
>        hThread = _beginthread((void (*)())_fork_func,
>        4096*2,
>        (void *)NULL);
>        while (!phost)
>         if (kbhit())
>          {CloseHandle(hThread); printf("Thread stopped. host: %s\n",host); ret
>urn 0; };
>        printf("Host found: %s %X\n", host, phost);
>        return WSACleanup();
>}
>
>
>
>========================================================
>E:\src\bcsock>gcc -O -o socktest socktest.c -lwsock32
>socktest.c: In function `main':
>socktest.c:27: warning: assignment makes pointer from integer without a cast
>
>E:\src\bcsock>socktest
>Host found: www.mit.edu 410C2C
>
>E:\src\bcsock>
>
>=========================================================

The fix for the problem suggested by Wayne Buttles et. al. is the
following, in which the console version of _beginthread is
replaced by the Win32 CreateThread.  Note that there are tests
for correct handles in the code.  For users of MINGW32 gcc, the
problem with getting a Dos-style intermediate text file for
`mailto:....' is in src/GridText.c, where `fputc('\n', fp);' is
used to end each line copied to the intermediate text file.
The two instances of these fputc() calls can be replaced by
`fprintf(fp, "\r\n");' and the resulting lynx.exe will pass a
correct text file to notepad or any other Windows text editor.
This is coming from that version of lynx with the corrections
noted.

#ifdef _WINDOWS
    char host[512];
    struct hostent  *phost;     /* Pointer to host - See netdb.h */
unsigned long _fork_func (void *arglist)
{
        return (unsigned long)(phost = gethostbyname(host));
}
#endif

#ifdef _WINDOWS
/* Note that this is a replacement for the `phost=gethostbyname()' */
/* statement in the #else clause below: */
        {
         unsigned long hThread, dwThreadID;
         hThread = CreateThread((void *)NULL, 4096UL,
                (unsigned long (*)())_fork_func,
                (void *)NULL, 0UL, (unsigned long *)&dwThreadID);
         if (!hThread)
                MessageBox((void *)NULL, "CreateThread",
                        "CreateThread Failed", 0L);
         while (!phost)
         if (HTCheckForInterrupt())
          {
           /* Note that host is a character array and is not freed */
           /* to avoid possible subthread problems: */
           if (!CloseHandle(hThread))
                MessageBox((void *)NULL, "CloseHandle","CloseHandle Failed",
                        0L);
           return HT_INTERRUPTED;
          };
        };
#else
        phost = gethostbyname(host);    /* See netdb.h */
#endif

reply via email to

[Prev in Thread] Current Thread [Next in Thread]