1 | /* $Id: asyncthread.h,v 1.14 2003-01-06 13:05:40 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Async thread help functions
|
---|
5 | *
|
---|
6 | * Copyright 2000 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | *
|
---|
8 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
9 | */
|
---|
10 | #ifndef __ASYNCTHREAD_H__
|
---|
11 | #define __ASYNCTHREAD_H__
|
---|
12 |
|
---|
13 | #include <vmutex.h>
|
---|
14 | #include "vsemaphore.h"
|
---|
15 |
|
---|
16 | #define ASYNCCNV _Optlink
|
---|
17 |
|
---|
18 | typedef void (* ASYNCCNV ASYNCTHREADPROC)(void *);
|
---|
19 |
|
---|
20 | enum AsyncRequestType {
|
---|
21 | ASYNC_GETHOSTBYNAME,
|
---|
22 | ASYNC_GETHOSTBYADDR,
|
---|
23 | ASYNC_GETPROTOBYNAME,
|
---|
24 | ASYNC_GETPROTOBYNUMBER,
|
---|
25 | ASYNC_GETSERVBYNAME,
|
---|
26 | ASYNC_GETSERVBYPORT,
|
---|
27 | ASYNC_SELECT
|
---|
28 | } ;
|
---|
29 |
|
---|
30 | typedef struct _ASYNCTHREADPARM
|
---|
31 | {
|
---|
32 | BOOL fActive;
|
---|
33 | BOOL fCancelled;
|
---|
34 | BOOL fConnected;
|
---|
35 | BOOL fWaitSelect;
|
---|
36 | BOOL fRemoved; //async select
|
---|
37 | AsyncRequestType request;
|
---|
38 | LHANDLE hAsyncTaskHandle;
|
---|
39 | HANDLE hThread; //handle of thread that started the async request
|
---|
40 | ASYNCTHREADPROC asyncProc;
|
---|
41 | VMutex *parmmutex;
|
---|
42 | DWORD notifyHandle;
|
---|
43 | DWORD notifyData;
|
---|
44 | LPSTR buf;
|
---|
45 | DWORD buflen;
|
---|
46 | union {
|
---|
47 | struct {
|
---|
48 | LPSTR name;
|
---|
49 | } gethostbyname;
|
---|
50 | struct {
|
---|
51 | LPSTR addr;
|
---|
52 | int len;
|
---|
53 | int type;
|
---|
54 | } gethostbyaddr;
|
---|
55 | struct {
|
---|
56 | LPSTR name;
|
---|
57 | } getprotobyname;
|
---|
58 | struct {
|
---|
59 | int number;
|
---|
60 | } getprotobynumber;
|
---|
61 | struct {
|
---|
62 | LPSTR name;
|
---|
63 | LPSTR proto;
|
---|
64 | } getservbyname;
|
---|
65 | struct {
|
---|
66 | int port;
|
---|
67 | LPSTR proto;
|
---|
68 | } getservbyport;
|
---|
69 | struct {
|
---|
70 | VSemaphore *asyncSem;
|
---|
71 | DWORD lEvents;
|
---|
72 | DWORD lEventsPending;
|
---|
73 | SOCKET s;
|
---|
74 | int mode;
|
---|
75 | // event bits to signal which event has occured
|
---|
76 | DWORD lLastEvent;
|
---|
77 | // error codes for all events
|
---|
78 | int iErrorCode[FD_MAX_EVENTS];
|
---|
79 | } asyncselect;
|
---|
80 | } u;
|
---|
81 | _ASYNCTHREADPARM *next;
|
---|
82 | } ASYNCTHREADPARM, *PASYNCTHREADPARM;
|
---|
83 |
|
---|
84 | extern VMutex asyncThreadMutex;
|
---|
85 | PASYNCTHREADPARM FindAsyncEvent(SOCKET s);
|
---|
86 |
|
---|
87 | ULONG QueueAsyncJob(ASYNCTHREADPROC asyncproc, PASYNCTHREADPARM pThreadParm, BOOL fSetBlocking = FALSE);
|
---|
88 | void RemoveFromQueue(PASYNCTHREADPARM pThreadParm);
|
---|
89 |
|
---|
90 | void EnableAsyncEvent(SOCKET s, ULONG flags);
|
---|
91 | BOOL QueryAsyncEvent(SOCKET s, int *pMode, ULONG *pNofityHandle, ULONG *pNofityData, ULONG *plEvent);
|
---|
92 | BOOL FindAndSetAsyncEvent(SOCKET s, int mode, int notifyHandle, int notifyData, ULONG lEventMask);
|
---|
93 |
|
---|
94 | void WSACancelAllAsyncRequests();
|
---|
95 | void WSAWaitForAllAsyncRequests();
|
---|
96 |
|
---|
97 | #endif //__ASYNCTHREAD_H__
|
---|