我试图每 10 毫秒后在套接字上发送一个文本文件。该代码工作正常,并在 10 毫秒的间隔后继续通过套接字发送文本文件。但经过一段时间(如 3-4 分钟后),fopen() 文件(尽管 fopen() 在一段时间内工作正常)并且我收到错误“Client2.exe 中 0x011f28f7 处的未处理异常:0xC00000FD:堆栈溢出。 " 休息一下
test dword ptr [eax],eax ; probe page.
在“chkstk.asm”中。
这可能是什么原因?fopen() 如何在一段时间内正常工作并在之后失败?
请帮我 :(
代码:
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;
}