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 8391 - (hide annotations) (download) (as text)
Thu Nov 21 15:00:01 2019 UTC (4 years, 4 months ago) by zmatsuo
File MIME type: text/x-csrc
File size: 4359 byte(s)
_CRTDBG_MAP_ALLOC を使ってデバッグバージョンのヒープ割り当て関数へ切り替え

- r8390
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 8391 #if !defined(_CRTDBG_MAP_ALLOC)
38     #define _CRTDBG_MAP_ALLOC
39     #endif
40     #include <stdlib.h>
41 zmatsuo 7930 #include <crtdbg.h>
42 zmatsuo 7479 #include "WSAAsyncGetAddrInfo.h"
43 doda 4165 #include "ttwsk.h"
44 maya 3227
45 zmatsuo 7930 struct getaddrinfo_args {
46     HWND hWnd;
47     unsigned int wMsg;
48     char *hostname;
49     char *portname;
50     struct addrinfo hints;
51     struct addrinfo **res;
52     HANDLE *lpHandle;
53     };
54    
55 doda 6801 static unsigned __stdcall getaddrinfo_thread(void * p);
56 maya 3227
57 doda 6801 HANDLE PASCAL WSAAsyncGetAddrInfo(HWND hWnd, unsigned int wMsg,
58     const char *hostname,
59     const char *portname,
60     struct addrinfo *hints,
61     struct addrinfo **res)
62 maya 3227 {
63     HANDLE thread;
64     unsigned tid;
65 doda 6801 struct getaddrinfo_args * ga;
66 maya 3227
67     /*
68     * allocate structure to pass args to sub-thread dynamically
69     * WSAAsyncGetAddrInfo() is reentrant
70     */
71 doda 6801 if ((ga = (struct getaddrinfo_args *)malloc(sizeof(struct getaddrinfo_args))) == NULL)
72 maya 3227 return NULL;
73    
74     /* packing arguments struct addrinfo_args */
75     ga->hWnd = hWnd;
76     ga->wMsg = wMsg;
77 yutakapon 5062 ga->hostname = _strdup(hostname); // �|�C���^�����n�����A�X���b�h�����s���������B(2012.11.7 yutaka)
78     ga->portname = _strdup(portname);
79 yutakapon 6344 ga->hints = *hints; // �|�C���^�����n�����A�X���b�h�����s���������B(2016.3.11 yutaka)
80 maya 3227 ga->res = res;
81    
82 doda 6801 ga->lpHandle = (HANDLE *)malloc(sizeof(HANDLE));
83 yutakapon 5062 if (ga->lpHandle == NULL) {
84     free(ga->hostname);
85     free(ga->portname);
86 maya 3227 return NULL;
87 yutakapon 5062 }
88 maya 3227
89     /* create sub-thread running getaddrinfo() */
90     thread = (HANDLE)_beginthreadex(NULL, 0, getaddrinfo_thread, ga, CREATE_SUSPENDED, &tid);
91     if (thread == 0) {
92     free(ga->lpHandle);
93 yutakapon 5062 free(ga->hostname);
94     free(ga->portname);
95 maya 3227 free(ga);
96 zmatsuo 7949 return NULL; // return error
97     }
98    
99     /* return thread handle */
100     *ga->lpHandle = thread;
101     ResumeThread(thread);
102     return thread;
103 maya 3227 }
104    
105 doda 6801 static unsigned __stdcall getaddrinfo_thread(void * p)
106 maya 3227 {
107     int gai;
108     HWND hWnd;
109     unsigned int wMsg;
110 doda 6801 const char *hostname;
111     const char *portname;
112     struct addrinfo *hints;
113     struct addrinfo **res;
114     struct getaddrinfo_args *ga;
115 maya 3227
116     /* unpacking arguments */
117 doda 6801 ga = (struct getaddrinfo_args *)p;
118 maya 3227 hWnd = ga->hWnd;
119     wMsg = ga->wMsg;
120     hostname = ga->hostname;
121     portname = ga->portname;
122 yutakapon 6344 hints = &ga->hints;
123 maya 3227 res = ga->res;
124    
125     /* call getaddrinfo */
126 doda 4165 // gai = Pgetaddrinfo(hostname, portname, hints, res);
127 maya 3227 gai = getaddrinfo(hostname, portname, hints, res);
128    
129     /* send value of gai as message to window hWnd */
130     PostMessage(hWnd, wMsg, (WPARAM)*ga->lpHandle, MAKELPARAM(0, gai));
131    
132     free(ga->lpHandle);
133 yutakapon 5062 free(ga->hostname);
134     free(ga->portname);
135 maya 3227 free(p);
136    
137     return 0;
138     }

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