@@ -286,7 +286,6 @@ NAN_METHOD(Write) {
286
286
}
287
287
288
288
WriteBaton* baton = new WriteBaton ();
289
- memset (baton, 0 , sizeof (WriteBaton));
290
289
baton->fd = fd;
291
290
baton->buffer .Reset (buffer);
292
291
baton->bufferData = bufferData;
@@ -320,14 +319,14 @@ DWORD __stdcall WriteThread(LPVOID param) {
320
319
WriteBaton* baton = static_cast <WriteBaton*>(param);
321
320
322
321
OVERLAPPED* ov = new OVERLAPPED;
323
- memset (ov, 0 , sizeof (ov ));
322
+ memset (ov, 0 , sizeof (OVERLAPPED ));
324
323
ov->hEvent = static_cast <void *>(baton);
325
324
326
325
while (!baton->complete ) {
327
326
char * offsetPtr = baton->bufferData + baton->offset ;
328
327
// WriteFileEx requires calling GetLastError even upon success. Clear the error beforehand.
329
328
SetLastError (0 );
330
- WriteFileEx ((HANDLE)baton->fd , offsetPtr, static_cast <DWORD>(baton->bufferLength ), ov, WriteIOCompletion);
329
+ WriteFileEx ((HANDLE)baton->fd , offsetPtr, static_cast <DWORD>(baton->bufferLength - baton-> offset ), ov, WriteIOCompletion);
331
330
// Error codes when call is successful, such as ERROR_MORE_DATA.
332
331
DWORD lastError = GetLastError ();
333
332
if (lastError != ERROR_SUCCESS) {
@@ -350,6 +349,7 @@ void EIO_AfterWrite(uv_async_t* req) {
350
349
Nan::HandleScope scope;
351
350
WriteBaton* baton = static_cast <WriteBaton*>(req->data );
352
351
WaitForSingleObject (baton->hThread , INFINITE);
352
+ CloseHandle (baton->hThread );
353
353
delete req;
354
354
355
355
v8::Local<v8::Value> argv[1 ];
@@ -404,7 +404,6 @@ NAN_METHOD(Read) {
404
404
}
405
405
406
406
ReadBaton* baton = new ReadBaton ();
407
- memset (baton, 0 , sizeof (ReadBaton));
408
407
baton->fd = fd;
409
408
baton->offset = offset;
410
409
baton->bytesToRead = bytesToRead;
@@ -434,6 +433,7 @@ void __stdcall ReadIOCompletion(DWORD errorCode, DWORD bytesTransferred, OVERLAP
434
433
return ;
435
434
}
436
435
if (bytesTransferred) {
436
+ baton->bytesToRead -= bytesTransferred;
437
437
baton->bytesRead += bytesTransferred;
438
438
baton->offset += bytesTransferred;
439
439
}
@@ -454,6 +454,7 @@ void __stdcall ReadIOCompletion(DWORD errorCode, DWORD bytesTransferred, OVERLAP
454
454
char * offsetPtr = baton->bufferData + baton->offset ;
455
455
456
456
// ReadFile, unlike ReadFileEx, needs an event in the overlapped structure.
457
+ memset (ov, 0 , sizeof (OVERLAPPED));
457
458
ov->hEvent = CreateEvent (NULL , TRUE , FALSE , NULL );
458
459
if (!ReadFile ((HANDLE)baton->fd , offsetPtr, baton->bytesToRead , &bytesTransferred, ov)) {
459
460
errorCode = GetLastError ();
@@ -526,6 +527,7 @@ void EIO_AfterRead(uv_async_t* req) {
526
527
Nan::HandleScope scope;
527
528
ReadBaton* baton = static_cast <ReadBaton*>(req->data );
528
529
WaitForSingleObject (baton->hThread , INFINITE);
530
+ CloseHandle (baton->hThread );
529
531
delete req;
530
532
531
533
v8::Local<v8::Value> argv[2 ];
0 commit comments