[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
LYNX-DEV Is this what you mean by nsl_fork?
From: |
afn06760 |
Subject: |
LYNX-DEV Is this what you mean by nsl_fork? |
Date: |
Wed, 11 Mar 1998 03:36:18 GMT |
Is this what you are getting at in the HTTCP.c code with the
fork around gethostbyname?
==================================================
nsl_fork.c :
#include <windows.h>
#include <process.h>
#if defined(_WINDOWS) && defined(NSL_FORK)
HANDLE fpid, waitret = (HANDLE)0;
int pfd[2], cstat, cst1 = 0;
void fork_fun ()
{
struct hostent FAR * phost;
** Child - for the long call.
*/
phost = gethostbyname(host);
cst1 = 0;
/*
** Return value (or nulls).
*/
if (phost != NULL)
write(pfd[1], phost->h_addr, phost->h_length);
else
write(pfd[1], &cst1, 4);
/*
** Return an error code.
*/
_endthread();
}
int windows_nsl_fork (void)
{
/*
** Start block for fork-based gethostbyname() with
** checks for interrupts. - Tom Zerucha (address@hidden) & FM
*/
{
/*
** Pipe, child pid, and status buffers.
*/
_pipe(pfd, 512, O_BINARY);
fpid = _beginthread(fork_fun, 4096*4, (void *)NULL);
/*
** (parent) Wait until lookup finishes, or interrupt.
*/
cstat = 0;
while (cstat <= 0) {
/*
** Exit when data sent.
*/
IOCTL(pfd[0], FIONREAD, &cstat);
if (cstat > 0)
break;
/*
** Exit if child exited.
*/
cwait(&waitret, fpid, WAIT_CHILD);
if (waitret > 0)
break;
/*
** Cancel if interrupt key pressed.
*/
if (HTCheckForInterrupt()) {
if (TRACE) {
fprintf(stderr,
"HTParseInet: INTERRUPTED gethostbyname.\n");
}
_endthread();
FREE(host);
close(pfd[0]);
close(pfd[1]);
return HT_INTERRUPTED;
}
/*
** Be nice to the system.
*/
sleep(1);
}
if (waitret <= 0)
cwait(&waitret, fpid, WAIT_CHILD);
else if (WIFSTOPPED(cst1)) {
fprintf(stderr,
"HTParseInet: NSL_FORK child %d is stopped, status 0x%x!\n",
(int)waitret, cst1);
}
}
/*
** 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);
fprintf(stderr,
" Trying again without forking.\n");
}
phost = gethostbyname(host); /* See netdb.h */
if (!phost) {
if (TRACE) {
fprintf(stderr,
"HTParseInet: Can't find internet node name `%s'.\n",
host);
}
memset((void *)&soc_in->sin_addr, 0,
sizeof(soc_in->sin_addr));
} else {
memcpy((void *)&soc_in->sin_addr,
phost->h_addr, phost->h_length);
}
#ifdef NOTDEFINED
cstat = read(pfd[0], (void *)&soc_in->sin_addr , 4);
#endif /* NOTDEFINED */
} else {
cstat = read(pfd[0], (void *)&soc_in->sin_addr , cstat);
}
close(pfd[0]);
close(pfd[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 */
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- LYNX-DEV Is this what you mean by nsl_fork?,
afn06760 <=