Skip to content

Commit

Permalink
fixed issue with certain buffer size patterns eg when piping from curl
Browse files Browse the repository at this point in the history
  • Loading branch information
adzm committed Aug 13, 2016
1 parent da0429f commit daae2f9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# mssqlPipe v1.2.0
# mssqlPipe v1.2.1

SQL Server command line backup and restore through pipes using stdin and stdout!

Expand Down
26 changes: 21 additions & 5 deletions mssqlPipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/****/

constexpr auto mssqlPipe_Version = "1.2.0";
constexpr auto mssqlPipe_Version = "1.2.1";

/****/

Expand Down Expand Up @@ -191,6 +191,10 @@ HRESULT processPipeRestore(IClientVirtualDevice* pDevice, InputFile& file, bool
while (bytesTransferred < pCmd->size) {
DWORD len = file.read(pCmd->buffer + bytesTransferred, pCmd->size - bytesTransferred);
bytesTransferred += len;
if (!len) {
hr = ::GetLastError();
break;
}
}

break;
Expand All @@ -207,7 +211,11 @@ HRESULT processPipeRestore(IClientVirtualDevice* pDevice, InputFile& file, bool
break;
}

hr = pDevice->CompleteCommand(pCmd, completionCode, bytesTransferred, 0);
HRESULT hrComplete = pDevice->CompleteCommand(pCmd, completionCode, bytesTransferred, 0);

if (!hr || bytesTransferred > 0) {
hr = hrComplete;
}

ps.accumulate(bytesTransferred);

Expand Down Expand Up @@ -272,6 +280,10 @@ HRESULT processPipeBackup(IClientVirtualDevice* pDevice, OutputFile& file, bool
while (bytesTransferred < pCmd->size) {
DWORD len = file.write(pCmd->buffer + bytesTransferred, pCmd->size - bytesTransferred);
bytesTransferred += len;
if (!len) {
hr = ::GetLastError();
break;
}
}
break;
case VDC_Flush:
Expand All @@ -284,14 +296,18 @@ HRESULT processPipeBackup(IClientVirtualDevice* pDevice, OutputFile& file, bool
break;
}

hr = pDevice->CompleteCommand(pCmd, completionCode, bytesTransferred, 0);
HRESULT hrComplete = pDevice->CompleteCommand(pCmd, completionCode, bytesTransferred, 0);

if (!hr || bytesTransferred > 0) {
hr = hrComplete;
}

ps.accumulate(bytesTransferred);

if (!SUCCEEDED(hr)) {
// error message?
break;
}

ps.accumulate(bytesTransferred);
}

ps.finalize();
Expand Down

0 comments on commit daae2f9

Please sign in to comment.