DSNetwork的讨论:其中是不是存在问题啊?
进来有时间,学习了一下DSNetwork,有些疑问:
关于bufferPool中:
1、部分代码没有看懂,我觉得有泄漏,并发现很久以前一个网友的看法与我一样,参见
http://topic.csdn.net/t/20051107/08/4375646.html
内容附在后面
2、我认为这两个变量没有必要存在
LIST_ENTRY m_Buffers ;
LIST_ENTRY m_RequestPool ;
参考MSPool也只是用了一个List,何必增加另外两个。
确实没看懂,有必要讨论一下,明白的人指教一下。
在接受端,使用双缓冲的代码,总感觉不对
CBuffer *CBufferPool::GetBuffer (
IN HANDLE hEvent,
IN DWORD dwTimeout
)
{
if(!IsListEmpty (& m_Buffers)
{
.......
}
else
{
// get a request
pBlockRequest = GetRequestLocked_ () ;
if (pBlockRequest == NULL) {
// memory allocation failure most likely
Unlock_ () ;
return NULL ;
}
// non-signal the event we'll wait on
pBlockRequest -> hEvent = hEvent ;
ResetEvent (pBlockRequest -> hEvent) ;
// insert into tail of request queue
InsertTailList (& m_Request, & pBlockRequest -> ListEntry) ;
// release the lock and wait
Unlock_ () ;
r = WaitForSingleObject (hEvent, dwTimeout) ;// dwTimeout =0
// reacquire the lock
Lock_ () ;
if (r == WAIT_TIMEOUT) {
// might have timed out and blocked on the lock aquisition while
// the BLOCK_REQUEST was being completed on the other side; if
// this is the case, we succeed the call, even though we timed
// out waiting
if (pBlockRequest -> pBuffer == NULL) {
// actual timeout; recycle the BLOCK_REQUEST and punt
RemoveEntryList (& pBlockRequest -> ListEntry) ;
RecycleRequestLocked_ (pBlockRequest) ;
Unlock_ () ;
return NULL ;
}
}
// we have a buffer, whether or not we timed out in the process of
// getting it
// we'll return this
pBuffer = pBlockRequest -> pBuffer ; //这个pBlockRequest -> pBuffer我认为始终为 NULL
// recycle the request struct
RecycleRequestLocked_ (pBlockRequest) ;
}
}
CBufferPool::Recycle (
IN CBuffer * pBuffer
)
{
LIST_ENTRY * pListEntry ;
BLOCK_REQUEST * pBlockRequest ;
Lock_ () ;
// check if there are queued outstanding requests
if (!IsListEmpty (& m_Request))
{
pListEntry = RemoveHeadList (& m_RequestPool) ; ///??????????
pBlockRequest = CONTAINING_RECORD (pListEntry, BLOCK_REQUEST, ListEntry) ;
// set the buffer and addref (BLOCK_REQUEST's)
pBlockRequest -> pBuffer = pBuffer ; //我觉得程序将无法访问pBlockRequest
pBuffer -> AddRef () ;
// signal; do this last
SetEvent (pBlockRequest -> hEvent) ;
}
}