Update of /cvsroot/pywin32/pywin32/win32/src
In directory sc8-pr-cvs1:/tmp/cvs-serv7459/src
Modified Files:
win32trace.cpp
Log Message:
Don't just die when we try and write >64k of data (now we only write a max
of 32k at a time, and sleep either 10ms or until a reader empties the
buffer, then write the next chunk.)
Add tests for the above.
Index: win32trace.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32trace.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** win32trace.cpp 15 May 2003 22:41:38 -0000 1.8
--- win32trace.cpp 31 Aug 2003 04:47:56 -0000 1.9
***************
*** 24,27 ****
--- 24,30 ----
output is discarded, and the text written to the new, empty buffer.
+ However, the most we will write at a time is "buffer_size/2" bytes, then we
+ will have a short, optimized sleep between chunks.
+
See - I told you the implementation was simple :-)
***************
*** 41,44 ****
--- 44,48 ----
const char *MUTEX_OBJECT_NAME = "PythonTraceOutputMutex";
const char *EVENT_OBJECT_NAME = "PythonTraceOutputEvent";
+ const char *EVENT_EMPTY_OBJECT_NAME = "PythonTraceOutputEmptyEvent";
// no const because of python api, this is the name of the entry
***************
*** 49,52 ****
--- 53,59 ----
// An auto-reset event so a reader knows when data is avail without polling.
HANDLE hEvent = NULL;
+ // An auto-reset event so writing large data can know when the buffer has
+ // been read.
+ HANDLE hEventEmpty = NULL;
SECURITY_ATTRIBUTES sa; // Security attributes.
***************
*** 289,311 ****
return FALSE;
}
- if (len>BUFFER_SIZE-sizeof(size_t)-1) {
- ReturnError("The data is too large.");
- return FALSE;
- }
BOOL rc = FALSE;
Py_BEGIN_ALLOW_THREADS
! if (GetMyMutex()) {
!
! size_t *pLen = (size_t *)pMapBaseWrite;
! char *buffer = (char *)(((size_t *)pMapBaseWrite)+1);
! size_t sizeLeft = (BUFFER_SIZE-sizeof(size_t)) - *pLen;
! if (sizeLeft<len)
! *pLen = 0;
!
! memcpy(buffer+(*pLen), data, len);
! *pLen += len;
! rc = ReleaseMyMutex();
! SetEvent(hEvent);
}
Py_END_ALLOW_THREADS
--- 296,324 ----
return FALSE;
}
BOOL rc = FALSE;
Py_BEGIN_ALLOW_THREADS
! const char *data_this = data;
! while (len) {
! unsigned len_this = min(len, BUFFER_SIZE/2);
! if (GetMyMutex()) {
! size_t *pLen = (size_t *)pMapBaseWrite;
! char *buffer = (char *)(((size_t *)pMapBaseWrite)+1);
! size_t sizeLeft = (BUFFER_SIZE-sizeof(size_t)) - *pLen;
! if (sizeLeft<len_this)
! *pLen = 0;
! memcpy(buffer+(*pLen), data_this, len_this);
! *pLen += len_this;
! rc = ReleaseMyMutex();
! SetEvent(hEvent);
! data_this += len_this;
! len -= len_this;
! if (len) {
! // If we had to split up the data, we can have little sleep
! // to let a reader grab the data (but if a reader empties us
! // before the timeout, then we wake up)
! WaitForSingleObject(hEventEmpty, 10);
! }
! }
}
Py_END_ALLOW_THREADS
***************
*** 345,348 ****
--- 358,362 ----
}
rc = ReleaseMyMutex();
+ SetEvent(hEventEmpty); // in case anyone wants to optimize waiting.
}
Py_END_ALLOW_THREADS
***************
*** 582,587 ****
sa.bInheritHandle = TRUE;
-
-
assert(hMutex == NULL);
hMutex = CreateMutex(&sa, FALSE, MUTEX_OBJECT_NAME);
--- 596,599 ----
***************
*** 595,598 ****
PyWin_SetAPIError("CreateEvent");
return ;
! }
}
--- 607,616 ----
PyWin_SetAPIError("CreateEvent");
return ;
! }
! assert (hEventEmpty==NULL);
! hEventEmpty = CreateEvent(&sa, FALSE, FALSE, EVENT_EMPTY_OBJECT_NAME);
! if (hEventEmpty==NULL) {
! PyWin_SetAPIError("CreateEvent");
! return ;
! }
}
|