88 * Author: Dmitry Ganyushin [email protected] 99 */
1010#include " FileHTTP.h"
11+ #include < cstring>
12+ #ifdef _MSC_VER
13+ #define FD_SETSIZE 1024
14+ #include < process.h>
15+ #include < time.h>
16+ #include < winsock2.h>
17+
18+ #include < windows.h>
19+ #define getpid () _getpid()
20+ #define read (fd, buf, len ) recv(fd, (buf), (len), 0 )
21+ #define write (fd, buf, len ) send(fd, buf, (len), 0 )
22+ #define close (x ) closesocket(x)
23+ #define INST_ADDRSTRLEN 50
24+ #else
25+ #include < netinet/in.h>
1126#include < sys/socket.h>
1227
1328#include < arpa/inet.h>
1429#include < cstring>
1530#include < netdb.h>
31+ #include < netinet/in.h>
1632#include < unistd.h>
33+ #endif
1734namespace adios2
1835{
1936namespace transport
@@ -43,7 +60,7 @@ void FileHTTP::Open(const std::string &name, const Mode openMode, const bool asy
4360{
4461 struct protoent *protoent;
4562 struct hostent *hostent;
46- in_addr_t in_addr ;
63+ uint32_t addr_tmp ;
4764
4865 m_Name = name;
4966 /* Build the socket. */
@@ -58,20 +75,21 @@ void FileHTTP::Open(const std::string &name, const Mode openMode, const bool asy
5875 /* get from parameters. Where the proxy should run*/
5976
6077 /* Build the address. */
78+ #define _WINSOCK_DEPRECATED_NO_WARNINGS 1
6179 hostent = gethostbyname (m_hostname.c_str ());
6280 if (hostent == NULL )
6381 {
6482 helper::Throw<std::ios_base::failure>(" Toolkit" , " transport::file::FileHTTP" , " Open" ,
6583 " error: gethostbyname " + m_hostname);
6684 }
67- in_addr = inet_addr (inet_ntoa (*(struct in_addr *)*(hostent->h_addr_list )));
68- if (in_addr == ( in_addr_t )- 1 )
85+ addr_tmp = inet_addr (inet_ntoa (*(struct in_addr *)*(hostent->h_addr_list )));
86+ if (addr_tmp == INADDR_NONE )
6987 {
7088 helper::Throw<std::ios_base::failure>(" Toolkit" , " transport::file::FileHTTP" , " Open" ,
7189 " error: inet_addr " +
7290 std::string (*(hostent->h_addr_list )));
7391 }
74- sockaddr_in.sin_addr .s_addr = in_addr ;
92+ sockaddr_in.sin_addr .s_addr = addr_tmp ;
7593 sockaddr_in.sin_family = AF_INET;
7694 sockaddr_in.sin_port = htons (m_server_port);
7795
@@ -227,8 +245,9 @@ void FileHTTP::Read(char *buffer, size_t size, size_t start)
227245 size_t bytes_recd = 0 ;
228246 while (bytes_recd < size)
229247 {
230- nbytes_total = read (m_socketFileDescriptor, buffer + bytes_recd,
231- std::min (size - bytes_recd, BUF_SIZE));
248+ size_t remaining = size - bytes_recd;
249+ int read_len = (int )(remaining < BUF_SIZE ? remaining : BUF_SIZE);
250+ nbytes_total = read (m_socketFileDescriptor, buffer + bytes_recd, read_len);
232251 if (nbytes_total == -1 )
233252 {
234253 helper::Throw<std::ios_base::failure>(" Toolkit" , " transport::file::FileHTTP" , " Read" ,
0 commit comments