0

I use a trivial CAsyncSocket to implement a TCP server. I cannot see any mistake here. Still, Receive returns WSAENOTSOCK:

class CMyWnd : CWnd
{
  CMySock m_sListener;
  CMySock m_sConnected;
}


CMyWnd::CMyWnd()
{
  m_sListener.SetWnd(this);
  m_sConnected.SetWnd(this);
  // ...
  m_sListener.Create(56999, SOCK_STREAM, FD_READ | FD_WRITE | FD_ACCEPT | FD_CLOSE, _T("127.0.0.1"));
  if(m_sListener.Listen() == FALSE) { exit(1)] }
}


void CMyWnd::OnReceive(void)
{
  TCHAR p[MAX_MSGLEN];
  memset(p, 0, sizeof(p));
  int nRead;
  nRead = m_sConnected.Receive(p, MAX_MSGLEN);
  if(nRead == SOCKET_ERROR)
  {
    UINT dwErr = GetLastError(); // returns WSAENOTSOCK!!
  }
}

void CMyWnd::OnAccept(void)
{
  m_sListener.Accept(m_sConnected);
}

The CMySock is just trivially inherited from CAsyncSock and passes to the window class:

 void CMySock::OnAccept(int nErrorCode)
 {
   if(m_pWnd && nErrorCode==0)
   {
     m_pWnd->OnReceive();
   }
   CAsyncSocket::OnAccept(nErrorCode);
 }

 void CMySock::OnReceive(int nErrorCode)
 {
   if(m_pAgentWnd && nErrorCode==0)
   {
     m_pWnd->OnReceive();
   }
   CAsyncSocket::OnReceive(nErrorCode);
 }

It's impossible that this returns WSAENOTSOCK here because it MUST be a socket! It is returned by accept iself and I also receive the notification when data is received.

divB
  • 896
  • 1
  • 11
  • 28

1 Answers1

0

OMG, how can that be? Look at CMySock::OnAccept. It calls OnReceive. Such a trivial error and I spent over one hour on it ...

divB
  • 896
  • 1
  • 11
  • 28