Skip to content

Commit

Permalink
* Added min and max functions after not being able to figure out how …
Browse files Browse the repository at this point in the history
…to include things to work on all visual studio versions *sigh* just not worth spending more time on things
  • Loading branch information
honkstar1 committed Jun 21, 2021
1 parent 74e08a7 commit 9daafc2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
2 changes: 2 additions & 0 deletions include/EACopyShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ int stringEquals(const char* a, const char* b);
bool stringCopy(wchar_t* dest, uint destCapacity, const wchar_t* source);
#define eacopy_sizeof_array(array) int(sizeof(array)/sizeof(array[0]))
WString getVersionString(uint major, uint minor, bool isDebug);
template<class T> T min(T a, T b) { return a < b ? a : b; }
template<class T> T max(T a, T b) { return a > b ? a : b; }

struct TimerScope
{
Expand Down
4 changes: 2 additions & 2 deletions source/EACopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ bool readSettings(Settings& outSettings, int argc, wchar_t* argv[])
{
outSettings.threadCount = 7;
if (arg[3] == ':')
outSettings.threadCount = std::max(0, wtoi(arg + 4) - 1);
outSettings.threadCount = max(0, wtoi(arg + 4) - 1);
}
else if (equalsIgnoreCase(arg, L"/NOSERVER"))
{
Expand Down Expand Up @@ -528,7 +528,7 @@ int main(int argc, char* argv_[])
if (stats.destServerUsed || stats.sourceServerUsed)
logInfoLinef(L" Server found and used! (%ls)", stats.info.c_str());
else if (stats.serverAttempt && !stats.destServerUsed)
logInfoLinef(L" Server not found (Spent ~%ls trying to connect. Use /NOSERVER to disable attempt)", toHourMinSec(stats.connectTime/std::max(1, (int)settings.threadCount)).c_str());
logInfoLinef(L" Server not found (Spent ~%ls trying to connect. Use /NOSERVER to disable attempt)", toHourMinSec(stats.connectTime/max(1, (int)settings.threadCount)).c_str());
else
logInfoLinef(L" No server used!");
}
Expand Down
16 changes: 8 additions & 8 deletions source/EACopyNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ bool sendFile(Socket& socket, const wchar_t* src, size_t fileSize, WriteFileType
while (pos != fileSize)
{
u64 left = fileSize - pos;
uint toWrite = (uint)std::min(left, u64(INT_MAX-1));
uint toWrite = (uint)min(left, u64(INT_MAX-1));

u64 startSendTime = getTime();
if (!TransmitFile(socket.socket, sourceFile, toWrite, 0, &overlapped, NULL, TF_USE_KERNEL_APC))
Expand Down Expand Up @@ -337,7 +337,7 @@ bool sendFile(Socket& socket, const wchar_t* src, size_t fileSize, WriteFileType
u64 left = fileSize;
while (left)
{
uint toRead = (uint)std::min(left, u64(NetworkTransferChunkSize));
uint toRead = (uint)min(left, u64(NetworkTransferChunkSize));
uint toReadAligned = useBufferedIO ? toRead : (((toRead + 4095) / 4096) * 4096);

u64 read;
Expand Down Expand Up @@ -370,7 +370,7 @@ bool sendFile(Socket& socket, const wchar_t* src, size_t fileSize, WriteFileType
// Make sure the amount of data we've read fit in the destination compressed buffer
static_assert(ZSTD_COMPRESSBOUND(CompressedNetworkTransferChunkSize - CompressBoundReservation) <= CompressedNetworkTransferChunkSize - 4, "");

uint toRead = std::min(left, u64(CompressedNetworkTransferChunkSize - CompressBoundReservation));
uint toRead = min(left, u64(CompressedNetworkTransferChunkSize - CompressBoundReservation));
uint toReadAligned = useBufferedIO ? toRead : (((toRead + 4095) / 4096) * 4096);
u64 read;
if (!readFile(src, sourceFile, copyContext.buffers[0], toReadAligned, read, ioStats))
Expand Down Expand Up @@ -428,9 +428,9 @@ bool sendFile(Socket& socket, const wchar_t* src, size_t fileSize, WriteFileType

u64 timeUnitsPerBytes = (cs.currentSendTime * 1000000) / cs.currentSendBytes;
if (timeUnitsPerBytes < cs.lastTimeUnitPerBytes)
cs.currentLevel = std::min(14, cs.currentLevel + 1);
cs.currentLevel = min(14, cs.currentLevel + 1);
else
cs.currentLevel = std::max(1, cs.currentLevel - 1);
cs.currentLevel = max(1, cs.currentLevel - 1);
cs.lastTimeUnitPerBytes = timeUnitsPerBytes;
}
}
Expand Down Expand Up @@ -475,7 +475,7 @@ bool receiveFile(bool& outSuccess, Socket& socket, const wchar_t* fullPath, size
// Copy the stuff already in the buffer
if (recvPos > commandSize)
{
u64 toCopy = std::min(u64(recvPos - commandSize), u64(fileSize));
u64 toCopy = min(u64(recvPos - commandSize), u64(fileSize));
outSuccess = outSuccess & writeFile(fullPath, file, recvBuffer + commandSize, toCopy, ioStats, &osWrite);
read = toCopy;
commandSize += (uint)toCopy;
Expand All @@ -487,7 +487,7 @@ bool receiveFile(bool& outSuccess, Socket& socket, const wchar_t* fullPath, size
{
u64 startRecvTime = getTime();
u64 left = fileSize - read;
uint toRead = (uint)std::min(left, u64(NetworkTransferChunkSize));
uint toRead = (uint)min(left, u64(NetworkTransferChunkSize));
WSABUF wsabuf;
wsabuf.len = toRead;
wsabuf.buf = (char*)copyContext.buffers[fileBufIndex];
Expand Down Expand Up @@ -539,7 +539,7 @@ bool receiveFile(bool& outSuccess, Socket& socket, const wchar_t* fullPath, size
// Copy the stuff already in the buffer
if (recvPos > commandSize)
{
u64 toCopy = std::min(u64(recvPos - commandSize), u64(fileSize));
u64 toCopy = min(u64(recvPos - commandSize), u64(fileSize));
outSuccess = outSuccess & writeFile(fullPath, file, recvBuffer + commandSize, toCopy, ioStats, &osWrite);
read = toCopy;
commandSize += (uint)toCopy;
Expand Down
6 changes: 3 additions & 3 deletions source/EACopyShared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,7 @@ bool writeFile(const wchar_t* fullPath, FileHandle& file, const void* data, u64
while (left)
{
uint written;
uint toWrite = (uint)std::min(left, u64(INT_MAX-1));
uint toWrite = (uint)min(left, u64(INT_MAX-1));
if (!WriteFile(file, data, toWrite, &written, nullptr))
{
logErrorf(L"Trying to write data to %ls: %ls", fullPath, getErrorText(fullPath, GetLastError()).c_str());
Expand All @@ -1443,7 +1443,7 @@ bool writeFile(const wchar_t* fullPath, FileHandle& file, const void* data, u64
u64 left = dataSize;
while (left)
{
size_t toWrite = (uint)std::min(left, u64(INT_MAX-1));
size_t toWrite = (uint)min(left, u64(INT_MAX-1));
size_t written = write(fileHandle, data, toWrite);
if (written == -1)
{
Expand Down Expand Up @@ -1774,7 +1774,7 @@ bool copyFile(const wchar_t* source, const FileInfo& sourceInfo, const wchar_t*
++ioStats.readCount;
TimerScope _(ioStats.readTime);

uint toRead = (uint)std::min(left, u64(ReadChunkSize));
uint toRead = (uint)min(left, u64(ReadChunkSize));
activeBufferIndex = (activeBufferIndex + 1) % 3;

uint toReadAligned = nobufferingFlag ? (((toRead + 4095) / 4096) * 4096) : toRead;
Expand Down
4 changes: 2 additions & 2 deletions test/EACopyTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ struct TestBase
WString fullFilename = dir + name;
const wchar_t* fullFileName = convertToShortPath(fullFilename.c_str(), tempBuffer);

u64 dataSize = std::min(size, 1024*1024*256ull);
u64 dataSize = min(size, 1024*1024*256ull);
char* data = new char[size];
for (u64 i=0; i!=dataSize; ++i)
data[i] = 'a' + i % 26;
Expand Down Expand Up @@ -323,7 +323,7 @@ struct TestBase
{
char buffer[128];
memset(buffer, 0, sizeof(buffer));
uint writePos = std::max((uint)0, (uint)(((uint(rand()) << 16) + uint(rand())) % (fileSize - 128)));
uint writePos = max((uint)0, (uint)(((uint(rand()) << 16) + uint(rand())) % (fileSize - 128)));
memcpy(data + writePos, buffer, sizeof(buffer));
}

Expand Down

0 comments on commit 9daafc2

Please sign in to comment.