CAsyncSocket::Create() in thread causes assertion failure 
Author Message
 CAsyncSocket::Create() in thread causes assertion failure

Hi All,

I have created a UI-Thread derived from CWinThread. On reception of
a specific thread message I want to open a socket connection.

In the thread initialization I call AfxSocketInit().
When receiving the thread message I execute the following code:

myThread::OnMyThreadMessage()
{
 if (mySocket == NULL)
 {
      mySocket = new SocketClass();
 }

 mySocket->Create(); // This line causes the assertion

Quote:
}

where SocketClass is derived from CSocket.

When running this code from the de{*filter*} it works fine.
Running it directly, without the de{*filter*}, leads to an assertion failure

in sockcore.cpp, line 552

BOOL CAsyncSocket::Socket(int nSocketType, long lEvent,
 int nProtocolType, int nAddressFormat)
{
 ASSERT(m_hSocket == INVALID_SOCKET); // << assertion failure here

with a callstack as follows:

CAsyncSocket::Socket(int 1, long 63, int 0, int 2) line 552 + 28 bytes
CAsyncSocket::Create(unsigned int 0, int 1, long 63, const char *
0x00000000) line 106 + 20 bytes
CSocket::Create(unsigned int 0, int 1, const char * 0x00000000) line 45
+ 29 bytes

Stepping through the code I saw that m_hSocket is set to INVALID_SOCKET
in the constructor of CAsyncSocket and not modified until the line with
the assertion is reached. So I guess it is a problem with the use of
threads.

Has someone got an idea?
Thanks,
Joerg



Sun, 14 Sep 2003 20:34:17 GMT  
 CAsyncSocket::Create() in thread causes assertion failure

The thread has to have been created before you call AfxSockInit eg in your thread's InitInstance (not the constructor)

  Hi All,
  I have created a UI-Thread derived from CWinThread. On reception of
  a specific thread message I want to open a socket connection.

  In the thread initialization I call AfxSocketInit().
  When receiving the thread message I execute the following code:

  myThread::OnMyThreadMessage()
  {
   if (mySocket == NULL)
   {
        mySocket = new SocketClass();
   }

   mySocket->Create(); // This line causes the assertion
  }

  where SocketClass is derived from CSocket.

  When running this code from the de{*filter*} it works fine.
  Running it directly, without the de{*filter*}, leads to an assertion failure
  in sockcore.cpp, line 552

  BOOL CAsyncSocket::Socket(int nSocketType, long lEvent,
   int nProtocolType, int nAddressFormat)
  {
   ASSERT(m_hSocket == INVALID_SOCKET); // << assertion failure here

  with a callstack as follows:

  CAsyncSocket::Socket(int 1, long 63, int 0, int 2) line 552 + 28 bytes
  CAsyncSocket::Create(unsigned int 0, int 1, long 63, const char * 0x00000000) line 106 + 20 bytes
  CSocket::Create(unsigned int 0, int 1, const char * 0x00000000) line 45 + 29 bytes

  Stepping through the code I saw that m_hSocket is set to INVALID_SOCKET
  in the constructor of CAsyncSocket and not modified until the line with
  the assertion is reached. So I guess it is a problem with the use of  threads.

  Has someone got an idea?
  Thanks,
  Joerg



Mon, 15 Sep 2003 04:27:10 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Close CAsyncSocket in a thread causes an assertion

2. CAsyncSocket: debug assertion failure, line 512 in sockcore.cpp

3. PLEASE HELP: Assertion failure with CAsyncSocket (Sockcore.cpp line 483)

4. CAsyncSocket - assertion failure

5. CAsyncSocket::Close() assertion failure.

6. Why does this function cause an assertion failure?

7. delete operator causing assertion failure

8. Accessing ComboBox in dialog box causes an Assertion failure

9. These codes cause a assertion failure..

10. CRecortset::Delete causes assertion failure!

11. MFC Callback Causes Assertion Failure

12. UpdateData(FALSE) causes assertion failure

 

 
Powered by phpBB® Forum Software