Re: WaitForSingleObeject runtime error
Larry wrote:
Hi,
I am getting this close to finish my tiny streaming server...having
said that I have a problem with the following code. It basically fires a
runtime error
...with which we really can't help you - that's OS-specific..
> when I disconect from the sever! (closing the telnet window)
I wound up finding out that the error may be fired because of this line:
"May be"? So, it's possible that it's not the call to
WaitForSingleObject but something else that screws up the memory
occupied by the actual 'eventi' map...
WaitForSingleObject(eventi[threadid], INFINITE);
If I replaceit with: Sleep(1000) everything goes ok....
Does the 'eventi' map actually contain a valid value with the key
'threadid' for passing it to 'WaitForSingleObject'? Those things need
to be checked, you know.
If access to 'data' in your 'buffer' is somehow incorrect (you need to
check), and you write beyond the boundary of 1024 elements, it's very
likely that you stomp all over the dynamically allocated memory used to
keep your 'eventi' map elements. Then attempt to access them can cause
undefined behaviour, which in your case ends up being a run-time error
reported by the OS.
[..]
struct buffer
{
unsigned char data[1024];
int bytesRecorded;
int flag;
buffer(const unsigned char * data_, const int bytesRecorded_, const
int flag_) :
bytesRecorded(bytesRecorded_), flag(flag_)
{
copy(data_, data_ + bytesRecorded_, data);
}
};
struct circular
{
circular_buffer<buffer> cb;
};
map<int, circular> users;
map<int, circular>::iterator uit;
map<int, HANDLE> eventi;
int main()
{
[..]
// thanks
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask