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 6841 - (hide annotations) (download) (as text)
Tue Jul 4 15:02:28 2017 UTC (6 years, 9 months ago) by doda
Original Path: trunk/teraterm/teraterm/WSAAsyncGetAddrInfo.c
File MIME type: text/x-csrc
File size: 4053 byte(s)
TeraTerm Project としてのライセンス表記を追加

・Tera Term 本体分を横 80 桁に収まるように改行位置を調整
・ttssh 関連の分を追加
1 maya 3227 /*
2 doda 6806 * Copyright (C) 2010-2017 TeraTerm Project
3     * 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     #include <windows.h>
35     #include <process.h>
36     #include "WSAASyncGetAddrInfo.h"
37 doda 4165 #include "ttwsk.h"
38 maya 3227
39 doda 6801 static unsigned __stdcall getaddrinfo_thread(void * p);
40 maya 3227
41 doda 6801 HANDLE PASCAL WSAAsyncGetAddrInfo(HWND hWnd, unsigned int wMsg,
42     const char *hostname,
43     const char *portname,
44     struct addrinfo *hints,
45     struct addrinfo **res)
46 maya 3227 {
47     HANDLE thread;
48     unsigned tid;
49 doda 6801 struct getaddrinfo_args * ga;
50 maya 3227
51     /*
52     * allocate structure to pass args to sub-thread dynamically
53     * WSAAsyncGetAddrInfo() is reentrant
54     */
55 doda 6801 if ((ga = (struct getaddrinfo_args *)malloc(sizeof(struct getaddrinfo_args))) == NULL)
56 maya 3227 return NULL;
57    
58     /* packing arguments struct addrinfo_args */
59     ga->hWnd = hWnd;
60     ga->wMsg = wMsg;
61 yutakapon 5062 ga->hostname = _strdup(hostname); // �|�C���^�����n�����A�X���b�h�����s���������B(2012.11.7 yutaka)
62     ga->portname = _strdup(portname);
63 yutakapon 6344 ga->hints = *hints; // �|�C���^�����n�����A�X���b�h�����s���������B(2016.3.11 yutaka)
64 maya 3227 ga->res = res;
65    
66 doda 6801 ga->lpHandle = (HANDLE *)malloc(sizeof(HANDLE));
67 yutakapon 5062 if (ga->lpHandle == NULL) {
68     free(ga->hostname);
69     free(ga->portname);
70 maya 3227 return NULL;
71 yutakapon 5062 }
72 maya 3227
73     /* create sub-thread running getaddrinfo() */
74     thread = (HANDLE)_beginthreadex(NULL, 0, getaddrinfo_thread, ga, CREATE_SUSPENDED, &tid);
75     *ga->lpHandle = (HANDLE)thread;
76     ResumeThread(thread);
77    
78     /* return thread handle */
79     if (thread == 0) {
80     free(ga->lpHandle);
81 yutakapon 5062 free(ga->hostname);
82     free(ga->portname);
83 maya 3227 free(ga);
84     return NULL;
85     } else
86     return (HANDLE)thread;
87     }
88    
89 doda 6801 static unsigned __stdcall getaddrinfo_thread(void * p)
90 maya 3227 {
91     int gai;
92     HWND hWnd;
93     unsigned int wMsg;
94 doda 6801 const char *hostname;
95     const char *portname;
96     struct addrinfo *hints;
97     struct addrinfo **res;
98     struct getaddrinfo_args *ga;
99 maya 3227
100     /* unpacking arguments */
101 doda 6801 ga = (struct getaddrinfo_args *)p;
102 maya 3227 hWnd = ga->hWnd;
103     wMsg = ga->wMsg;
104     hostname = ga->hostname;
105     portname = ga->portname;
106 yutakapon 6344 hints = &ga->hints;
107 maya 3227 res = ga->res;
108    
109     /* call getaddrinfo */
110 doda 4165 // gai = Pgetaddrinfo(hostname, portname, hints, res);
111 maya 3227 gai = getaddrinfo(hostname, portname, hints, res);
112    
113     /* send value of gai as message to window hWnd */
114     PostMessage(hWnd, wMsg, (WPARAM)*ga->lpHandle, MAKELPARAM(0, gai));
115    
116     free(ga->lpHandle);
117 yutakapon 5062 free(ga->hostname);
118     free(ga->portname);
119 maya 3227 free(p);
120    
121     return 0;
122     }

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