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 5062 - (hide annotations) (download) (as text)
Wed Nov 7 11:16:30 2012 UTC (11 years, 5 months ago) by yutakapon
Original Path: trunk/teraterm/teraterm/WSAAsyncGetAddrInfo.c
File MIME type: text/x-csrc
File size: 2559 byte(s)
チケット#30025: X11転送が開始できない
X11転送の開始が接続エラーで失敗することがある問題を修正した。

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 yutakapon 5062 ga->hostname = _strdup(hostname); // �|�C���^�����n�����A�X���b�h�����s���������B(2012.11.7 yutaka)
35     ga->portname = _strdup(portname);
36 maya 3227 ga->hints = hints;
37     ga->res = res;
38    
39     ga->lpHandle = (HANDLE FAR *)malloc(sizeof(HANDLE));
40 yutakapon 5062 if (ga->lpHandle == NULL) {
41     free(ga->hostname);
42     free(ga->portname);
43 maya 3227 return NULL;
44 yutakapon 5062 }
45 maya 3227
46     /* create sub-thread running getaddrinfo() */
47     thread = (HANDLE)_beginthreadex(NULL, 0, getaddrinfo_thread, ga, CREATE_SUSPENDED, &tid);
48     *ga->lpHandle = (HANDLE)thread;
49     ResumeThread(thread);
50    
51     /* return thread handle */
52     if (thread == 0) {
53     free(ga->lpHandle);
54 yutakapon 5062 free(ga->hostname);
55     free(ga->portname);
56 maya 3227 free(ga);
57     return NULL;
58     } else
59     return (HANDLE)thread;
60     }
61    
62     static unsigned __stdcall getaddrinfo_thread(void FAR * p)
63     {
64     int gai;
65     HWND hWnd;
66     unsigned int wMsg;
67     const char FAR * hostname;
68     const char FAR * portname;
69     struct addrinfo FAR * hints;
70     struct addrinfo FAR * FAR * res;
71     struct getaddrinfo_args FAR * ga;
72    
73     /* unpacking arguments */
74     ga = (struct getaddrinfo_args FAR *)p;
75     hWnd = ga->hWnd;
76     wMsg = ga->wMsg;
77     hostname = ga->hostname;
78     portname = ga->portname;
79     hints = ga->hints;
80     res = ga->res;
81    
82     /* call getaddrinfo */
83 doda 4165 // gai = Pgetaddrinfo(hostname, portname, hints, res);
84 maya 3227 gai = getaddrinfo(hostname, portname, hints, res);
85    
86     /* send value of gai as message to window hWnd */
87     PostMessage(hWnd, wMsg, (WPARAM)*ga->lpHandle, MAKELPARAM(0, gai));
88    
89     free(ga->lpHandle);
90 yutakapon 5062 free(ga->hostname);
91     free(ga->portname);
92 maya 3227 free(p);
93    
94     return 0;
95     }

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