recv() in new thread does not block...

Hey... Thread-Question again^^...

In my chat prog, i am beginnning a thread for every new accepted Connection...

and in that thread i start receiving data by using "recv()"... as i read in the msdn "recv()" is a blocking function...

but in my thread it does not block and says it receives data while my client did not send any:(
Last edited on
Could you be listening on a port that's being used? Although I'm not sure that makes a difference.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//Check for incoming connections
		if(c < 64)										//Check for maximum connection
		{
			//Accept Connection
			Clients[c] = accept(AcceptSocket, NULL,NULL);

			if(Clients[c] == INVALID_SOCKET)
			{
				WaitForSingleObject(outMutex,INFINITE);
				cerr << "\nError Accepting Connection\n";
				ReleaseMutex(outMutex);
			}
			else
			{
				cout << "Connection Accepted\n\n";
				//Pass socket to new thread
				_beginthread(DX_Func,NULL,(void*)Clients[c]);
				c++;
			}
		}		

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
void DX_Func(void* v)
{
	SOCKET client;
	int threadRC = 0;					//Error Return Code
	char cBuf[256] = "";				//Buffer
	
	//Receive Data
	client = (SOCKET)v;
	/*do
	{*/
		threadRC = recv(client, cBuf, sizeof(cBuf),0);

		//Check for Errors
		if(threadRC == 0 || threadRC == SOCKET_ERROR)
		{
			switch(threadRC)
			{
			case 0:
				WaitForSingleObject(outMutex,INFINITE);
				cerr << "\nClient Returns 0 Data\n";
				ReleaseMutex(outMutex);
				break;
			case SOCKET_ERROR:
				WaitForSingleObject(outMutex,INFINITE);
				cerr << "\nClient Error\n";
				ReleaseMutex(outMutex);
				break;
			};
		}
		else
		{
			cout << "Received Data\n";
			WaitForSingleObject(copybufferMutex, INFINITE);
			strcpy(::outBuf,cBuf);		//Copy Buffer
			ReleaseMutex(copybufferMutex);
			boutBuf = true;
		}
	//}while(rc!=0);

	_endthread();

}


thats my code... and it always outs :"Received Data"... even if i dont send some...
Last edited on
found out what happened... my client did send empty data with getline, because of some "\n" left in the input buffer...^^
Topic archived. No new replies allowed.