- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我收到以下错误:
Debug Assertion Failed. Expression (stream !=NULL) File: f:\dd\vctools/crty_bld/self_x86\crt\src\fwrite.c
创建 4 个线程时 CPU 使用率 100%。该代码最初在一段时间内运行良好,然后出现此错误。
该代码是使用 WSAWaitforMultipleEvents() 的 UDP 单服务器/多客户端应用程序。
编辑:
调试器在 fwrite.c 中触发断点
if(size ==0 || count == 0)
return 0;
// just checking for stream != NULL here
// rest of the validation is in _fwrite_nolock()
**_VALIDATE_RETURN( (stream != NULL) ,EINVAL, 0);** /*Debugger triggered a break point here*/
_lock_str(stream);
所有文件都在一个单独的文件夹中,该文件夹使用 fopen() 打开。当只打开两个文件时,它工作正常,但是当打开两个以上文件时,就会出错。
代码太长不知道应该分享哪一部分:(
实际上有 3 个 ReceiveThread,每个 Receive Thread 都有自己的 sendThread。
接收线程只持续接收缓冲区并持续写入文本文件。如果接收到 EOF 或 EXIT,则接收线程应终止自身及其 SendThread。
另一方面,发送线程只会继续从文本文件中读取并继续在套接字上发送。
DWORD WINAPI sendAllThreadProcedure(LPVOID param)
{
threadDetailStruct* myDetailStruct = (threadDetailStruct*) (param);
int threadNumber,portNumber;
char *ipNumber;
SOCKADDR_IN sendSocket = myDetailStruct->cliSock;
SOCKET sendSocketIdentifier = myDetailStruct->cliSockIdentifier;
threadNumber = myDetailStruct->threadNum;
char clientPort[32],*clientIP = inet_ntoa(sendSocket.sin_addr);
int cliPort = ntohs(sendSocket.sin_port);
itoa(cliPort,clientPort,10);
//=======================================================================
int clientSocketLength = sizeof(SOCKADDR_IN);
char receiveBuffer[10000];
int recv_len=0;
//=======================================================================
char file[32]="File.txt";
int sendCount=0;
FILE *fpSend;
while(1)
{
if(WaitForSingleObject(terminate_thread_event[threadNumber],0) == WAIT_OBJECT_0)
{
ResetEvent(terminate_thread_event[threadNumber]);
break;
}
if((fpSend = fopen(TEXT(fileName), "r+b")) == NULL)
{
//"Unable to open the File"
continue;
}
else
{
char file_buffer[10000];
int bytes_read=0;
char new_buffer[1000] = "FILE",send[1000];
if(sendto(sendSocketIdentifier, new_buffer, sizeof(new_buffer), 0, (struct sockaddr *) &sendSocket, sizeof(sendSocket))<0)
{
//FILE MEssage NOT SENNT!"
continue;
}
else
{
while(fpSend!=NULL)
{
if(WaitForSingleObject(terminate_thread_event[threadNumber],0) == WAIT_OBJECT_0)
{
ResetEvent(terminate_thread_event[threadNumber]);
closesocket(sendSocketIdentifier);
fclose(fpSend);
return 0;
}
if((bytes_read=fread(file_buffer, sizeof(char), 5, fpSend))<=0)
{
if(feof(fpSend))
{
char new_buffer[1000] = "EOF",send[1000],exit_message[12];
if(sendto(sendSocketIdentifier, new_buffer, sizeof(new_buffer), 0, (struct sockaddr *) &sendSocket, sizeof(sendSocket))<0)
{
//"EOF NOT SENNT!"
break;
}
fclose(fpSend);
break;
}
else
{
/*Unable to copy file into buffer*/
fclose(fpSend);
break;
}
}
else
{
if(sendto(sendSocketIdentifier, file_buffer, bytes_read, 0, (struct sockaddr *) &sendSocket, sizeof(sendSocket))<0)
{
//"Bytes read from File NOT SENT!"
fclose(fpSend);
break;
}
else
{
sendCount = sendCount+1;
}
}
}
}
Sleep(100);
closesocket(sendSocketIdentifier);
return 0;
}
// ====================
// RECEIVE Thread
DWORD WINAPI newrecvThreadProcedure(LPVOID param)
{
newRecvThreadDetailStruct* myDetailStruct = (newRecvThreadDetailStruct*) (param);
char newDetail[256], threadNumber_char[12], ipNumber[32],
*detail = myDetailStruct>newsocketDetail;
int portNumber,threadNumber_int = myDetailStruct->threadNum;
sscanf(detail,"%s %d",ipNumber,&portNumber);
itoa(threadNumber_int,threadNumber_char,10);
strcpy(newDetail,threadNumber_char);
strcat(newDetail," ");
strcat(newDetail,detail);
struct node *cur, *newNode;
EnterCriticalSection(&cs);
cur =cread();
cur->data = newDetail;
cur->n=NULL;
push(cur);
newNode = pop();
MessageBox( NULL,"PUSH DONE!","PUSH!",MB_ICONEXCLAMATION | MB_OK);
if (ResetEvent(data_available_event) == 0) // signal sender thread that data is available
{
MessageBox( NULL,"RESET Event is not Set","Failed!",MB_ICONEXCLAMATION | MB_OK);
}
LeaveCriticalSection(&cs);
char file[64] = client.txt;
//====================================================================
// Creating New Socket Now
WSADATA wsa;
//Initialise winsock//
if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
{
char err[128];
itoa(WSAGetLastError(),err,10);
MessageBox( NULL,
err,
"WinSock Initialization FAILED",
MB_ICONINFORMATION);
exit(EXIT_FAILURE);
}
//Create a socket//
SOCKET newSocketIdentifier;
SOCKADDR_IN newSocket;
if((newSocketIdentifier = socket(AF_INET , SOCK_DGRAM , 0 )) == INVALID_SOCKET)
{
// "Socket Creation Failed",
exit(EXIT_FAILURE);
}
//Socket Created//
//Prepare the sockaddr_in structure//
newSocket.sin_family = AF_INET;
newSocket.sin_addr.s_addr = INADDR_ANY;
newSocket.sin_port = htons(portNumber);
//Bind//
if( bind(newSocketIdentifier ,(struct sockaddr *)&newSocket, sizeof(SOCKADDR_IN)) == SOCKET_ERROR)
{
//"BIND FAILED inside Thread"
}
//Bind Done//
int waitRet;
WSAEVENT hEvent = WSACreateEvent();
WSANETWORKEVENTS events;
WSAEventSelect(newSocketIdentifier, hEvent, FD_READ | FD_WRITE);
SOCKADDR_IN clientSocket;
int clientSocketLength = sizeof(SOCKADDR_IN);
char receiveBuffer[3000]={0};
int recv_len = 0,receiveCount = 0;
while(1)
{
waitRet = WSAWaitForMultipleEvents(1, &hEvent, FALSE, INFINITE, FALSE);
//WSAResetEvent(hEvent);
if(WSAEnumNetworkEvents(newSocketIdentifier,hEvent,&events) == SOCKET_ERROR)
{
//"FAILURE"
continue;
}
else
{ //else event occurred starts
if(events.lNetworkEvents & FD_READ)
{
if((recv_len = recvfrom(newSocketIdentifier, receiveBuffer, sizeof(receiveBuffer), 0, (struct sockaddr *) &clientSocket, &clientSocketLength)) == SOCKET_ERROR)
{
continue;
}
else
{
if(memcmp(receiveBuffer,"NewSocket",9) == 0)
{
if(sendto(newSocketIdentifier, "NewSocket ACK", sizeof("NewSocket ACK"), 0, (struct sockaddr *) &clientSocket, sizeof(clientSocket))<0)
{
//"NewSocket ACK not SENNT!",err,MB_ICONEXCLAMATION | MB_OK);
continue;
}
else
{
break;
}
}
}
}
}
}
threadDetailStruct threadDetail;
threadDetail.cliSock = clientSocket;
threadDetail.cliSockIdentifier = newSocketIdentifier;
threadDetail.threadNum = threadNumber_int;
AHN_glb_sendAllThreadHandle[threadNumber_int] = CreateThread( NULL,
0,
sendAllThreadProcedure,
(LPVOID)&threadDetail,
0,
&idThread[threadNumber_int]
);
while(1)
{
waitRet = WSAWaitForMultipleEvents(1, &hEvent, FALSE, INFINITE, FALSE);
//WSAResetEvent(hEvent);
if(WSAEnumNetworkEvents(newSocketIdentifier,hEvent,&events) == SOCKET_ERROR)
{
// "FAILURE"
continue;
}
else
{ //else event occurred starts
if(events.lNetworkEvents & FD_READ)
{ //check for network event starts
//FD_READ
if((recv_len = recvfrom(newSocketIdentifier, receiveBuffer, sizeof(receiveBuffer), 0, (struct sockaddr *) &clientSocket, &clientSocketLength)) == SOCKET_ERROR)
{
//"after FD READ Could not Receive Data"
continue;
}
if(memcmp(receiveBuffer,"EXIT",4) == 0)
{
SetEvent(terminate_thread_event[threadNumber_int]);
}
if(memcmp(receiveBuffer,"FILE",4) == 0)
{
FILE *fprecv = fopen(TEXT(file),"wb");
while(1)
{
waitRet = WSAWaitForMultipleEvents(1, &hEvent, FALSE, 0, FALSE);
if(WSAEnumNetworkEvents(newSocketIdentifier,hEvent,&events) == SOCKET_ERROR)
{
fclose(fprecv);
break;
}
else
{
if(events.lNetworkEvents & FD_READ)//else event occurred starts
{
if((recv_len = recvfrom(newSocketIdentifier, receiveBuffer, sizeof(receiveBuffer), 0, (struct sockaddr *) &clientSocket, &clientSocketLength)) == SOCKET_ERROR)
{ MessageBox( NULL,"error","Data Reception Failed",MB_ICONINFORMATION);
fclose(fprecv);
exit(EXIT_FAILURE);
break;
}
receiveCount = recv_len+receiveCount;
if(memcmp(receiveBuffer,"EXIT",4) == 0)
{
SetEvent(terminate_thread_event[threadNumber_int]);
fclose(fprecv);
return 0;
}
if(memcmp(receiveBuffer,"EOF",3) == 0)
{
fclose(fprecv);
break;
}
if(memcmp(receiveBuffer,"FILE",4) == 0)
{
fclose(fprecv);
remove(TEXT(file));
fprecv = fopen(TEXT(file),"wb");
continue;
}
**if(fwrite(receiveBuffer, 1, recv_len, fprecv)<0)
{
MessageBox( NULL,"problem while writing file","Error!",MB_ICONINFORMATION);
fclose(fprecv);
break;
}**
} //if FD_READ
}// else network event receievd ENDS
}// While(1) for receiveing File Ends
FILE *fp1 ;
if((fp1 = fopen(TEXT(file), "rb")) == NULL)
{
MessageBox( NULL,"Unable to open the File","Error!",MB_ICONEXCLAMATION |MB_OK);
break;
}
char filecmp[1000];
strcpy(filecmp,"Client");
strcat(filecmp,threadNumber_char);
strcat(filecmp,"Original");
strcat(filecmp,".txt");
FILE *fp2 ;
if((fp2 = fopen(TEXT(filecmp), "rb")) == NULL)
{
MessageBox( NULL,"Unable to open the Original File","Error!",MB_ICONEXCLAMATION | MB_OK);
break;
}
int ch1 = getc( fp1 ) ;
int ch2 = getc( fp2 ) ;
while( (ch1!=EOF) && (ch2!=EOF) && (ch1 == ch2))
{
ch1 = getc(fp1);
ch2 = getc(fp2) ;
}
char display[3000];
strcpy(display,file);
strcat(display," Received and ");
strcat(display,filecmp);
int idx=GetWindowTextLength(AHN_glb_resultWindowHandle);
SendMessage(AHN_glb_resultWindowHandle,EM_SETSEL,idx,idx);
SendMessage(AHN_glb_resultWindowHandle,EM_REPLACESEL,0,(LPARAM)"\r\n");
if (ch1 != ch2)
{
SendMessage(AHN_glb_resultWindowHandle,EM_REPLACESEL,0,(LPARAM)"\r\n");
SendMessage(AHN_glb_resultWindowHandle,EM_REPLACESEL,0,(LPARAM)" ");
SendMessage(AHN_glb_resultWindowHandle,EM_REPLACESEL,0,(LPARAM)TEXT(display));
SendMessage(AHN_glb_resultWindowHandle,EM_REPLACESEL,0,(LPARAM)" are Not Identical");
}
else if (ch1 == ch2)
{
SendMessage(AHN_glb_resultWindowHandle,EM_REPLACESEL,0,(LPARAM)"\r\n");
SendMessage(AHN_glb_resultWindowHandle,EM_REPLACESEL,0,(LPARAM)" ");
SendMessage(AHN_glb_resultWindowHandle,EM_REPLACESEL,0,(LPARAM)TEXT(display));
SendMessage(AHN_glb_resultWindowHandle,EM_REPLACESEL,0,(LPARAM)" are Identical");
}
fclose ( fp1 );
fclose ( fp2 );
} //if memecmp == FILE ENDS
} //if FD_READ ENDS
}// else if event occurred ENDS
}//while(1) ENDS
return 0;
}
// ===============================================================================================================
最佳答案
你需要检查
FILE *fprecv = fopen(TEXT(file),"wb");
确保它没有返回错误。另外,请修正您的缩进。这个逻辑很难理解。
关于c - 调试断言失败。表达式(流!= NULL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17037458/
最近开始学习oracle和sql。 在学习的过程中,我遇到了几个问题,我的 friend 在接受采访时被问到这些问题。 SELECT * FROM Employees WHERE NULL IS N
这个问题在这里已经有了答案: Can we subtract NULL pointers? (4 个回答) 关闭 2 个月前。 是否定义了NULL - NULL? (char *)NULL - (ch
是否有推荐的方法(根据 .net Framework 指南)检查 null,例如: if (value == null) {//code1} else {//code2} 或 if (value !=
我正在尝试将值插入数据库,但出现这样的错误任何人都可以告诉我为什么该值为空,如下所示: An exception occurred while executing 'INSERT INTO perso
这个问题在这里已经有了答案: String concatenation with a null seems to nullify the entire string - is that desire
您好,我正在 Android 联系人搜索模块中工作。我正在查询下方运行。 cur = context.getContentResolver().query(ContactsContract.Data.
下面的 SQL 表定义说明了从我的 MYSQL 数据库创建表的语句之一,该数据库是由我公司的前开发人员开发的。 DROP TABLE IF EXISTS `classifieds`.`category
我主要有应用程序开发背景。在编程语言中 variable == null或 variable != null有效。 当涉及到 SQL 时,以下查询不会给出任何语法错误,但也不会返回正确的结果。 sel
我在尝试检查某些元素是否为 NULL 时遇到段错误或不。任何人都可以帮忙吗? void addEdge(int i, int j) { if (i >= 0 && j > 0)
在 SQL 服务器中考虑到以下事实:Col1 和 Col2 包含数值和 NULL 值 SELECT COALESCE(Col1,Col2) 返回一个错误:“COALESCE 的至少一个参数必须是一个不
在 SQL 服务器中考虑到以下事实:Col1 和 Col2 包含数值和 NULL 值 SELECT COALESCE(Col1,Col2) 返回一个错误:“COALESCE 的至少一个参数必须是一个不
下面查询的关系代数表达式是什么?我找不到“Is Null”的表达式。 SELECT reader.name FROM reader LEFT JOIN book_borrow ON reader.ca
我正在尝试使用三元运算符来检查值是否为 null 并返回一个表达式或另一个。将此合并到 LINQ 表达式时,我遇到的是 LINQ 表达式的 Transact-SQL 转换试图执行“column = n
我在给定的代码中看到了以下行: select(0, (fd_set *) NULL, (fd_set *) NULL, (fd_set *) NULL, &timeout); http://linux
var re = /null/g; re.test('null null'); //> true re.test('null null'); //> true re.test('null null')
这个问题在这里已经有了答案: 关闭 13 年前。 我今天避开了一场关于数据库中空值的激烈辩论。 我的观点是 null 是未指定值的极好指示符。团队中有意见的其他每个人都认为零和空字符串是可行的方法。
由于此错误,我无法在模拟器中运行我的应用: Error:null value in entry: streamOutputFolder=null 或 gradle - Error:null value
我正在尝试在 Android 应用程序中创建电影数据库,但它返回错误。知道这意味着什么吗? public Cursor returnData() { return db.query(TABLE
我一直在检查浏览器中的日期函数以及运行时间 new Date (null, null, null); 在开发工具控制台中,它给出了有效的日期 Chrome v 61 回归 Sun Dec 31 189
为什么 NA==NULL 会导致 logical (0) 而不是 FALSE? 为什么 NULL==NULL 会导致 logical(0) 而不是 TRUE? 最佳答案 NULL 是一个“零长度”对象
我是一名优秀的程序员,十分优秀!