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

とりあえず Tera Term 本体分。
TeraTerm Project としての copyright 表記の年部分はコミットログを確認して書いたつもりだけど、ミスってたらすみません。

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

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