Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /branches/ttcomtester/teraterm/teraterm/WSAAsyncGetAddrInfo.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4165 - (hide annotations) (download) (as text)
Wed Nov 24 11:35:04 2010 UTC (13 years, 4 months ago) by doda
Original Path: trunk/teraterm/teraterm/WSAAsyncGetAddrInfo.c
File MIME type: text/x-csrc
File size: 2333 byte(s)
freeaddrinfoをTTXでフック出来るようにした。

1 maya 3227 /*
2     * WSAAsyncGetAddrInfo.c -- asynchronous version of getaddrinfo
3     * Copyright(C) 2000-2003 Jun-ya Kato <kato@win6.jp>
4     */
5     #include <winsock2.h>
6     #include <ws2tcpip.h>
7     #include <windows.h>
8     #include <process.h>
9     #include "WSAASyncGetAddrInfo.h"
10 doda 4165 #include "ttwsk.h"
11 maya 3227
12     static unsigned __stdcall getaddrinfo_thread(void FAR * p);
13    
14 doda 4163 HANDLE FAR PASCAL WSAAsyncGetAddrInfo(HWND hWnd, unsigned int wMsg,
15 maya 3227 const char FAR * hostname,
16     const char FAR * portname,
17     struct addrinfo FAR * hints,
18     struct addrinfo FAR * FAR * res)
19     {
20     HANDLE thread;
21     unsigned tid;
22     struct getaddrinfo_args FAR * ga;
23    
24     /*
25     * allocate structure to pass args to sub-thread dynamically
26     * WSAAsyncGetAddrInfo() is reentrant
27     */
28     if ((ga = (struct getaddrinfo_args FAR *)malloc(sizeof(struct getaddrinfo_args))) == NULL)
29     return NULL;
30    
31     /* packing arguments struct addrinfo_args */
32     ga->hWnd = hWnd;
33     ga->wMsg = wMsg;
34     ga->hostname = hostname;
35     ga->portname = portname;
36     ga->hints = hints;
37     ga->res = res;
38    
39     ga->lpHandle = (HANDLE FAR *)malloc(sizeof(HANDLE));
40     if (ga->lpHandle == NULL)
41     return NULL;
42    
43     /* create sub-thread running getaddrinfo() */
44     thread = (HANDLE)_beginthreadex(NULL, 0, getaddrinfo_thread, ga, CREATE_SUSPENDED, &tid);
45     *ga->lpHandle = (HANDLE)thread;
46     ResumeThread(thread);
47    
48     /* return thread handle */
49     if (thread == 0) {
50     free(ga->lpHandle);
51     free(ga);
52     return NULL;
53     } else
54     return (HANDLE)thread;
55     }
56    
57     static unsigned __stdcall getaddrinfo_thread(void FAR * p)
58     {
59     int gai;
60     HWND hWnd;
61     unsigned int wMsg;
62     const char FAR * hostname;
63     const char FAR * portname;
64     struct addrinfo FAR * hints;
65     struct addrinfo FAR * FAR * res;
66     struct getaddrinfo_args FAR * ga;
67    
68     /* unpacking arguments */
69     ga = (struct getaddrinfo_args FAR *)p;
70     hWnd = ga->hWnd;
71     wMsg = ga->wMsg;
72     hostname = ga->hostname;
73     portname = ga->portname;
74     hints = ga->hints;
75     res = ga->res;
76    
77     /* call getaddrinfo */
78 doda 4165 // gai = Pgetaddrinfo(hostname, portname, hints, res);
79 maya 3227 gai = getaddrinfo(hostname, portname, hints, res);
80    
81     /* send value of gai as message to window hWnd */
82     PostMessage(hWnd, wMsg, (WPARAM)*ga->lpHandle, MAKELPARAM(0, gai));
83    
84     free(ga->lpHandle);
85     free(p);
86    
87     return 0;
88     }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26