Skip to content

Commit

Permalink
fix win32
Browse files Browse the repository at this point in the history
  • Loading branch information
tqchen committed May 28, 2015
1 parent 8bbed35 commit fd8920c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
2 changes: 2 additions & 0 deletions guide/basic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*
* \author Tianqi Chen
*/
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#include <vector>
#include <rabit.h>
using namespace rabit;
Expand Down
10 changes: 5 additions & 5 deletions src/allreduce_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ AllreduceBase::TryAllreduceTree(void *sendrecvbuf_,
if (len != -1) {
size_up_out += static_cast<size_t>(len);
} else {
ReturnType ret = Errno2Return(errno);
ReturnType ret = Errno2Return();
if (ret != kSuccess) {
return ReportError(&links[parent_index], ret);
}
Expand All @@ -533,7 +533,7 @@ AllreduceBase::TryAllreduceTree(void *sendrecvbuf_,
utils::Assert(size_down_in <= size_up_out,
"Allreduce: boundary error");
} else {
ReturnType ret = Errno2Return(errno);
ReturnType ret = Errno2Return();
if (ret != kSuccess) {
return ReportError(&links[parent_index], ret);
}
Expand Down Expand Up @@ -709,7 +709,7 @@ AllreduceBase::TryAllgatherRing(void *sendrecvbuf_, size_t total_size,
if (len != -1) {
read_ptr += static_cast<size_t>(len);
} else {
ReturnType ret = Errno2Return(errno);
ReturnType ret = Errno2Return();
if (ret != kSuccess) return ReportError(&next, ret);
}
}
Expand All @@ -723,7 +723,7 @@ AllreduceBase::TryAllgatherRing(void *sendrecvbuf_, size_t total_size,
if (len != -1) {
write_ptr += static_cast<size_t>(len);
} else {
ReturnType ret = Errno2Return(errno);
ReturnType ret = Errno2Return();
if (ret != kSuccess) return ReportError(&prev, ret);
}
}
Expand Down Expand Up @@ -826,7 +826,7 @@ AllreduceBase::TryReduceScatterRing(void *sendrecvbuf_,
if (len != -1) {
write_ptr += static_cast<size_t>(len);
} else {
ReturnType ret = Errno2Return(errno);
ReturnType ret = Errno2Return();
if (ret != kSuccess) return ReportError(&prev, ret);
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/allreduce_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,13 @@ class AllreduceBase : public IEngine {
}
};
/*! \brief translate errno to return type */
inline static ReturnType Errno2Return(int errsv) {
if (errsv == EAGAIN || errsv == EWOULDBLOCK) return kSuccess;
inline static ReturnType Errno2Return() {
int errsv = utils::Socket::GetLastError();
if (errsv == EAGAIN || errsv == EWOULDBLOCK || errsv == 0) return kSuccess;
#ifdef _WIN32
if (errsv == WSAEWOULDBLOCK) return kSuccess;
if (errsv == WSAECONNRESET) return kConnReset;
#endif
if (errsv == ECONNRESET) return kConnReset;
return kSockError;
}
Expand Down Expand Up @@ -299,7 +304,7 @@ class AllreduceBase : public IEngine {
if (len == 0) {
sock.Close(); return kRecvZeroLen;
}
if (len == -1) return Errno2Return(errno);
if (len == -1) return Errno2Return();
size_read += static_cast<size_t>(len);
return kSuccess;
}
Expand All @@ -318,7 +323,7 @@ class AllreduceBase : public IEngine {
if (len == 0) {
sock.Close(); return kRecvZeroLen;
}
if (len == -1) return Errno2Return(errno);
if (len == -1) return Errno2Return();
size_read += static_cast<size_t>(len);
return kSuccess;
}
Expand All @@ -331,7 +336,7 @@ class AllreduceBase : public IEngine {
inline ReturnType WriteFromArray(const void *sendbuf_, size_t max_size) {
const char *p = static_cast<const char*>(sendbuf_);
ssize_t len = sock.Send(p + size_write, max_size - size_write);
if (len == -1) return Errno2Return(errno);
if (len == -1) return Errno2Return();
size_write += static_cast<size_t>(len);
return kSuccess;
}
Expand Down
6 changes: 3 additions & 3 deletions src/allreduce_robust.cc
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ AllreduceRobust::TryRecoverData(RecoverType role,
if (len != -1) {
links[i].size_write += len;
} else {
ReturnType ret = Errno2Return(errno);
ReturnType ret = Errno2Return();
if (ret != kSuccess) return ReportError(&links[i], ret);
}
}
Expand Down Expand Up @@ -1161,7 +1161,7 @@ AllreduceRobust::RingPassing(void *sendrecvbuf_,
if (len != -1) {
read_ptr += static_cast<size_t>(len);
} else {
ReturnType ret = Errno2Return(errno);
ReturnType ret = Errno2Return();
if (ret != kSuccess) return ReportError(&prev, ret);
}
}
Expand All @@ -1171,7 +1171,7 @@ AllreduceRobust::RingPassing(void *sendrecvbuf_,
if (len != -1) {
write_ptr += static_cast<size_t>(len);
} else {
ReturnType ret = Errno2Return(errno);
ReturnType ret = Errno2Return();
if (ret != kSuccess) return ReportError(&prev, ret);
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ class Socket {
inline operator SOCKET() const {
return sockfd;
}
inline static int GetLastError(void) {
#ifdef _WIN32
return WSAGetLastError();
#else
return errno;
#endif
}
/*!
* \brief start up the socket module
* call this before using the sockets
Expand Down
1 change: 1 addition & 0 deletions windows/basic/basic.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>..\..\include</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand Down

0 comments on commit fd8920c

Please sign in to comment.