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 7479 - (hide annotations) (download) (as text)
Wed Mar 13 15:32:17 2019 UTC (5 years, 1 month ago) by zmatsuo
File MIME type: text/x-csrc
File size: 4075 byte(s)
wspiapi.h を include した
ws2_32.dll関連でエラーが出ないバイナリがビルドできるようになった
従来は _WIN32_WINNT のdefine具合よってWindows95でエラーが出るバイナリとなっていた
1 maya 3227 /*
2 zmatsuo 7479 * Copyright (C) 2010-2019 TeraTerm Project
3 doda 6806 * All rights reserved.
4     *
5 doda 6841 * Redistribution and use in source and binary forms, with or without
6     * modification, are permitted provided that the following conditions
7     * are met:
8 doda 6806 *
9 doda 6841 * 1. Redistributions of source code must retain the above copyright
10     * notice, this list of conditions and the following disclaimer.
11     * 2. Redistributions in binary form must reproduce the above copyright
12     * notice, this list of conditions and the following disclaimer in the
13     * documentation and/or other materials provided with the distribution.
14     * 3. The name of the author may not be used to endorse or promote products
15     * derived from this software without specific prior written permission.
16 doda 6806 *
17 doda 6841 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18     * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19     * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20     * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22     * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26     * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 doda 6806 */
28     /*
29 maya 3227 * WSAAsyncGetAddrInfo.c -- asynchronous version of getaddrinfo
30     * Copyright(C) 2000-2003 Jun-ya Kato <kato@win6.jp>
31     */
32     #include <winsock2.h>
33     #include <ws2tcpip.h>
34 zmatsuo 7479 #include <wspiapi.h>
35 maya 3227 #include <windows.h>
36     #include <process.h>
37 zmatsuo 7479 #include "WSAAsyncGetAddrInfo.h"
38 doda 4165 #include "ttwsk.h"
39 maya 3227
40 doda 6801 static unsigned __stdcall getaddrinfo_thread(void * p);
41 maya 3227
42 doda 6801 HANDLE PASCAL WSAAsyncGetAddrInfo(HWND hWnd, unsigned int wMsg,
43     const char *hostname,
44     const char *portname,
45     struct addrinfo *hints,
46     struct addrinfo **res)
47 maya 3227 {
48     HANDLE thread;
49     unsigned tid;
50 doda 6801 struct getaddrinfo_args * ga;
51 maya 3227
52     /*
53     * allocate structure to pass args to sub-thread dynamically
54     * WSAAsyncGetAddrInfo() is reentrant
55     */
56 doda 6801 if ((ga = (struct getaddrinfo_args *)malloc(sizeof(struct getaddrinfo_args))) == NULL)
57 maya 3227 return NULL;
58    
59     /* packing arguments struct addrinfo_args */
60     ga->hWnd = hWnd;
61     ga->wMsg = wMsg;
62 yutakapon 5062 ga->hostname = _strdup(hostname); // �|�C���^�����n�����A�X���b�h�����s���������B(2012.11.7 yutaka)
63     ga->portname = _strdup(portname);
64 yutakapon 6344 ga->hints = *hints; // �|�C���^�����n�����A�X���b�h�����s���������B(2016.3.11 yutaka)
65 maya 3227 ga->res = res;
66    
67 doda 6801 ga->lpHandle = (HANDLE *)malloc(sizeof(HANDLE));
68 yutakapon 5062 if (ga->lpHandle == NULL) {
69     free(ga->hostname);
70     free(ga->portname);
71 maya 3227 return NULL;
72 yutakapon 5062 }
73 maya 3227
74     /* create sub-thread running getaddrinfo() */
75     thread = (HANDLE)_beginthreadex(NULL, 0, getaddrinfo_thread, ga, CREATE_SUSPENDED, &tid);
76     *ga->lpHandle = (HANDLE)thread;
77     ResumeThread(thread);
78    
79     /* return thread handle */
80     if (thread == 0) {
81     free(ga->lpHandle);
82 yutakapon 5062 free(ga->hostname);
83     free(ga->portname);
84 maya 3227 free(ga);
85     return NULL;
86     } else
87     return (HANDLE)thread;
88     }
89    
90 doda 6801 static unsigned __stdcall getaddrinfo_thread(void * p)
91 maya 3227 {
92     int gai;
93     HWND hWnd;
94     unsigned int wMsg;
95 doda 6801 const char *hostname;
96     const char *portname;
97     struct addrinfo *hints;
98     struct addrinfo **res;
99     struct getaddrinfo_args *ga;
100 maya 3227
101     /* unpacking arguments */
102 doda 6801 ga = (struct getaddrinfo_args *)p;
103 maya 3227 hWnd = ga->hWnd;
104     wMsg = ga->wMsg;
105     hostname = ga->hostname;
106     portname = ga->portname;
107 yutakapon 6344 hints = &ga->hints;
108 maya 3227 res = ga->res;
109    
110     /* call getaddrinfo */
111 doda 4165 // gai = Pgetaddrinfo(hostname, portname, hints, res);
112 maya 3227 gai = getaddrinfo(hostname, portname, hints, res);
113    
114     /* send value of gai as message to window hWnd */
115     PostMessage(hWnd, wMsg, (WPARAM)*ga->lpHandle, MAKELPARAM(0, gai));
116    
117     free(ga->lpHandle);
118 yutakapon 5062 free(ga->hostname);
119     free(ga->portname);
120 maya 3227 free(p);
121    
122     return 0;
123     }

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