Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/teraterm/teraterm/WSAAsyncGetAddrInfo.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6801 - (hide annotations) (download) (as text)
Tue Jun 13 10:30:12 2017 UTC (6 years, 9 months ago) by doda
File MIME type: text/x-csrc
File size: 2544 byte(s)
eliminate FAR keyword.
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 doda 6801 static unsigned __stdcall getaddrinfo_thread(void * p);
13 maya 3227
14 doda 6801 HANDLE PASCAL WSAAsyncGetAddrInfo(HWND hWnd, unsigned int wMsg,
15     const char *hostname,
16     const char *portname,
17     struct addrinfo *hints,
18     struct addrinfo **res)
19 maya 3227 {
20     HANDLE thread;
21     unsigned tid;
22 doda 6801 struct getaddrinfo_args * ga;
23 maya 3227
24     /*
25     * allocate structure to pass args to sub-thread dynamically
26     * WSAAsyncGetAddrInfo() is reentrant
27     */
28 doda 6801 if ((ga = (struct getaddrinfo_args *)malloc(sizeof(struct getaddrinfo_args))) == NULL)
29 maya 3227 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 yutakapon 6344 ga->hints = *hints; // ƒ|ƒCƒ“ƒ^‚¾‚¯“n‚·‚Æ�AƒXƒŒƒbƒh�æ‚Å•s’è‚Æ‚È‚é�B(2016.3.11 yutaka)
37 maya 3227 ga->res = res;
38    
39 doda 6801 ga->lpHandle = (HANDLE *)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 doda 6801 static unsigned __stdcall getaddrinfo_thread(void * p)
63 maya 3227 {
64     int gai;
65     HWND hWnd;
66     unsigned int wMsg;
67 doda 6801 const char *hostname;
68     const char *portname;
69     struct addrinfo *hints;
70     struct addrinfo **res;
71     struct getaddrinfo_args *ga;
72 maya 3227
73     /* unpacking arguments */
74 doda 6801 ga = (struct getaddrinfo_args *)p;
75 maya 3227 hWnd = ga->hWnd;
76     wMsg = ga->wMsg;
77     hostname = ga->hostname;
78     portname = ga->portname;
79 yutakapon 6344 hints = &ga->hints;
80 maya 3227 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