I am trying to send a text file at a socket after every 10ms. The code works fine and keeps on sending the text file over the socket after an interval of 10ms. But after some period of time (like after 3-4 minutes), fopen() fils (though fopen() works fine for some duration) and I get an error "Unhandled exception at 0x011f28f7 in Client2.exe: 0xC00000FD: Stack overflow." and a break at
test dword ptr [eax],eax ; probe page.
in "chkstk.asm".
what could be the possible reason for this? How fopen() works fine for sometime and fails afterwards?
Please help me :(
CODE:
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
char timer[1000];
switch(msg)
{ case WM_TIMER:
switch(wParam)
{
case IDT_TIMER1:
{
FILE *fpSend ;
if((fpSend = fopen("Client4.txt", "r+b")) == NULL)
{
MessageBox( NULL,
"Unable to open the File",
"Error!",
MB_ICONEXCLAMATION |
MB_OK);
exit(EXIT_FAILURE);
}
char file_buffer[100000];
fseek(fpSend, 0, SEEK_END);
size_t file_size = ftell(fpSend);
fseek(fpSend, 0, SEEK_SET);
if(file_size>0)
{
int bytes_read=0;
if((bytes_read=fread(file_buffer, file_size, 1, fpSend))<=0)
{
}
if(sendto(socketIdentifier, file_buffer, file_size, 0, (struct sockaddr *) &AH_glb_connectedSocket, sizeof(AH_glb_connectedSocket))<0)
{
}
else
{
sendCount = sendCount+1;
memset(file_buffer, 0, sizeof(file_buffer));
}
}
break;
default:
return 0;
}
break;
}
}
int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
closesocket(socketIdentifier);
WSACleanup();
return 0;
}