[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 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);
return 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>
=========================================================