src/protocols/gg/lib/http.c

changeset 11546
acb5676e57bb
parent 11360
b77fd5a8959a
child 12218
e65f13592888
equal deleted inserted replaced
11545:df2f9bb3fd6e 11546:acb5676e57bb
1 /* $Id: http.c 13582 2005-08-28 22:46:01Z boler $ */ 1 /* $Id: http.c 13801 2005-09-14 19:10:39Z datallah $ */
2 2
3 /* 3 /*
4 * (C) Copyright 2001-2002 Wojtek Kaniewski <wojtekka@irc.pl> 4 * (C) Copyright 2001-2002 Wojtek Kaniewski <wojtekka@irc.pl>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
18 * USA. 18 * USA.
19 */ 19 */
20 20
21 #include <sys/types.h> 21 #include <sys/types.h>
22 #ifndef _WIN32
22 #include <sys/wait.h> 23 #include <sys/wait.h>
23 #include <sys/socket.h> 24 #include <sys/socket.h>
24 #include <netinet/in.h> 25 #include <netinet/in.h>
25 #include <arpa/inet.h> 26 #include <arpa/inet.h>
27 #endif
26 28
27 #include "libgadu-config.h" 29 #include "libgadu-config.h"
28 30
29 #include <ctype.h> 31 #include <ctype.h>
30 #include <errno.h> 32 #include <errno.h>
33 #ifndef _WIN32
31 #include <netdb.h> 34 #include <netdb.h>
35 #endif
32 #ifdef __GG_LIBGADU_HAVE_PTHREAD 36 #ifdef __GG_LIBGADU_HAVE_PTHREAD
33 # include <pthread.h> 37 # include <pthread.h>
34 #endif 38 #endif
35 #include <stdarg.h> 39 #include <stdarg.h>
36 #include <stdio.h> 40 #include <stdio.h>
99 } 103 }
100 104
101 gg_debug(GG_DEBUG_MISC, "=> -----BEGIN-HTTP-QUERY-----\n%s\n=> -----END-HTTP-QUERY-----\n", h->query); 105 gg_debug(GG_DEBUG_MISC, "=> -----BEGIN-HTTP-QUERY-----\n%s\n=> -----END-HTTP-QUERY-----\n", h->query);
102 106
103 if (async) { 107 if (async) {
104 #ifndef __GG_LIBGADU_HAVE_PTHREAD 108 #ifdef __GG_LIBGADU_HAVE_PTHREAD
109 if (gg_resolve_pthread(&h->fd, &h->resolver, hostname)) {
110 #elif defined _WIN32
111 if (gg_resolve_win32thread(&h->fd, &h->resolver, hostname)) {
112 #else
105 if (gg_resolve(&h->fd, &h->pid, hostname)) { 113 if (gg_resolve(&h->fd, &h->pid, hostname)) {
106 #else
107 if (gg_resolve_pthread(&h->fd, &h->resolver, hostname)) {
108 #endif 114 #endif
109 gg_debug(GG_DEBUG_MISC, "// gg_http_connect() resolver failed\n"); 115 gg_debug(GG_DEBUG_MISC, "// gg_http_connect() resolver failed\n");
110 gg_http_free(h); 116 gg_http_free(h);
111 errno = ENOENT; 117 errno = ENOENT;
112 return NULL; 118 return NULL;
196 } 202 }
197 203
198 close(h->fd); 204 close(h->fd);
199 h->fd = -1; 205 h->fd = -1;
200 206
201 #ifndef __GG_LIBGADU_HAVE_PTHREAD 207 #ifdef __GG_LIBGADU_HAVE_PTHREAD
202 waitpid(h->pid, NULL, 0);
203 #else
204 if (h->resolver) { 208 if (h->resolver) {
205 pthread_cancel(*((pthread_t *) h->resolver)); 209 pthread_cancel(*((pthread_t *) h->resolver));
206 free(h->resolver); 210 free(h->resolver);
207 h->resolver = NULL; 211 h->resolver = NULL;
208 } 212 }
213 #elif defined _WIN32
214 if (h->resolver) {
215 HANDLE hnd = h->resolver;
216 TerminateThread(hnd, 0);
217 CloseHandle(hnd);
218 h->resolver = NULL;
219 }
220 #else
221 waitpid(h->pid, NULL, 0);
209 #endif 222 #endif
210 223
211 gg_debug(GG_DEBUG_MISC, "=> http, connecting to %s:%d\n", inet_ntoa(a), h->port); 224 gg_debug(GG_DEBUG_MISC, "=> http, connecting to %s:%d\n", inet_ntoa(a), h->port);
212 225
213 if ((h->fd = gg_connect(&a, h->port, h->async)) == -1) { 226 if ((h->fd = gg_connect(&a, h->port, h->async)) == -1) {

mercurial