Ticket #1124: file.c.diff
File file.c.diff, 2.2 KB (added by mcr42.myopenid.com, 8 years ago) |
---|
-
file.c
51 51 #include <netdb.h> 52 52 #endif 53 53 54 #ifdef HAVE_WINSOCK 55 #include <winsock2.h> 56 #include <ws2tcpip.h> 57 int inet_aton(const char *cp, struct in_addr *inp); 58 59 int inet_aton(const char *cp, struct in_addr *inp) 60 { 61 unsigned long addr = inet_addr(cp); 62 inp->S_un.S_addr = addr; 63 return addr!=-1; 64 } 65 #endif 66 54 67 extern char *version; 55 68 56 69 #ifdef HAVE_LIBCRYPTO … … 95 108 #pragma pack(pop) 96 109 #endif 97 110 98 #if def HAVE_SOCKET111 #if defined(HAVE_SOCKET) || defined(HAVE_WINSOCK) 99 112 static int 100 113 file_socket_connect(char *host, char *service) 101 114 { … … 103 116 struct addrinfo *result, *rp; 104 117 int fd=-1,s; 105 118 119 #ifdef _WIN32 120 WSADATA wsi; 121 WSAStartup(0x0202,&wsi); 122 #endif 123 106 124 memset(&hints, 0, sizeof(struct addrinfo)); 107 125 hints.ai_family = AF_UNSPEC; 108 126 hints.ai_socktype = SOCK_STREAM; … … 130 148 file_http_request(struct file *file, char *method, char *host, char *path, char *header, int persistent) 131 149 { 132 150 char *request=g_strdup_printf("%s %s HTTP/1.0\r\nUser-Agent: navit %s\r\nHost: %s\r\n%s%s%s\r\n",method,path,version,host,persistent?"Connection: Keep-Alive\r\n":"",header?header:"",header?"\r\n":""); 151 #ifdef _WIN32 152 send(file->fd, request, strlen(request), 0); 153 #else 133 154 write(file->fd, request, strlen(request)); 155 #endif 134 156 dbg(1,"%s\n",request); 135 157 file->requests++; 136 158 } … … 202 224 int 203 225 file_request(struct file *f, struct attr **options) 204 226 { 205 #if def HAVE_SOCKET227 #if defined(HAVE_SOCKET) || defined(HAVE_WINSOCK) 206 228 return file_request_do(f, options, 0); 207 229 #else 208 230 return 0; … … 225 247 int open_flags=O_LARGEFILE|O_BINARY; 226 248 227 249 if (options && (attr=attr_search(options, NULL, attr_url))) { 228 #if def HAVE_SOCKET250 #if defined(HAVE_SOCKET) || defined(HAVE_WINSOCK) 229 251 file_request_do(file, options, 1); 230 252 #endif 231 253 } else { … … 436 458 if (toread >= 4096 && !eof) { 437 459 if (!file->requests && toread > size) 438 460 toread=size; 461 #ifdef _WIN32 462 rd=recv(file->fd, file->buffer+file->buffer_len, toread, 0); 463 #else 439 464 rd=read(file->fd, file->buffer+file->buffer_len, toread); 465 #endif 440 466 if (rd > 0) { 441 467 file->buffer_len+=rd; 442 468 } else