Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix upload bug #46

Merged
merged 1 commit into from
Mar 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions TOSMBClient/TOSMBSessionUploadTask.m
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,19 @@ - (void)performTaskWithOperation:(NSBlockOperation * _Nonnull __weak)weakOperati
NSUInteger bufferSize = self.data.length;
void *buffer = malloc(bufferSize);
[self.data getBytes:buffer length:bufferSize];
size_t uploadBufferLimit = MIN(bufferSize, 65471);
// change the limit size to 63488(62KB)
// (if still crash, change the limit size < 63488)
size_t uploadBufferLimit = MIN(bufferSize, 63488);

ssize_t bytesWritten = 0;
ssize_t totalBytesWritten = 0;

do {
bytesWritten = smb_fwrite(self.smbSession, fileID, buffer, uploadBufferLimit);
// change the the size of last part
if (bufferSize - totalBytesWritten < uploadBufferLimit) {
uploadBufferLimit = bufferSize - totalBytesWritten;
}
bytesWritten = smb_fwrite(self.smbSession, fileID, buffer+totalBytesWritten, uploadBufferLimit);
if (bytesWritten < 0) {
[self fail];
[self didFailWithError:errorForErrorCode(TOSMBSessionErrorCodeFileDownloadFailed)];
Expand Down