我试图在每10ms后在套接字上发送一个文本文件。代码工作正常,并在10ms的间隔后继续通过套接字发送文本文件。但经过一段时间(比如3-4分钟后),fopen()fils(虽然fopen()工作正常一段时间)我得到一个错误“Client2.exe中0x011f28f7处的未处理异常:0xC00000FD:堆栈溢出。 “
休息test dword ptr [eax],eax ; probe page.
在“chkstk.asm”中。
可能的原因是什么? fopen()如何正常工作并在之后失败?
请帮帮我:(
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) //if file size>0
{
int bytes_read=0;
if((bytes_read=fread(file_buffer, file_size, 1, fpSend))<=0)
{
//"Unable to copy file into buffer",
}
//"File copied in Buffer",
if(sendto(socketIdentifier, file_buffer, file_size, 0, (struct sockaddr *) &AH_glb_connectedSocket, sizeof(AH_glb_connectedSocket))<0)
{
//"Not Sent"
}
else
{
//"File Sent Successfully!",
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 )
{
//window created.
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
closesocket(socketIdentifier);
WSACleanup();
return 0;
}
答案 0 :(得分:4)
我在这里看不到任何fclose()。也许你的资源耗尽了?
这听起来很相似:
Why would fopen fail to open a file that exists?
当没有完成fclose时,它最终将无法找到新的文件描述符,因为它们是有限的。