Reimplemented winsock asynchronous DNS services. No longer use a
fork()ed process, but either a service thread or inline blocking calls for non-threading architectures. (Makes Free Agent16 work again.)
This commit is contained in:
parent
5d2a658865
commit
bdb6bec83a
|
@ -526,48 +526,6 @@ typedef struct timeval TIMEVAL, *PTIMEVAL, *LPTIMEVAL;
|
|||
#define WS_DUP_OFFSET 0x0002 /* internal pointers are offsets */
|
||||
#define WS_DUP_SEGPTR 0x0004 /* internal pointers are SEGPTRs */
|
||||
/* by default, internal pointers are linear */
|
||||
/* async DNS op flags */
|
||||
|
||||
#define AOP_IO 0x0000001 /* aop_control paramaters */
|
||||
|
||||
#define AOP_CONTROL_REMOVE 0x0000000 /* aop_control return values */
|
||||
#define AOP_CONTROL_KEEP 0x0000001
|
||||
|
||||
typedef struct __aop
|
||||
{
|
||||
/* AOp header */
|
||||
|
||||
struct __aop *next, *prev;
|
||||
int fd[2]; /* pipe */
|
||||
int (*aop_control)(struct __aop*, int); /* SIGIO handler */
|
||||
pid_t pid; /* child process pid */
|
||||
|
||||
/* custom data */
|
||||
|
||||
HWND hWnd; /* hWnd to post */
|
||||
UINT uMsg; /* uMsg message to. */
|
||||
|
||||
union
|
||||
{
|
||||
SEGPTR seg_base;
|
||||
LPSTR lin_base;
|
||||
void* ptr_base;
|
||||
} b; /* buffer to copy result to */
|
||||
|
||||
UINT buflen;
|
||||
UINT flags; /* WSMSG_ASYNC_... */
|
||||
} ws_async_op;
|
||||
|
||||
#define WSMSG_ASYNC_HOSTBYNAME 0x0001
|
||||
#define WSMSG_ASYNC_HOSTBYADDR 0x0002
|
||||
#define WSMSG_ASYNC_PROTOBYNAME 0x0010
|
||||
#define WSMSG_ASYNC_PROTOBYNUM 0x0020
|
||||
#define WSMSG_ASYNC_SERVBYNAME 0x0100
|
||||
#define WSMSG_ASYNC_SERVBYPORT 0x0200
|
||||
#define WSMSG_ASYNC_RQMASK 0x0fff
|
||||
|
||||
#define WSMSG_WIN32_AOP 0x1000
|
||||
#define WSMSG_DEAD_AOP 0x8000
|
||||
|
||||
typedef struct __sop /* WSAAsyncSelect() control struct */
|
||||
{
|
||||
|
@ -620,25 +578,6 @@ int WS_dup_he(LPWSINFO pwsi, struct hostent* p_he, int flag);
|
|||
int WS_dup_pe(LPWSINFO pwsi, struct protoent* p_pe, int flag);
|
||||
int WS_dup_se(LPWSINFO pwsi, struct servent* p_se, int flag);
|
||||
|
||||
void WS_do_async_gethost(LPWSINFO, unsigned);
|
||||
void WS_do_async_getproto(LPWSINFO, unsigned);
|
||||
void WS_do_async_getserv(LPWSINFO, unsigned);
|
||||
|
||||
/* winsock_dns.c */
|
||||
extern HANDLE16 __WSAsyncDBQuery(LPWSINFO pwsi, HWND hWnd, UINT uMsg,
|
||||
INT type, LPCSTR init, INT len, LPCSTR proto, void* sbuf,
|
||||
INT buflen, UINT flag);
|
||||
|
||||
int WINSOCK_async_io(int fd, int async);
|
||||
int WINSOCK_unblock_io(int fd, int noblock);
|
||||
|
||||
int WINSOCK_check_async_op(ws_async_op* p_aop);
|
||||
void WINSOCK_link_async_op(ws_async_op* p_aop);
|
||||
void WINSOCK_unlink_async_op(ws_async_op* p_aop);
|
||||
int WINSOCK_cancel_async_op(ws_async_op* p_aop);
|
||||
|
||||
void WINSOCK_cancel_task_aops(HTASK16, void (*__memfree)(void*) );
|
||||
|
||||
BOOL WINSOCK_HandleIO(int* fd_max, int num_pending, fd_set pending_set[3], fd_set master_set[3] );
|
||||
void WINSOCK_Shutdown(void);
|
||||
UINT16 wsaErrno(void);
|
||||
|
|
|
@ -38,7 +38,7 @@ C_SRCS = \
|
|||
win32s16.c \
|
||||
windebug.c \
|
||||
winsock.c \
|
||||
winsock_dns.c \
|
||||
winsock_async.c \
|
||||
wsprintf.c \
|
||||
xmalloc.c
|
||||
|
||||
|
|
281
misc/winsock.c
281
misc/winsock.c
|
@ -122,6 +122,18 @@ static int _px_tcp_ops[] = {
|
|||
static int _check_ws(LPWSINFO pwsi, ws_socket* pws);
|
||||
static char* _check_buffer(LPWSINFO pwsi, int size);
|
||||
|
||||
/* ----------------------------------- non-blocking I/O */
|
||||
|
||||
static int WINSOCK_unblock_io(int fd, int noblock)
|
||||
{
|
||||
int fd_flags;
|
||||
|
||||
fd_flags = fcntl(fd, F_GETFL, 0);
|
||||
if (fcntl(fd, F_SETFL, (noblock)? fd_flags | O_NONBLOCK
|
||||
: fd_flags & ~O_NONBLOCK ) != -1) return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* convert_sockopt()
|
||||
*
|
||||
|
@ -413,8 +425,6 @@ INT WINAPI WSAStartup(UINT wVersionRequested, LPWSADATA lpWSAData)
|
|||
void WINSOCK_Shutdown()
|
||||
{
|
||||
/* Called on exit(), has to remove all outstanding async DNS processes. */
|
||||
|
||||
WINSOCK_cancel_task_aops( 0, __ws_memfree );
|
||||
}
|
||||
|
||||
INT WINSOCK_DeleteTaskWSI( TDB* pTask, LPWSINFO pwsi )
|
||||
|
@ -429,10 +439,6 @@ INT WINSOCK_DeleteTaskWSI( TDB* pTask, LPWSINFO pwsi )
|
|||
|
||||
if( --pwsi->num_startup > 0 ) return 0;
|
||||
|
||||
SIGNAL_MaskAsyncEvents( TRUE );
|
||||
WINSOCK_cancel_task_aops( pTask->hSelf, __ws_memfree );
|
||||
SIGNAL_MaskAsyncEvents( FALSE );
|
||||
|
||||
/* unlink socket control struct */
|
||||
|
||||
if( pwsi == _wsi_list )
|
||||
|
@ -1947,269 +1953,6 @@ INT16 WINAPI WINSOCK_gethostname16(char *name, INT16 namelen)
|
|||
/* ------------------------------------- Windows sockets extensions -- *
|
||||
* *
|
||||
* ------------------------------------------------------------------- */
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetHostByAddr() (WINSOCK.102)
|
||||
*/
|
||||
HANDLE16 WINAPI WSAAsyncGetHostByAddr16(HWND16 hWnd, UINT16 uMsg, LPCSTR addr,
|
||||
INT16 len, INT16 type, SEGPTR sbuf, INT16 buflen)
|
||||
{
|
||||
LPWSINFO pwsi = wsi_find(GetCurrentTask());
|
||||
|
||||
TRACE(winsock, "(%08x): hwnd %04x, msg %04x, addr %08x[%i]\n",
|
||||
(unsigned)pwsi, hWnd, uMsg, (unsigned)addr , len );
|
||||
|
||||
if( pwsi )
|
||||
return __WSAsyncDBQuery(pwsi, hWnd, uMsg, type, addr, len,
|
||||
NULL, (void*)sbuf, buflen, WSMSG_ASYNC_HOSTBYADDR );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetHostByAddr() (WSOCK32.102)
|
||||
*/
|
||||
HANDLE WINAPI WSAAsyncGetHostByAddr(HWND hWnd, UINT uMsg, LPCSTR addr,
|
||||
INT len, INT type, LPSTR sbuf, INT buflen)
|
||||
{
|
||||
LPWSINFO pwsi = wsi_find(GetCurrentTask());
|
||||
|
||||
TRACE(winsock, "(%08x): hwnd %04x, msg %08x, addr %08x[%i]\n",
|
||||
(unsigned)pwsi, (HWND16)hWnd, uMsg, (unsigned)addr , len );
|
||||
|
||||
if( pwsi )
|
||||
return __WSAsyncDBQuery(pwsi, hWnd, uMsg, type, addr, len,
|
||||
NULL, (void*)sbuf, buflen, WSMSG_ASYNC_HOSTBYADDR | WSMSG_WIN32_AOP);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetHostByName() (WINSOCK.103)
|
||||
*/
|
||||
HANDLE16 WINAPI WSAAsyncGetHostByName16(HWND16 hWnd, UINT16 uMsg, LPCSTR name,
|
||||
SEGPTR sbuf, INT16 buflen)
|
||||
{
|
||||
LPWSINFO pwsi = wsi_find(GetCurrentTask());
|
||||
|
||||
TRACE(winsock, "(%08x): hwnd %04x, msg %04x, host %s,
|
||||
buffer %i\n", (unsigned)pwsi, hWnd, uMsg, (name)?name:NULL_STRING, (int)buflen );
|
||||
|
||||
if( pwsi )
|
||||
return __WSAsyncDBQuery(pwsi, hWnd, uMsg, 0, name, 0,
|
||||
NULL, (void*)sbuf, buflen, WSMSG_ASYNC_HOSTBYNAME );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetHostByName32() (WSOCK32.103)
|
||||
*/
|
||||
HANDLE WINAPI WSAAsyncGetHostByName(HWND hWnd, UINT uMsg, LPCSTR name,
|
||||
LPSTR sbuf, INT buflen)
|
||||
{
|
||||
LPWSINFO pwsi = wsi_find(GetCurrentTask());
|
||||
TRACE(winsock, "(%08x): hwnd %04x, msg %08x, host %s, buffer %i\n",
|
||||
(unsigned)pwsi, (HWND16)hWnd, uMsg,
|
||||
(name)?name:NULL_STRING, (int)buflen );
|
||||
if( pwsi )
|
||||
return __WSAsyncDBQuery(pwsi, hWnd, uMsg, 0, name, 0,
|
||||
NULL, (void*)sbuf, buflen, WSMSG_ASYNC_HOSTBYNAME | WSMSG_WIN32_AOP);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetProtoByName() (WINSOCK.105)
|
||||
*/
|
||||
HANDLE16 WINAPI WSAAsyncGetProtoByName16(HWND16 hWnd, UINT16 uMsg, LPCSTR name,
|
||||
SEGPTR sbuf, INT16 buflen)
|
||||
{
|
||||
LPWSINFO pwsi = wsi_find(GetCurrentTask());
|
||||
|
||||
TRACE(winsock, "(%08x): hwnd %04x, msg %08x, protocol %s\n",
|
||||
(unsigned)pwsi, (HWND16)hWnd, uMsg, (name)?name:NULL_STRING );
|
||||
|
||||
if( pwsi )
|
||||
return __WSAsyncDBQuery(pwsi, hWnd, uMsg, 0, name, 0,
|
||||
NULL, (void*)sbuf, buflen, WSMSG_ASYNC_PROTOBYNAME );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetProtoByName() (WSOCK32.105)
|
||||
*/
|
||||
HANDLE WINAPI WSAAsyncGetProtoByName(HWND hWnd, UINT uMsg, LPCSTR name,
|
||||
LPSTR sbuf, INT buflen)
|
||||
{
|
||||
LPWSINFO pwsi = wsi_find(GetCurrentTask());
|
||||
|
||||
TRACE(winsock, "(%08x): hwnd %04x, msg %08x, protocol %s\n",
|
||||
(unsigned)pwsi, (HWND16)hWnd, uMsg, (name)?name:NULL_STRING );
|
||||
|
||||
if( pwsi )
|
||||
return __WSAsyncDBQuery(pwsi, hWnd, uMsg, 0, name, 0,
|
||||
NULL, (void*)sbuf, buflen, WSMSG_ASYNC_PROTOBYNAME | WSMSG_WIN32_AOP);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetProtoByNumber() (WINSOCK.104)
|
||||
*/
|
||||
HANDLE16 WINAPI WSAAsyncGetProtoByNumber16(HWND16 hWnd, UINT16 uMsg, INT16 number,
|
||||
SEGPTR sbuf, INT16 buflen)
|
||||
{
|
||||
LPWSINFO pwsi = wsi_find(GetCurrentTask());
|
||||
|
||||
TRACE(winsock, "(%08x): hwnd %04x, msg %04x, num %i\n",
|
||||
(unsigned)pwsi, hWnd, uMsg, number );
|
||||
|
||||
if( pwsi )
|
||||
return __WSAsyncDBQuery(pwsi, hWnd, uMsg, number, NULL, 0,
|
||||
NULL, (void*)sbuf, buflen, WSMSG_ASYNC_PROTOBYNUM );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetProtoByNumber() (WSOCK32.104)
|
||||
*/
|
||||
HANDLE WINAPI WSAAsyncGetProtoByNumber(HWND hWnd, UINT uMsg, INT number,
|
||||
LPSTR sbuf, INT buflen)
|
||||
{
|
||||
LPWSINFO pwsi = wsi_find(GetCurrentTask());
|
||||
|
||||
TRACE(winsock, "(%08x): hwnd %04x, msg %08x, num %i\n",
|
||||
(unsigned)pwsi, (HWND16)hWnd, uMsg, number );
|
||||
|
||||
if( pwsi )
|
||||
return __WSAsyncDBQuery(pwsi, hWnd, uMsg, number, NULL, 0,
|
||||
NULL, (void*)sbuf, buflen, WSMSG_ASYNC_PROTOBYNUM | WSMSG_WIN32_AOP);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetServByName() (WINSOCK.107)
|
||||
*/
|
||||
HANDLE16 WINAPI WSAAsyncGetServByName16(HWND16 hWnd, UINT16 uMsg, LPCSTR name,
|
||||
LPCSTR proto, SEGPTR sbuf, INT16 buflen)
|
||||
{
|
||||
LPWSINFO pwsi = wsi_find(GetCurrentTask());
|
||||
|
||||
TRACE(winsock, "(%08x): hwnd %04x, msg %04x, name %s, proto %s\n",
|
||||
(unsigned)pwsi, hWnd, uMsg,
|
||||
(name)?name:NULL_STRING, (proto)?proto:NULL_STRING );
|
||||
|
||||
if( pwsi )
|
||||
{
|
||||
int i = wsi_strtolo( pwsi, name, proto );
|
||||
|
||||
if( i )
|
||||
return __WSAsyncDBQuery(pwsi, hWnd, uMsg, 0, pwsi->buffer, 0,
|
||||
pwsi->buffer + i, (void*)sbuf, buflen, WSMSG_ASYNC_SERVBYNAME );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetServByName() (WSOCK32.107)
|
||||
*/
|
||||
HANDLE WINAPI WSAAsyncGetServByName(HWND hWnd, UINT uMsg, LPCSTR name,
|
||||
LPCSTR proto, LPSTR sbuf, INT buflen)
|
||||
{
|
||||
LPWSINFO pwsi = wsi_find(GetCurrentTask());
|
||||
|
||||
TRACE(winsock, "(%08x): hwnd %04x, msg %08x, name %s, proto %s\n",
|
||||
(unsigned)pwsi, (HWND16)hWnd, uMsg,
|
||||
(name)?name:NULL_STRING, (proto)?proto:NULL_STRING );
|
||||
if( pwsi )
|
||||
{
|
||||
int i = wsi_strtolo( pwsi, name, proto );
|
||||
|
||||
if( i )
|
||||
return __WSAsyncDBQuery(pwsi, hWnd, uMsg, 0, pwsi->buffer, 0,
|
||||
pwsi->buffer + i, (void*)sbuf, buflen, WSMSG_ASYNC_SERVBYNAME | WSMSG_WIN32_AOP);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetServByPort() (WINSOCK.106)
|
||||
*/
|
||||
HANDLE16 WINAPI WSAAsyncGetServByPort16(HWND16 hWnd, UINT16 uMsg, INT16 port,
|
||||
LPCSTR proto, SEGPTR sbuf, INT16 buflen)
|
||||
{
|
||||
LPWSINFO pwsi = wsi_find(GetCurrentTask());
|
||||
|
||||
TRACE(winsock, "(%08x): hwnd %04x, msg %04x, port %i, proto %s\n",
|
||||
(unsigned)pwsi, hWnd, uMsg, port, (proto)?proto:NULL_STRING );
|
||||
|
||||
if( pwsi )
|
||||
{
|
||||
int i = wsi_strtolo( pwsi, proto, NULL );
|
||||
|
||||
if( i )
|
||||
return __WSAsyncDBQuery(pwsi, hWnd, uMsg, port, pwsi->buffer, 0,
|
||||
NULL, (void*)sbuf, buflen, WSMSG_ASYNC_SERVBYPORT );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetServByPort() (WSOCK32.106)
|
||||
*/
|
||||
HANDLE WINAPI WSAAsyncGetServByPort(HWND hWnd, UINT uMsg, INT port,
|
||||
LPCSTR proto, LPSTR sbuf, INT buflen)
|
||||
{
|
||||
LPWSINFO pwsi = wsi_find(GetCurrentTask());
|
||||
|
||||
TRACE(winsock, "(%08x): hwnd %04x, msg %08x, port %i, proto %s\n",
|
||||
(unsigned)pwsi, (HWND16)hWnd, uMsg, port, (proto)?proto:NULL_STRING );
|
||||
|
||||
if( pwsi )
|
||||
{
|
||||
int i = wsi_strtolo( pwsi, proto, NULL );
|
||||
|
||||
if( i )
|
||||
return __WSAsyncDBQuery(pwsi, hWnd, uMsg, port, pwsi->buffer, 0,
|
||||
NULL, (void*)sbuf, buflen, WSMSG_ASYNC_SERVBYPORT | WSMSG_WIN32_AOP);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* WSACancelAsyncRequest() (WINSOCK.108)(WSOCK32.109)
|
||||
*/
|
||||
INT WINAPI WSACancelAsyncRequest(HANDLE hAsyncTaskHandle)
|
||||
{
|
||||
INT retVal = SOCKET_ERROR;
|
||||
LPWSINFO pwsi = wsi_find(GetCurrentTask());
|
||||
ws_async_op* p_aop = (ws_async_op*)WS_HANDLE2PTR(hAsyncTaskHandle);
|
||||
|
||||
TRACE(winsock, "(%08x): handle %08x\n",
|
||||
(unsigned)pwsi, hAsyncTaskHandle);
|
||||
if( pwsi )
|
||||
{
|
||||
SIGNAL_MaskAsyncEvents( TRUE ); /* block SIGIO */
|
||||
if( WINSOCK_cancel_async_op(p_aop) )
|
||||
{
|
||||
WS_FREE(p_aop);
|
||||
pwsi->num_async_rq--;
|
||||
retVal = 0;
|
||||
}
|
||||
else pwsi->err = WSAEINVAL;
|
||||
SIGNAL_MaskAsyncEvents( FALSE );
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
INT16 WINAPI WSACancelAsyncRequest16(HANDLE16 hAsyncTaskHandle)
|
||||
{
|
||||
return (HANDLE16)WSACancelAsyncRequest((HANDLE)hAsyncTaskHandle);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncSelect() (WINSOCK.101)(WSOCK32.101)
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,514 @@
|
|||
/* Async WINSOCK DNS services
|
||||
*
|
||||
* (C) 1993,1994,1996,1997 John Brezak, Erik Bos, Alex Korobka.
|
||||
* (C) 1999 Marcus Meissner
|
||||
*
|
||||
* NOTE: If you make any changes to fix a particular app, make sure
|
||||
* they don't break something else like Netscape or telnet and ftp
|
||||
* clients and servers (www.winsite.com got a lot of those).
|
||||
*
|
||||
* FIXME:
|
||||
* - Add WSACancel* and correct handle management. (works rather well for
|
||||
* now without it.)
|
||||
* - Verify & Check all calls for correctness
|
||||
* (currently only WSAGetHostByName*, WSAGetServByPort* calls)
|
||||
* - Check error returns.
|
||||
* - mirc/mirc32 Finger @linux.kernel.org sometimes fails in threaded mode.
|
||||
* (not sure why)
|
||||
* - This implementation did ignore the "NOTE:" section above (since the
|
||||
* whole stuff did not work anyway to other changes).
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef HAVE_SYS_FILIO_H
|
||||
# include <sys/filio.h>
|
||||
#endif
|
||||
#if defined(__svr4__)
|
||||
#include <sys/ioccom.h>
|
||||
#include <sys/sockio.h>
|
||||
#endif
|
||||
|
||||
#if defined(__EMX__)
|
||||
# include <sys/so_ioctl.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#include <sys/msg.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <sys/errno.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef HAVE_ARPA_NAMESER_H
|
||||
# include <arpa/nameser.h>
|
||||
#endif
|
||||
#ifdef HAVE_RESOLV_H
|
||||
# include <resolv.h>
|
||||
#endif
|
||||
|
||||
#include "wine/winbase16.h"
|
||||
#include "winsock.h"
|
||||
#include "winnt.h"
|
||||
#include "heap.h"
|
||||
#include "task.h"
|
||||
#include "message.h"
|
||||
#include "miscemu.h"
|
||||
#include "debug.h"
|
||||
|
||||
#pragma pack(4)
|
||||
|
||||
/* ----------------------------------- helper functions - */
|
||||
|
||||
static int list_size(char** l, int item_size)
|
||||
{
|
||||
int i,j = 0;
|
||||
if(l)
|
||||
{ for(i=0;l[i];i++)
|
||||
j += (item_size) ? item_size : strlen(l[i]) + 1;
|
||||
j += (i + 1) * sizeof(char*); }
|
||||
return j;
|
||||
}
|
||||
|
||||
static int list_dup(char** l_src, char* ref, char* base, int item_size)
|
||||
{
|
||||
/* base is either either equal to ref or 0 or SEGPTR */
|
||||
|
||||
char* p = ref;
|
||||
char** l_to = (char**)ref;
|
||||
int i,j,k;
|
||||
|
||||
for(j=0;l_src[j];j++) ;
|
||||
p += (j + 1) * sizeof(char*);
|
||||
for(i=0;i<j;i++)
|
||||
{ l_to[i] = base + (p - ref);
|
||||
k = ( item_size ) ? item_size : strlen(l_src[i]) + 1;
|
||||
memcpy(p, l_src[i], k); p += k; }
|
||||
l_to[i] = NULL;
|
||||
return (p - ref);
|
||||
}
|
||||
|
||||
/* ----- hostent */
|
||||
|
||||
static int hostent_size(struct hostent* p_he)
|
||||
{
|
||||
int size = 0;
|
||||
if( p_he )
|
||||
{ size = sizeof(struct hostent);
|
||||
size += strlen(p_he->h_name) + 1;
|
||||
size += list_size(p_he->h_aliases, 0);
|
||||
size += list_size(p_he->h_addr_list, p_he->h_length ); }
|
||||
return size;
|
||||
}
|
||||
|
||||
/* Copy hostent to p_to, fix up inside pointers using p_base (different for
|
||||
* Win16 (linear vs. segmented). Return -neededsize on overrun.
|
||||
*/
|
||||
static int WS_copy_he(struct ws_hostent *p_to,char *p_base,int t_size,struct hostent* p_he)
|
||||
{
|
||||
char* p_name,*p_aliases,*p_addr,*p;
|
||||
int size=hostent_size(p_he)+(sizeof(struct ws_hostent)-sizeof(struct hostent));
|
||||
|
||||
if (t_size < size)
|
||||
return -size;
|
||||
p = (char*)p_to;
|
||||
p += sizeof(struct ws_hostent);
|
||||
p_name = p;
|
||||
strcpy(p, p_he->h_name); p += strlen(p) + 1;
|
||||
p_aliases = p;
|
||||
p += list_dup(p_he->h_aliases, p, p_base + (p - (char*)p_to), 0);
|
||||
p_addr = p;
|
||||
list_dup(p_he->h_addr_list, p, p_base + (p - (char*)p_to), p_he->h_length);
|
||||
|
||||
p_to->h_addrtype = (INT16)p_he->h_addrtype;
|
||||
p_to->h_length = (INT16)p_he->h_length;
|
||||
p_to->h_name = (SEGPTR)(p_base + (p_name - (char*)p_to));
|
||||
p_to->h_aliases = (SEGPTR)(p_base + (p_aliases - (char*)p_to));
|
||||
p_to->h_addr_list = (SEGPTR)(p_base + (p_addr - (char*)p_to));
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
/* ----- protoent */
|
||||
|
||||
static int protoent_size(struct protoent* p_pe)
|
||||
{
|
||||
int size = 0;
|
||||
if( p_pe )
|
||||
{ size = sizeof(struct protoent);
|
||||
size += strlen(p_pe->p_name) + 1;
|
||||
size += list_size(p_pe->p_aliases, 0); }
|
||||
return size;
|
||||
}
|
||||
|
||||
/* Copy protoent to p_to, fix up inside pointers using p_base (different for
|
||||
* Win16 (linear vs. segmented). Return -neededsize on overrun.
|
||||
*/
|
||||
static int WS_copy_pe(struct ws_protoent *p_to,char *p_base,int t_size,struct protoent* p_pe)
|
||||
{
|
||||
char* p_name,*p_aliases,*p;
|
||||
int size=protoent_size(p_pe)+(sizeof(struct ws_protoent)-sizeof(struct protoent));
|
||||
|
||||
if (t_size < size)
|
||||
return -size;
|
||||
p = (char*)p_to;
|
||||
p += sizeof(struct ws_protoent);
|
||||
p_name = p;
|
||||
strcpy(p, p_pe->p_name); p += strlen(p) + 1;
|
||||
p_aliases = p;
|
||||
list_dup(p_pe->p_aliases, p, p_base + (p - (char*)p_to), 0);
|
||||
|
||||
p_to->p_proto = (INT16)p_pe->p_proto;
|
||||
p_to->p_name = (SEGPTR)(p_base) + (p_name - (char*)p_to);
|
||||
p_to->p_aliases = (SEGPTR)((p_base) + (p_aliases - (char*)p_to));
|
||||
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
/* ----- servent */
|
||||
|
||||
static int servent_size(struct servent* p_se)
|
||||
{
|
||||
int size = 0;
|
||||
if( p_se ) {
|
||||
size += sizeof(struct servent);
|
||||
size += strlen(p_se->s_proto) + strlen(p_se->s_name) + 2;
|
||||
size += list_size(p_se->s_aliases, 0);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
/* Copy servent to p_to, fix up inside pointers using p_base (different for
|
||||
* Win16 (linear vs. segmented). Return -neededsize on overrun.
|
||||
*/
|
||||
static int WS_copy_se(struct ws_servent *p_to,char *p_base,int t_size,struct servent* p_se)
|
||||
{
|
||||
char* p_name,*p_aliases,*p_proto,*p;
|
||||
int size = servent_size(p_se)+(sizeof(struct ws_servent)-sizeof(struct servent));
|
||||
|
||||
if (t_size < size )
|
||||
return -size;
|
||||
p = (char*)p_to;
|
||||
p += sizeof(struct ws_servent);
|
||||
p_name = p;
|
||||
strcpy(p, p_se->s_name); p += strlen(p) + 1;
|
||||
p_proto = p;
|
||||
strcpy(p, p_se->s_proto); p += strlen(p) + 1;
|
||||
p_aliases = p;
|
||||
list_dup(p_se->s_aliases, p, p_base + (p - (char*)p_to), 0);
|
||||
|
||||
p_to->s_port = (INT16)p_se->s_port;
|
||||
p_to->s_name = (SEGPTR)(p_base + (p_name - (char*)p_to));
|
||||
p_to->s_proto = (SEGPTR)(p_base + (p_proto - (char*)p_to));
|
||||
p_to->s_aliases = (SEGPTR)(p_base + (p_aliases - (char*)p_to));
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
static HANDLE __ws_async_handle = 0xdead;
|
||||
|
||||
/* Generic async query struct. we use symbolic names for the different queries
|
||||
* for readability.
|
||||
*/
|
||||
typedef struct _async_query {
|
||||
HWND16 hWnd;
|
||||
UINT16 uMsg;
|
||||
LPCSTR ptr1;
|
||||
#define host_name ptr1
|
||||
#define host_addr ptr1
|
||||
#define serv_name ptr1
|
||||
#define proto_name ptr1
|
||||
LPCSTR ptr2;
|
||||
#define serv_proto ptr2
|
||||
int int1;
|
||||
#define host_len int1
|
||||
#define proto_number int1
|
||||
#define serv_port int1
|
||||
int int2;
|
||||
#define host_type int2
|
||||
SEGPTR sbuf;
|
||||
INT16 sbuflen;
|
||||
|
||||
HANDLE16 async_handle;
|
||||
int flags;
|
||||
#define AQ_WIN16 0
|
||||
#define AQ_WIN32 4
|
||||
#define HB_WIN32(hb) (hb->flags & AQ_WIN32)
|
||||
#define AQ_NUMBER 0
|
||||
#define AQ_NAME 8
|
||||
|
||||
#define AQ_GETHOST 0
|
||||
#define AQ_GETPROTO 1
|
||||
#define AQ_GETSERV 2
|
||||
#define AQ_GETMASK 3
|
||||
int qt;
|
||||
} async_query;
|
||||
|
||||
/****************************************************************************
|
||||
* The async query function.
|
||||
*
|
||||
* It is either called as a thread startup routine or directly. It has
|
||||
* to free the passed arg from the process heap and PostMessageA the async
|
||||
* result or the error code.
|
||||
*
|
||||
* FIXME:
|
||||
* - errorhandling not verified.
|
||||
*/
|
||||
static DWORD WINAPI _async_queryfun(LPVOID arg) {
|
||||
async_query *aq = (async_query*)arg;
|
||||
int size = 0;
|
||||
WORD fail = 0;
|
||||
char *targetptr = (HB_WIN32(aq)?(char*)aq->sbuf:(char*)PTR_SEG_TO_LIN(aq->sbuf));
|
||||
|
||||
switch (aq->flags & AQ_GETMASK) {
|
||||
case AQ_GETHOST: {
|
||||
struct hostent *he;
|
||||
struct ws_hostent *wshe = (struct ws_hostent*)targetptr;
|
||||
|
||||
he = (aq->flags & AQ_NAME) ?
|
||||
gethostbyname(aq->host_name):
|
||||
gethostbyaddr(aq->host_addr,aq->host_len,aq->host_type);
|
||||
if (he) {
|
||||
size = WS_copy_he(wshe,(char*)aq->sbuf,aq->sbuflen,he);
|
||||
if (size < 0) {
|
||||
fail = WSAENOBUFS;
|
||||
size = -size;
|
||||
}
|
||||
} else {
|
||||
fail = WSAENOBUFS;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AQ_GETPROTO: {
|
||||
struct protoent *pe;
|
||||
struct ws_protoent *wspe = (struct ws_protoent*)targetptr;
|
||||
pe = (aq->flags & AQ_NAME)?
|
||||
getprotobyname(aq->proto_name) :
|
||||
getprotobynumber(aq->proto_number);
|
||||
if (pe) {
|
||||
size = WS_copy_pe(wspe,(char*)aq->sbuf,aq->sbuflen,pe);
|
||||
if (size < 0) {
|
||||
fail = WSAENOBUFS;
|
||||
size = -size;
|
||||
}
|
||||
} else {
|
||||
fail = WSAENOBUFS;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AQ_GETSERV: {
|
||||
struct servent *se;
|
||||
struct ws_servent *wsse = (struct ws_servent*)targetptr;
|
||||
se = (aq->flags & AQ_NAME)?
|
||||
getservbyname(aq->serv_name,aq->serv_proto) :
|
||||
getservbyport(aq->serv_port,aq->serv_proto);
|
||||
if (se) {
|
||||
size = WS_copy_se(wsse,(char*)aq->sbuf,aq->sbuflen,se);
|
||||
if (size < 0) {
|
||||
fail = WSAENOBUFS;
|
||||
size = -size;
|
||||
}
|
||||
} else {
|
||||
fail = WSAENOBUFS;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
PostMessageA(aq->hWnd,aq->uMsg,aq->async_handle,size|(fail<<16));
|
||||
HeapFree(GetProcessHeap(),0,arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* The main async help function.
|
||||
*
|
||||
* It either starts a thread or just calls the function directly for platforms
|
||||
* with no thread support. This relies on the fact that PostMessage() does
|
||||
* not actually call the windowproc before the function returns.
|
||||
*/
|
||||
static HANDLE16 __WSAsyncDBQuery(
|
||||
HWND hWnd, UINT uMsg,INT int1,LPCSTR ptr1, INT int2, LPCSTR ptr2,
|
||||
void *sbuf, INT sbuflen, UINT flags
|
||||
) {
|
||||
async_query *aq = HeapAlloc(GetProcessHeap(),0,sizeof(async_query));
|
||||
HANDLE hthread;
|
||||
|
||||
aq->hWnd = hWnd;
|
||||
aq->uMsg = uMsg;
|
||||
aq->int1 = int1;
|
||||
aq->ptr1 = ptr1;
|
||||
aq->int2 = int2;
|
||||
aq->ptr2 = ptr2;
|
||||
aq->async_handle = ++__ws_async_handle;
|
||||
aq->flags = flags;
|
||||
aq->sbuf = (SEGPTR)sbuf;
|
||||
aq->sbuflen = sbuflen;
|
||||
#if 1
|
||||
hthread = CreateThread(NULL,NULL,_async_queryfun,aq,0,NULL);
|
||||
if (hthread==INVALID_HANDLE_VALUE)
|
||||
#endif
|
||||
_async_queryfun(aq);
|
||||
return __ws_async_handle;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetHostByAddr() (WINSOCK.102)
|
||||
*/
|
||||
HANDLE16 WINAPI WSAAsyncGetHostByAddr16(HWND16 hWnd, UINT16 uMsg, LPCSTR addr,
|
||||
INT16 len, INT16 type, SEGPTR sbuf, INT16 buflen)
|
||||
{
|
||||
TRACE(winsock, "hwnd %04x, msg %04x, addr %08x[%i]\n",
|
||||
hWnd, uMsg, (unsigned)addr , len );
|
||||
return __WSAsyncDBQuery(hWnd,uMsg,len,addr,type,NULL,(void*)sbuf,buflen,AQ_NUMBER|AQ_WIN16|AQ_GETHOST);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetHostByAddr() (WSOCK32.102)
|
||||
*/
|
||||
HANDLE WINAPI WSAAsyncGetHostByAddr(HWND hWnd, UINT uMsg, LPCSTR addr,
|
||||
INT len, INT type, LPSTR sbuf, INT buflen)
|
||||
{
|
||||
TRACE(winsock, "hwnd %04x, msg %04x, addr %08x[%i]\n",
|
||||
hWnd, uMsg, (unsigned)addr , len );
|
||||
return __WSAsyncDBQuery(hWnd,uMsg,len,addr,type,NULL,sbuf,buflen,AQ_NUMBER|AQ_WIN32|AQ_GETHOST);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetHostByName() (WINSOCK.103)
|
||||
*/
|
||||
HANDLE16 WINAPI WSAAsyncGetHostByName16(HWND16 hWnd, UINT16 uMsg, LPCSTR name,
|
||||
SEGPTR sbuf, INT16 buflen)
|
||||
{
|
||||
TRACE(winsock, "hwnd %04x, msg %04x, host %s, buffer %i\n", hWnd, uMsg, (name)?name:"<null>", (int)buflen );
|
||||
|
||||
return __WSAsyncDBQuery(hWnd,uMsg,0,name,0,NULL,(void*)sbuf,buflen,AQ_NAME|AQ_WIN16|AQ_GETHOST);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetHostByName32() (WSOCK32.103)
|
||||
*/
|
||||
HANDLE WINAPI WSAAsyncGetHostByName(HWND hWnd, UINT uMsg, LPCSTR name,
|
||||
LPSTR sbuf, INT buflen)
|
||||
{
|
||||
TRACE(winsock, "hwnd %04x, msg %08x, host %s, buffer %i\n",
|
||||
(HWND16)hWnd, uMsg, (name)?name:"<null>", (int)buflen );
|
||||
return __WSAsyncDBQuery(hWnd,uMsg,0,name,0,NULL,sbuf,buflen,AQ_NAME|AQ_WIN32|AQ_GETHOST);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetProtoByName() (WINSOCK.105)
|
||||
*/
|
||||
HANDLE16 WINAPI WSAAsyncGetProtoByName16(HWND16 hWnd, UINT16 uMsg, LPCSTR name,
|
||||
SEGPTR sbuf, INT16 buflen)
|
||||
{
|
||||
TRACE(winsock, "hwnd %04x, msg %08x, protocol %s\n",
|
||||
(HWND16)hWnd, uMsg, (name)?name:"<null>" );
|
||||
return __WSAsyncDBQuery(hWnd,uMsg,0,name,0,NULL,(void*)sbuf,buflen,AQ_GETPROTO|AQ_NAME|AQ_WIN16);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetProtoByName() (WSOCK32.105)
|
||||
*/
|
||||
HANDLE WINAPI WSAAsyncGetProtoByName(HWND hWnd, UINT uMsg, LPCSTR name,
|
||||
LPSTR sbuf, INT buflen)
|
||||
{
|
||||
TRACE(winsock, "hwnd %04x, msg %08x, protocol %s\n",
|
||||
(HWND16)hWnd, uMsg, (name)?name:"<null>" );
|
||||
return __WSAsyncDBQuery(hWnd,uMsg,0,name,0,NULL,sbuf,buflen,AQ_GETPROTO|AQ_NAME|AQ_WIN32);
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetProtoByNumber() (WINSOCK.104)
|
||||
*/
|
||||
HANDLE16 WINAPI WSAAsyncGetProtoByNumber16(HWND16 hWnd,UINT16 uMsg,INT16 number,
|
||||
SEGPTR sbuf, INT16 buflen)
|
||||
{
|
||||
TRACE(winsock, "hwnd %04x, msg %04x, num %i\n", hWnd, uMsg, number );
|
||||
return __WSAsyncDBQuery(hWnd,uMsg,number,NULL,0,NULL,(void*)sbuf,buflen,AQ_GETPROTO|AQ_NUMBER|AQ_WIN16);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetProtoByNumber() (WSOCK32.104)
|
||||
*/
|
||||
HANDLE WINAPI WSAAsyncGetProtoByNumber(HWND hWnd, UINT uMsg, INT number,
|
||||
LPSTR sbuf, INT buflen)
|
||||
{
|
||||
TRACE(winsock, "hwnd %04x, msg %04x, num %i\n", hWnd, uMsg, number );
|
||||
|
||||
return __WSAsyncDBQuery(hWnd,uMsg,number,NULL,0,NULL,sbuf,buflen,AQ_GETPROTO|AQ_NUMBER|AQ_WIN32);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetServByName() (WINSOCK.107)
|
||||
*/
|
||||
HANDLE16 WINAPI WSAAsyncGetServByName16(HWND16 hWnd, UINT16 uMsg, LPCSTR name,
|
||||
LPCSTR proto, SEGPTR sbuf, INT16 buflen)
|
||||
{
|
||||
TRACE(winsock, "hwnd %04x, msg %04x, name %s, proto %s\n",
|
||||
hWnd, uMsg, (name)?name:"<null>", (proto)?proto:"<null>" );
|
||||
|
||||
return __WSAsyncDBQuery(hWnd,uMsg,0,name,0,proto,(void*)sbuf,buflen,AQ_GETSERV|AQ_NAME|AQ_WIN16);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetServByName() (WSOCK32.107)
|
||||
*/
|
||||
HANDLE WINAPI WSAAsyncGetServByName(HWND hWnd, UINT uMsg, LPCSTR name,
|
||||
LPCSTR proto, LPSTR sbuf, INT buflen)
|
||||
{
|
||||
TRACE(winsock, "hwnd %04x, msg %04x, name %s, proto %s\n",
|
||||
hWnd, uMsg, (name)?name:"<null>", (proto)?proto:"<null>" );
|
||||
return __WSAsyncDBQuery(hWnd,uMsg,0,name,0,proto,sbuf,buflen,AQ_GETSERV|AQ_NAME|AQ_WIN32);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetServByPort() (WINSOCK.106)
|
||||
*/
|
||||
HANDLE16 WINAPI WSAAsyncGetServByPort16(HWND16 hWnd, UINT16 uMsg, INT16 port,
|
||||
LPCSTR proto, SEGPTR sbuf, INT16 buflen)
|
||||
{
|
||||
TRACE(winsock, "hwnd %04x, msg %04x, port %i, proto %s\n",
|
||||
hWnd, uMsg, port, (proto)?proto:"<null>" );
|
||||
return __WSAsyncDBQuery(hWnd,uMsg,port,NULL,0,proto,(void*)sbuf,buflen,AQ_GETSERV|AQ_NUMBER|AQ_WIN16);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* WSAAsyncGetServByPort() (WSOCK32.106)
|
||||
*/
|
||||
HANDLE WINAPI WSAAsyncGetServByPort(HWND hWnd, UINT uMsg, INT port,
|
||||
LPCSTR proto, LPSTR sbuf, INT buflen)
|
||||
{
|
||||
TRACE(winsock, "hwnd %04x, msg %04x, port %i, proto %s\n",
|
||||
hWnd, uMsg, port, (proto)?proto:"<null>" );
|
||||
return __WSAsyncDBQuery(hWnd,uMsg,port,NULL,0,proto,sbuf,buflen,AQ_GETSERV|AQ_NUMBER|AQ_WIN32);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* WSACancelAsyncRequest() (WINSOCK.108)(WSOCK32.109)
|
||||
*/
|
||||
INT WINAPI WSACancelAsyncRequest(HANDLE hAsyncTaskHandle)
|
||||
{
|
||||
FIXME(winsock, "(%08x),stub\n", hAsyncTaskHandle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
INT16 WINAPI WSACancelAsyncRequest16(HANDLE16 hAsyncTaskHandle)
|
||||
{
|
||||
return (HANDLE16)WSACancelAsyncRequest((HANDLE)hAsyncTaskHandle);
|
||||
}
|
|
@ -1,539 +0,0 @@
|
|||
/*
|
||||
* asynchronous DNS services
|
||||
*
|
||||
* (C) 1996,1997 Alex Korobka.
|
||||
*
|
||||
* TODO: Fork dns lookup helper during the startup (with a pipe
|
||||
* for communication) and make it fork for a database request
|
||||
* instead of forking the main process (i.e. something like
|
||||
* Netscape 4.0).
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/msg.h>
|
||||
#include <sys/wait.h>
|
||||
#include <errno.h>
|
||||
#ifdef __EMX__
|
||||
# include <sys/so_ioctl.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_FILIO_H
|
||||
# include <sys/filio.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_FILE_H
|
||||
# include <sys/file.h>
|
||||
#endif
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#ifdef HAVE_ARPA_NAMESER_H
|
||||
# include <arpa/nameser.h>
|
||||
#endif
|
||||
#ifdef HAVE_RESOLV_H
|
||||
# include <resolv.h>
|
||||
#endif
|
||||
|
||||
#include "wine/winuser16.h"
|
||||
#include "winsock.h"
|
||||
#include "heap.h"
|
||||
#include "ldt.h"
|
||||
#include "message.h"
|
||||
#include "miscemu.h"
|
||||
#include "async.h"
|
||||
#include "debug.h"
|
||||
|
||||
static void WINSOCK_async_handler(int unixfd,void *private);
|
||||
|
||||
/* async DNS op control struct */
|
||||
typedef struct
|
||||
{
|
||||
ws_async_op* ws_aop;
|
||||
char* buffer;
|
||||
int type;
|
||||
union
|
||||
{
|
||||
char* init;
|
||||
char* name;
|
||||
char* addr;
|
||||
} rq;
|
||||
unsigned ilength;
|
||||
} ws_async_ctl;
|
||||
|
||||
extern HANDLE16 __ws_gethandle( void* ptr );
|
||||
extern void* __ws_memalloc( int size );
|
||||
extern void __ws_memfree( void* ptr );
|
||||
|
||||
/* NOTE: ws_async_op list is traversed inside the SIGIO handler! */
|
||||
static ws_async_op* __async_op_list = NULL;
|
||||
|
||||
static void fixup_wshe(struct ws_hostent* p_wshe, void* base);
|
||||
static void fixup_wspe(struct ws_protoent* p_wspe, void* base);
|
||||
static void fixup_wsse(struct ws_servent* p_wsse, void* base);
|
||||
|
||||
/* ----------------------------------- async/non-blocking I/O */
|
||||
|
||||
int WINSOCK_unblock_io(int fd, int noblock)
|
||||
{
|
||||
int fd_flags;
|
||||
|
||||
fd_flags = fcntl(fd, F_GETFL, 0);
|
||||
if (fcntl(fd, F_SETFL, (noblock)? fd_flags | O_NONBLOCK
|
||||
: fd_flags & ~O_NONBLOCK ) != -1) return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int WINSOCK_check_async_op(ws_async_op* p_aop)
|
||||
{
|
||||
ws_async_op* p = __async_op_list;
|
||||
while( p ) if( p == p_aop ) return 1;
|
||||
else p = p->next;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WINSOCK_cancel_async_op(ws_async_op* p_aop)
|
||||
{
|
||||
/* SIGIO unsafe! */
|
||||
|
||||
if( WINSOCK_check_async_op(p_aop) )
|
||||
{
|
||||
if( !(p_aop->flags & WSMSG_DEAD_AOP) )
|
||||
{
|
||||
kill(p_aop->pid, SIGKILL);
|
||||
waitpid(p_aop->pid, NULL, 0); /* just in case */
|
||||
close(p_aop->fd[0]);
|
||||
}
|
||||
WINSOCK_unlink_async_op(p_aop);
|
||||
EVENT_DeleteIO( p_aop->fd[0], EVENT_IO_READ );
|
||||
p_aop->flags = 0;
|
||||
p_aop->hWnd = p_aop->uMsg = 0;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void WINSOCK_cancel_task_aops(HTASK16 hTask, void (*__opfree)(void*))
|
||||
{
|
||||
/* SIGIO safe, hTask == 0 cancels all outstanding async ops */
|
||||
|
||||
int num = 0, num_dead = 0;
|
||||
ws_async_op* p, *next;
|
||||
|
||||
TRACE(winsock," cancelling async DNS requests... \n");
|
||||
|
||||
SIGNAL_MaskAsyncEvents( TRUE );
|
||||
next = __async_op_list;
|
||||
while( (p = next) )
|
||||
{
|
||||
HTASK16 hWndTask = GetWindowTask16(p->hWnd);
|
||||
|
||||
next = p->next;
|
||||
if(!hTask || !hWndTask || (hTask == hWndTask))
|
||||
{
|
||||
num++;
|
||||
if( p->flags & WSMSG_DEAD_AOP )
|
||||
num_dead++;
|
||||
|
||||
WINSOCK_cancel_async_op(p);
|
||||
if( __opfree ) __opfree(p);
|
||||
}
|
||||
}
|
||||
SIGNAL_MaskAsyncEvents( FALSE );
|
||||
TRACE(winsock," -> %i total (%i active)\n", num, num - num_dead );
|
||||
}
|
||||
|
||||
void WINSOCK_link_async_op(ws_async_op* p_aop)
|
||||
{
|
||||
/* SIGIO safe */
|
||||
|
||||
p_aop->prev = NULL;
|
||||
SIGNAL_MaskAsyncEvents( TRUE );
|
||||
if( __async_op_list )
|
||||
{
|
||||
ws_async_op* p = __async_op_list;
|
||||
__async_op_list->prev = p_aop;
|
||||
|
||||
/* traverse the list and retire dead ops created
|
||||
* by the signal handler (see below). */
|
||||
|
||||
while( p )
|
||||
{
|
||||
if( p->flags & WSMSG_DEAD_AOP )
|
||||
{
|
||||
ws_async_op* dead = p;
|
||||
|
||||
TRACE(winsock,"\treaping dead aop [%08x]\n", (unsigned)p );
|
||||
|
||||
p = p->next;
|
||||
WINSOCK_unlink_async_op( dead );
|
||||
__ws_memfree( dead );
|
||||
continue;
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
p_aop->next = __async_op_list;
|
||||
__async_op_list = p_aop;
|
||||
|
||||
SIGNAL_MaskAsyncEvents( FALSE );
|
||||
|
||||
ASYNC_RegisterFD(p_aop->fd[0],WINSOCK_async_handler,p_aop);
|
||||
}
|
||||
|
||||
void WINSOCK_unlink_async_op(ws_async_op* p_aop)
|
||||
{
|
||||
/* SIGIO unsafe! */
|
||||
|
||||
if( p_aop == __async_op_list ) __async_op_list = p_aop->next;
|
||||
else
|
||||
p_aop->prev->next = p_aop->next;
|
||||
if( p_aop->next ) p_aop->next->prev = p_aop->prev;
|
||||
|
||||
ASYNC_UnregisterFD(p_aop->fd[0],WINSOCK_async_handler);
|
||||
}
|
||||
|
||||
/* ----------------------------------- SIGIO handler -
|
||||
*
|
||||
* link_async_op/unlink_async_op allow to install generic
|
||||
* async IO handlers (provided that aop_control function is defined).
|
||||
*
|
||||
* Note: pipe-based handlers must raise explicit SIGIO with kill(2).
|
||||
*/
|
||||
|
||||
static void WINSOCK_async_handler(int unixfd,void *private)
|
||||
{
|
||||
ws_async_op* p_aop = (ws_async_op*)private;
|
||||
|
||||
if( p_aop->aop_control(p_aop, AOP_IO) == AOP_CONTROL_REMOVE )
|
||||
{
|
||||
/* NOTE: memory management is signal-unsafe, therefore
|
||||
* we can only set a flag to remove this p_aop later on.
|
||||
*/
|
||||
p_aop->flags = WSMSG_DEAD_AOP;
|
||||
close(p_aop->fd[0]);
|
||||
if( p_aop->pid )
|
||||
{
|
||||
kill(p_aop->pid, SIGKILL);
|
||||
waitpid(p_aop->pid, NULL, WNOHANG);
|
||||
p_aop->pid = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------- getXbyY requests */
|
||||
|
||||
/* child process control struct */
|
||||
static ws_async_ctl async_ctl;
|
||||
|
||||
static int aop_control(ws_async_op* p_aop, int flag )
|
||||
{
|
||||
unsigned lLength;
|
||||
|
||||
/* success: LOWORD(lLength) has the length of the struct
|
||||
* to read.
|
||||
* failure: LOWORD(lLength) is zero, HIWORD(lLength) contains
|
||||
* the error code.
|
||||
*/
|
||||
|
||||
read(p_aop->fd[0], &lLength, sizeof(unsigned));
|
||||
if( LOWORD(lLength) )
|
||||
{
|
||||
if( (int)LOWORD(lLength) <= p_aop->buflen )
|
||||
{
|
||||
char* buffer = (p_aop->flags & WSMSG_WIN32_AOP)
|
||||
? p_aop->b.lin_base : (char*)PTR_SEG_TO_LIN(p_aop->b.seg_base);
|
||||
|
||||
read(p_aop->fd[0], buffer, LOWORD(lLength));
|
||||
switch( p_aop->flags & WSMSG_ASYNC_RQMASK )
|
||||
{
|
||||
case WSMSG_ASYNC_HOSTBYNAME:
|
||||
case WSMSG_ASYNC_HOSTBYADDR:
|
||||
fixup_wshe((struct ws_hostent*)buffer, p_aop->b.ptr_base); break;
|
||||
case WSMSG_ASYNC_PROTOBYNAME:
|
||||
case WSMSG_ASYNC_PROTOBYNUM:
|
||||
fixup_wspe((struct ws_protoent*)buffer, p_aop->b.ptr_base); break;
|
||||
case WSMSG_ASYNC_SERVBYNAME:
|
||||
case WSMSG_ASYNC_SERVBYPORT:
|
||||
fixup_wsse((struct ws_servent*)buffer, p_aop->b.ptr_base); break;
|
||||
default:
|
||||
if( p_aop->flags ) WARN(winsock,"Received unknown async request!\n");
|
||||
return AOP_CONTROL_REMOVE;
|
||||
}
|
||||
}
|
||||
else lLength = ((UINT)LOWORD(lLength)) | ((unsigned)WSAENOBUFS << 16);
|
||||
} /* failure */
|
||||
|
||||
/* was a __WS_ASYNC_DEBUG statement */
|
||||
TRACE(winsock, "DNS aop completed: hWnd [%04x], uMsg [%04x], "
|
||||
"aop [%04x], event [%08lx]\n",
|
||||
p_aop->hWnd, p_aop->uMsg, __ws_gethandle(p_aop), (LPARAM)lLength);
|
||||
|
||||
/* FIXME: update num_async_rq */
|
||||
EVENT_DeleteIO( p_aop->fd[0], EVENT_IO_READ );
|
||||
PostMessageA( p_aop->hWnd, p_aop->uMsg, __ws_gethandle(p_aop), (LPARAM)lLength );
|
||||
|
||||
return AOP_CONTROL_REMOVE; /* one-shot request */
|
||||
}
|
||||
|
||||
|
||||
HANDLE16 __WSAsyncDBQuery(LPWSINFO pwsi, HWND hWnd, UINT uMsg, INT type,
|
||||
LPCSTR init, INT len, LPCSTR proto, void* sbuf, INT buflen, UINT flag)
|
||||
{
|
||||
/* queue 'flag' request and fork off its handler */
|
||||
|
||||
async_ctl.ws_aop = (ws_async_op*)__ws_memalloc(sizeof(ws_async_op));
|
||||
|
||||
if( async_ctl.ws_aop )
|
||||
{
|
||||
HANDLE16 handle = __ws_gethandle(async_ctl.ws_aop);
|
||||
|
||||
if( pipe(async_ctl.ws_aop->fd) == 0 )
|
||||
{
|
||||
async_ctl.rq.init = (char*)init;
|
||||
async_ctl.ilength = len;
|
||||
async_ctl.buffer = (char*)proto;
|
||||
async_ctl.type = type;
|
||||
|
||||
async_ctl.ws_aop->hWnd = hWnd;
|
||||
async_ctl.ws_aop->uMsg = uMsg;
|
||||
async_ctl.ws_aop->b.ptr_base = sbuf;
|
||||
async_ctl.ws_aop->buflen = buflen;
|
||||
async_ctl.ws_aop->flags = flag;
|
||||
async_ctl.ws_aop->aop_control = &aop_control;
|
||||
|
||||
WINSOCK_link_async_op( async_ctl.ws_aop );
|
||||
|
||||
EVENT_AddIO( async_ctl.ws_aop->fd[0], EVENT_IO_READ );
|
||||
pwsi->num_async_rq++;
|
||||
|
||||
async_ctl.ws_aop->pid = fork();
|
||||
if( async_ctl.ws_aop->pid )
|
||||
{
|
||||
TRACE(winsock, "\tasync_op = %04x (child %i)\n",
|
||||
handle, async_ctl.ws_aop->pid);
|
||||
|
||||
close(async_ctl.ws_aop->fd[1]); /* write endpoint */
|
||||
if( async_ctl.ws_aop->pid > 0 )
|
||||
return __ws_gethandle(async_ctl.ws_aop);
|
||||
|
||||
/* fork() failed */
|
||||
|
||||
pwsi->num_async_rq--;
|
||||
EVENT_DeleteIO( async_ctl.ws_aop->fd[0], EVENT_IO_READ );
|
||||
close(async_ctl.ws_aop->fd[0]);
|
||||
pwsi->err = WSAEWOULDBLOCK;
|
||||
}
|
||||
else
|
||||
{
|
||||
extern BOOL THREAD_InitDone;
|
||||
|
||||
THREAD_InitDone = FALSE;
|
||||
/* child process */
|
||||
|
||||
close(async_ctl.ws_aop->fd[0]); /* read endpoint */
|
||||
switch( flag & WSMSG_ASYNC_RQMASK )
|
||||
{
|
||||
case WSMSG_ASYNC_HOSTBYADDR:
|
||||
case WSMSG_ASYNC_HOSTBYNAME:
|
||||
WS_do_async_gethost(pwsi, flag);
|
||||
break;
|
||||
case WSMSG_ASYNC_PROTOBYNUM:
|
||||
case WSMSG_ASYNC_PROTOBYNAME:
|
||||
WS_do_async_getproto(pwsi, flag);
|
||||
break;
|
||||
case WSMSG_ASYNC_SERVBYPORT:
|
||||
case WSMSG_ASYNC_SERVBYNAME:
|
||||
WS_do_async_getserv(pwsi, flag);
|
||||
break;
|
||||
}
|
||||
_exit(0); /* skip atexit()'ed cleanup */
|
||||
}
|
||||
}
|
||||
else pwsi->err = wsaErrno(); /* failed to create pipe */
|
||||
|
||||
__ws_memfree((void*)async_ctl.ws_aop);
|
||||
} else pwsi->err = WSAEWOULDBLOCK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _async_notify()
|
||||
{
|
||||
/* use half-duplex pipe to send variable length packets
|
||||
* to the parent process */
|
||||
|
||||
write(async_ctl.ws_aop->fd[1], &async_ctl.ilength, sizeof(unsigned));
|
||||
write(async_ctl.ws_aop->fd[1], async_ctl.buffer, async_ctl.ilength );
|
||||
|
||||
#ifndef __EMX__
|
||||
kill(getppid(), SIGIO); /* simulate async I/O */
|
||||
#endif
|
||||
|
||||
/* was a __WS_ASYNC_DEBUG statement */
|
||||
TRACE(winsock, "handler - notify aop [%d, buf %d]\n",
|
||||
async_ctl.ilength, async_ctl.ws_aop->buflen);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void _async_fail()
|
||||
{
|
||||
/* write a DWORD with error code (low word is zero) */
|
||||
|
||||
async_ctl.ilength =
|
||||
(h_errno < 0) ? (unsigned)WSAMAKEASYNCREPLY( 0, wsaErrno() )
|
||||
: (unsigned)WSAMAKEASYNCREPLY( 0, wsaHerrno() );
|
||||
write(async_ctl.ws_aop->fd[1], &async_ctl.ilength, sizeof(unsigned) );
|
||||
#ifndef __EMX__
|
||||
kill(getppid(), SIGIO); /* simulate async I/O */
|
||||
#endif
|
||||
|
||||
/* was a __WS_ASYNC_DEBUG statement */
|
||||
TRACE(winsock, "handler - failed aop [%d, buf %d]\n",
|
||||
async_ctl.ilength, async_ctl.ws_aop->buflen);
|
||||
}
|
||||
|
||||
void dump_ws_hostent_offset(struct ws_hostent* wshe)
|
||||
{
|
||||
int i;
|
||||
char* base = (char*)wshe;
|
||||
unsigned* ptr;
|
||||
|
||||
DUMP("h_name = %08x\t[%s]\n",
|
||||
(unsigned)wshe->h_name, base + (unsigned)wshe->h_name);
|
||||
DUMP("h_aliases = %08x\t[%08x]\n",
|
||||
(unsigned)wshe->h_aliases, (unsigned)(base+(unsigned)wshe->h_aliases));
|
||||
ptr = (unsigned*)(base + (unsigned)wshe->h_aliases);
|
||||
for(i = 0; ptr[i]; i++ )
|
||||
{
|
||||
DUMP("%i - %08x [%s]\n", i + 1, ptr[i], ((char*)base) + ptr[i]);
|
||||
}
|
||||
DUMP("h_length = %i\n", wshe->h_length);
|
||||
}
|
||||
|
||||
void WS_do_async_gethost(LPWSINFO pwsi, unsigned flag )
|
||||
{
|
||||
int size = 0;
|
||||
struct hostent* p_he;
|
||||
|
||||
close(async_ctl.ws_aop->fd[0]);
|
||||
|
||||
p_he = (flag & WSMSG_ASYNC_HOSTBYNAME)
|
||||
? gethostbyname(async_ctl.rq.name)
|
||||
: gethostbyaddr(async_ctl.rq.name,
|
||||
async_ctl.ilength, async_ctl.type);
|
||||
|
||||
TRACE(winsock,"DNS: got hostent for [%s]\n", async_ctl.rq.name );
|
||||
|
||||
if( p_he ) /* convert to the Winsock format with internal pointers as offsets */
|
||||
size = WS_dup_he(pwsi, p_he, WS_DUP_OFFSET |
|
||||
((flag & WSMSG_WIN32_AOP) ? WS_DUP_LINEAR : WS_DUP_SEGPTR) );
|
||||
if( size )
|
||||
{
|
||||
async_ctl.buffer = (char*)pwsi->he;
|
||||
async_ctl.ilength = (unsigned)WSAMAKEASYNCREPLY( (UINT16)size, 0 );
|
||||
_async_notify( flag );
|
||||
}
|
||||
else _async_fail();
|
||||
}
|
||||
|
||||
void WS_do_async_getproto(LPWSINFO pwsi, unsigned flag )
|
||||
{
|
||||
int size = 0;
|
||||
struct protoent* p_pe;
|
||||
|
||||
close(async_ctl.ws_aop->fd[0]);
|
||||
p_pe = (flag & WSMSG_ASYNC_PROTOBYNAME)
|
||||
? getprotobyname(async_ctl.rq.name)
|
||||
: getprotobynumber(async_ctl.type);
|
||||
|
||||
TRACE(winsock,"DNS: got protoent for [%s]\n", async_ctl.rq.name );
|
||||
|
||||
if( p_pe ) /* convert to the Winsock format with internal pointers as offsets */
|
||||
size = WS_dup_pe(pwsi, p_pe, WS_DUP_OFFSET |
|
||||
((flag & WSMSG_WIN32_AOP) ? WS_DUP_LINEAR : WS_DUP_SEGPTR) );
|
||||
if( size )
|
||||
{
|
||||
async_ctl.buffer = (char*)pwsi->pe;
|
||||
async_ctl.ilength = (unsigned)WSAMAKEASYNCREPLY( (UINT16)size, 0 );
|
||||
_async_notify( flag );
|
||||
}
|
||||
else _async_fail();
|
||||
}
|
||||
|
||||
void WS_do_async_getserv(LPWSINFO pwsi, unsigned flag )
|
||||
{
|
||||
int size = 0;
|
||||
struct servent* p_se;
|
||||
|
||||
close(async_ctl.ws_aop->fd[0]);
|
||||
p_se = (flag & WSMSG_ASYNC_SERVBYNAME)
|
||||
? getservbyname(async_ctl.rq.name, async_ctl.buffer)
|
||||
: getservbyport(async_ctl.type, async_ctl.buffer);
|
||||
|
||||
if( p_se ) /* convert to the Winsock format with internal pointers as offsets */
|
||||
size = WS_dup_se(pwsi, p_se, WS_DUP_OFFSET |
|
||||
((flag & WSMSG_WIN32_AOP) ? WS_DUP_LINEAR : WS_DUP_SEGPTR) );
|
||||
if( size )
|
||||
{
|
||||
async_ctl.buffer = (char*)pwsi->se;
|
||||
async_ctl.ilength = (unsigned)WSAMAKEASYNCREPLY( (UINT16)size, 0 );
|
||||
_async_notify( flag );
|
||||
}
|
||||
else _async_fail();
|
||||
}
|
||||
|
||||
/* ----------------------------------- helper functions -
|
||||
*
|
||||
* Raw results from the pipe contain internal pointers stored as
|
||||
* offsets relative to the beginning of the buffer and we need
|
||||
* to apply a fixup before passing them to applications.
|
||||
*
|
||||
* NOTE: It is possible to exploit the fact that fork() doesn't
|
||||
* change the buffer address by storing fixed up pointers right
|
||||
* in the handler. However, this will get in the way if we ever
|
||||
* get around to implementing DNS helper daemon a-la Netscape 4.x.
|
||||
*/
|
||||
|
||||
void fixup_wshe(struct ws_hostent* p_wshe, void* base)
|
||||
{
|
||||
/* add 'base' to ws_hostent pointers to convert them from offsets */
|
||||
|
||||
int i;
|
||||
unsigned* p_aliases,*p_addr;
|
||||
|
||||
p_aliases = (unsigned*)((char*)p_wshe + (unsigned)p_wshe->h_aliases);
|
||||
p_addr = (unsigned*)((char*)p_wshe + (unsigned)p_wshe->h_addr_list);
|
||||
((unsigned)(p_wshe->h_name)) += (unsigned)base;
|
||||
((unsigned)(p_wshe->h_aliases)) += (unsigned)base;
|
||||
((unsigned)(p_wshe->h_addr_list)) += (unsigned)base;
|
||||
for(i=0;p_aliases[i];i++) p_aliases[i] += (unsigned)base;
|
||||
for(i=0;p_addr[i];i++) p_addr[i] += (unsigned)base;
|
||||
}
|
||||
|
||||
void fixup_wspe(struct ws_protoent* p_wspe, void* base)
|
||||
{
|
||||
int i;
|
||||
unsigned* p_aliases = (unsigned*)((char*)p_wspe + (unsigned)p_wspe->p_aliases);
|
||||
((unsigned)(p_wspe->p_name)) += (unsigned)base;
|
||||
((unsigned)(p_wspe->p_aliases)) += (unsigned)base;
|
||||
for(i=0;p_aliases[i];i++) p_aliases[i] += (unsigned)base;
|
||||
}
|
||||
|
||||
void fixup_wsse(struct ws_servent* p_wsse, void* base)
|
||||
{
|
||||
int i;
|
||||
unsigned* p_aliases = (unsigned*)((char*)p_wsse + (unsigned)p_wsse->s_aliases);
|
||||
((unsigned)(p_wsse->s_name)) += (unsigned)base;
|
||||
((p_wsse->s_proto)) += (unsigned)base;
|
||||
((p_wsse->s_aliases)) += (unsigned)base;
|
||||
for(i=0;p_aliases[i];i++) p_aliases[i] += (unsigned)base;
|
||||
}
|
Loading…
Reference in New Issue