Click here to Skip to main content
15,905,508 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Another InsertColumn question Pin
David Crow4-Dec-03 4:01
David Crow4-Dec-03 4:01 
QuestionReference to Variables? Pin
ypo_cnihtmarcher3-Dec-03 9:25
ypo_cnihtmarcher3-Dec-03 9:25 
AnswerRe: Reference to Variables? Pin
Christian Graus3-Dec-03 9:36
protectorChristian Graus3-Dec-03 9:36 
GeneralRe: Reference to Variables? Pin
GeMe_Hendrix3-Dec-03 11:36
GeMe_Hendrix3-Dec-03 11:36 
GeneralRe: Reference to Variables? Pin
Christian Graus3-Dec-03 11:39
protectorChristian Graus3-Dec-03 11:39 
GeneralInsertColumn ordering Pin
ns3-Dec-03 9:16
ns3-Dec-03 9:16 
GeneralRe: InsertColumn ordering Pin
David Crow3-Dec-03 10:38
David Crow3-Dec-03 10:38 
GeneralDebug assertion failed dbgheap.c! :( Pin
Kuniva3-Dec-03 9:04
Kuniva3-Dec-03 9:04 
Hi, i'm trying to write a multithreaded TCP server and it seemed to work ok now but suddenly i got this assertion error! The thing is, to test the server i connect with the windows 98 telnet application to my server. The clienthandler threads of my server continously check with select() if there is something to read on the socket. This gives me the oportunity to also check if the socket handle is not INVALID_SOCKET, since we might set it to this from somewhere else if we would like to "boot" the client and make sure the thread terminates. I get the assertion error in a number of particular cases, these are the two most common:
When i connect via telnet, type some text, then connect another one, also type some text, and then i close the first one without disconnecting properly, also the server does not see it is disconnected.
Or, when i connect, type some text, close telnet without disconnecting, and reconnect.

After these two situations it always gives me the error "Debug Assertion failed" in dbgheap.c.
This is part of my code:

DWORD WINAPI ClientHandler(void* prms)
{
	ClientInfo * clinfo = (struct ClientInfo*)prms;
	SOCKET sd = (SOCKET)clinfo->SocketHandle;

	char buffer[1024];
	int nRead = 0;
	BOOL abort = FALSE;

	do
	{
		if(sd!=INVALID_SOCKET && IsSocketReadyToRead(sd,50))
		{
			nRead = recv(sd, buffer, sizeof(buffer), 0);
			if(nRead==0)
			{
				abort = TRUE;
			}
		}
	}
	while(!abort);

	RemoveConnection(sd);

	return 0;
}

ClientInfo is just a struct with some information about each client (socket handle, thread handle, etc..)

This is what IsSocketReadyToRead() looks like:
BOOL IsSocketReadyToRead(SOCKET s, int timeout)
{
    int retval;
    fd_set* socketset;

    socketset = new fd_set;
	FD_ZERO(socketset);
	FD_SET(s, socketset);

    if( timeout!=0 )
    {
        struct timeval time;
		memset(&time,0,sizeof(struct timeval));
        time.tv_sec = 0;
        time.tv_usec = (long)timeout;
        retval = select( 0, socketset, NULL, NULL, &time );
    }
    else
    {
        struct timeval time = { 0, 0 };
        retval = select( 0, socketset, NULL, NULL, &time );
    }

	delete socketset;

	switch(retval)
	{
	case 1:
		return TRUE;
		break;
	case 0:
		return FALSE;
		break;
	case SOCKET_ERROR:
		return FALSE;
		break;
	default:
		return FALSE;
	}
}


The RemoveConnection function does not matter seeings in neither of the situations it is called.

Does anyone have any idea what might be causing this?
Oh yes btw, i also, at other times, in the same situation, did not get the assertion error, but a memory error where it gave me that "the memory could not be written." and the contents of a pointer. But i don't know if its my app or the underlying framework. Thanks for any help, if you would like to see more code, just ask.

Kuniva
--------------------------------------------
GeneralCRichEditView and jpg images Pin
Anonymous3-Dec-03 8:58
Anonymous3-Dec-03 8:58 
GeneralRe: CRichEditView and jpg images Pin
Joel Lucsy4-Dec-03 3:31
Joel Lucsy4-Dec-03 3:31 
GeneralDeleting tmp files from windows service Pin
haritadala3-Dec-03 8:32
haritadala3-Dec-03 8:32 
GeneralRe: Deleting tmp files from windows service Pin
Jörgen Sigvardsson3-Dec-03 8:54
Jörgen Sigvardsson3-Dec-03 8:54 
GeneralRe: Deleting tmp files from windows service Pin
haritadala3-Dec-03 13:13
haritadala3-Dec-03 13:13 
GeneralRe: Deleting tmp files from windows service Pin
Jörgen Sigvardsson3-Dec-03 13:21
Jörgen Sigvardsson3-Dec-03 13:21 
Questionhow can i Transfer a PictureBox picture to an array of bytes? Pin
asd17533-Dec-03 7:41
asd17533-Dec-03 7:41 
GeneralDao DB Pin
rfraser3-Dec-03 6:11
rfraser3-Dec-03 6:11 
GeneralRe: Dao DB Pin
RChin3-Dec-03 7:33
RChin3-Dec-03 7:33 
GeneralRe: Dao DB Pin
GeMe_Hendrix3-Dec-03 11:31
GeMe_Hendrix3-Dec-03 11:31 
GeneralRe: Dao DB Pin
RChin3-Dec-03 12:54
RChin3-Dec-03 12:54 
GeneralRe: Dao DB Pin
coralsnake_21-Dec-03 8:49
coralsnake_21-Dec-03 8:49 
GeneralScrolling CRichEditCtrl to the limit Pin
RickyC3-Dec-03 6:07
RickyC3-Dec-03 6:07 
GeneralCapture application start Pin
zebiloute3-Dec-03 5:45
zebiloute3-Dec-03 5:45 
GeneralRe: Capture application start Pin
Anonymous3-Dec-03 7:38
Anonymous3-Dec-03 7:38 
GeneralRe: Capture application start Pin
David Crow3-Dec-03 7:41
David Crow3-Dec-03 7:41 
GeneralRe: Capture application start Pin
Peter Molnar3-Dec-03 13:02
Peter Molnar3-Dec-03 13:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.