lynx-dev
[Top][All Lists]
Advanced

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

LYNX-DEV Or maybe you mean something like this for _WINDOWS nsl_fork?


From: afn06760
Subject: LYNX-DEV Or maybe you mean something like this for _WINDOWS nsl_fork?
Date: Wed, 11 Mar 1998 04:48:25 GMT

Closer approximation to Windows nsl_fork using threads:

========================================================
LYwinutils.c :
========================================================
#define Win32_Winsock /* Because CYGWIN32 and MING32 need this. */

#include <windows.h>
#include <stdio.h>
#include <process.h>

#if defined(_WINDOWS) && defined(NSL_FORK)
 int pfd[2], cstat = 0;

void fork_fun (void *phost)
{
 
        /*  Child process */
        phost = (void *)gethostbyname(host);
}

int windows_nsl_fork (void)
{
  int nIndex = 1;
        /*
        **  Start block for thread-based gethostbyname() with
        **  checks for interrupts.
        */
        {
            /*
            **  Open Pipe.
            */
            _pipe(pfd, 512, O_TEXT);

            phost = (void *)NULL;

            _beginthread(fork_fun, 4096, (void *)phost);

            /*
            **  (parent) Wait until lookup finishes, or interrupt.
            */
           while ((phost == (void *)NULL) && (nIndex <= 30))
            {
                if (HTCheckForInterrupt())
                 {
                    _endthread();
                    FREE(host);
                    close(pfd[0]);
                    close(pfd[1]);
                    return HT_INTERRUPTED;
                 };
                _sleep(500UL); nIndex++;
            };
            /*
            **  Read as much as we can - should be the address.
            */
            IOCTL(pfd[0], FIONREAD, &cstat);
            if (cstat < 4)
                {
                if (TRACE)
                    fprintf(stderr,
                       "HTParseInet: NSL_FORK child returns only %d bytes.\n",
                            cstat);
                FREE(host);
                close(pfd[0]);
                close(pfd[1]);
                return -1;
                };
        if (soc_in->sin_addr.s_addr == 0) {
            if (TRACE) {
                fprintf(stderr,
                        "HTParseInet: Can't find internet node name `%s'.\n",
                        host);
            }
            FREE(host);
            return -1;
        }
        FREE(host);
#ifdef MVS
        if (TRACE) {
            fprintf(stderr,
                    "HTParseInet: gethostbyname() returned %d\n", phost);
        }
#endif /* MVS */
}

#ifdef _WINDOWS
void windowsstartup ()
{
    WSADATA WSAData;
        int err;
        WORD wVerReq;

        wVerReq = MAKEWORD(1,1);

        err = WSAStartup(wVerReq, &WSAData);
        if (err != 0)
        {
            printf("No Winsock found, sorry.");
            sleep(5);
            return;
        }
}

void windowscleanup ()
{
    WSACleanup();
}
#endif /* _WINDOWS */


reply via email to

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