Click here to Skip to main content
15,919,749 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MSComm produces memory leak Pin
D.D. de Kerf31-May-01 21:26
D.D. de Kerf31-May-01 21:26 
GeneralRe: MSComm produces memory leak (the solution!) Pin
D.D. de Kerf6-Jun-01 20:56
D.D. de Kerf6-Jun-01 20:56 
GeneralDestructor not being called Pin
Miroslav Rajcic30-May-01 20:08
Miroslav Rajcic30-May-01 20:08 
GeneralRe: Destructor not being called Pin
30-May-01 20:16
suss30-May-01 20:16 
GeneralRe: Destructor not being called Pin
Miroslav Rajcic30-May-01 20:35
Miroslav Rajcic30-May-01 20:35 
GeneralRe: Destructor not being called Pin
Christian Graus30-May-01 20:41
protectorChristian Graus30-May-01 20:41 
GeneralThanks Pin
Miroslav Rajcic30-May-01 20:42
Miroslav Rajcic30-May-01 20:42 
QuestionW2K/multi-CPU overlapped sockets bug? Pin
Taka Muraoka30-May-01 19:45
Taka Muraoka30-May-01 19:45 
We have a server app that uses overlapped socket I/O that runs fine on a single-CPU machine under NT 4 and W2K and also on a dual under NT. We have just received a quad running W2K Advanced Server and our app blows up big time.

We have nailed the problem down to WSAAccept() returning 0 when nobody is trying to connect instead of -1 (i.e. INVALID_SOCKET). We tried hacking around this by checking for 0 as well as -1 but we ran into problems later on: we also receive data using overlapped I/O and when our event gets signalled we call WSAGetOverlappedResult() to find out how many bytes have arrived; this is failing with WSASYSCALLFAILURE ("A system call that should never fail has failed"!!!) and doesn't initialize the byte count variable.

We have stripped everything out into a test app, running on a single thread, as dumb and as simple as we can make it and it is still failing. We are not sure if this problem is SMP-related but that is certainly our first suspicion.

Has anyone ever seen anything like this?!?! It just occurred to me that we were using WSA- functions on a socket created by socket(), but apparently that is OK (from the MSDN: "Overlapped I/O follows the model established in Win32 and can be performed only on sockets created through the WSASocket function with the WSA_FLAG_OVERLAPPED flag set or sockets created through the socket() function").

This is our stripped-down sample app:

  // open a socket 
  cout << "Creating a socket..." << endl ; 
  SOCKET hListenSocket = socket( AF_INET , SOCK_STREAM , 0 ) ; 
  if ( hListenSocket == INVALID_SOCKET )
  {
    cout << "ERROR: Can't create the socket." << endl ; 
    exit( 1 ) ; 
  }
  cout << "- hListenSocket=" << hListenSocket << endl ; 
 
  // initialize the host address 
  struct hostent* pHostEnt = gethostbyname( pHostAddress ) ;
  if ( pHostEnt == NULL )
  {
    cout << "ERROR: Can't resolve the host name: " << pHostAddress << endl ; 
    exit( 1 ) ; 
  }
  in_addr hostAddress = *((struct in_addr *)pHostEnt->h_addr_list[0]) ;
 
  // bind the socket 
  cout << "Binding the socket." << endl ;
  sockaddr_in addr ;
  addr.sin_family = AF_INET ;
  addr.sin_addr.s_addr = hostAddress.s_addr ;
  addr.sin_port = htons( portNo ) ;
  int rc = bind( hListenSocket , (sockaddr*)&addr , sizeof(addr) ) ; 
  if ( rc != 0 )
  {
    cout << "ERROR: Can't bind the socket ; rc=" << rc << endl ; 
    exit( 1 ) ; 
  }
   
  // start listening on the socket 
  cout << "Listening on the socket..." << endl ;
  rc = listen( hListenSocket , SOMAXCONN ) ;
  if ( rc != 0 )
  {
    cout << "ERROR: Can't listen on the socket ; rc=" << WSAGetLastError() << endl ;
    exit( 1 ) ; 
  }
 
  // create an event that will be flagged when somebody tries to connect 
  WSAEVENT hConnectEvent = WSACreateEvent() ;
  rc = WSAEventSelect( hListenSocket , hConnectEvent , FD_ACCEPT ) ;
  if ( rc != 0 )
  {
    cout << "ERROR: Can't set the connect event ; rc=" << WSAGetLastError() << endl ; 
    exit( 1 ) ; 
  }
 
  // wait for a connection 
  cout << "Waiting for a connection..." << endl ; 
  SOCKET hSocket = WSAAccept( hListenSocket , NULL , NULL , NULL , NULL ) ; 
/***** FAILS HERE! 0 GETS RETURNED *****/
  if ( hSocket == INVALID_SOCKET )                                
  {
    cout << "- Connection pending..." << endl ; 
    WSAEVENT hEvents[1] ;
    hEvents[0] = hConnectEvent ;
    DWORD rc = WSAWaitForMultipleEvents( 1 , hEvents , FALSE , INFINITE , FALSE ) ; 
    if ( rc == WSA_WAIT_EVENT_0 )
    {
      cout << "Connection received." << endl ;
      hSocket = WSAAccept( hListenSocket , NULL , NULL , NULL , NULL ) ; 
      cout << "- hSocket=" << hSocket << endl ; 
      onServerConnection( hSocket ) ; 
    }
  }
  else 
  {
    cout << "- Connection received immediately ; hSocket=" << hSocket << endl ; 
    onServerConnection( hSocket ) ; 
  }

QuestionDocking Bar inside a DLL? Pin
Steve The Plant30-May-01 19:12
Steve The Plant30-May-01 19:12 
AnswerRe: Docking Bar inside a DLL? Pin
Tomasz Sowinski31-May-01 0:09
Tomasz Sowinski31-May-01 0:09 
GeneralNegative values in resource.h Pin
Nick Blumhardt30-May-01 14:55
Nick Blumhardt30-May-01 14:55 
GeneralRe: Negative values in resource.h Pin
Christian Graus30-May-01 15:15
protectorChristian Graus30-May-01 15:15 
GeneralCreating Remote Desktop Sharing Software Pin
30-May-01 14:23
suss30-May-01 14:23 
GeneralFrustration with BSTR* Pin
30-May-01 13:47
suss30-May-01 13:47 
GeneralRe: Frustration with BSTR* Pin
Christian Graus30-May-01 13:53
protectorChristian Graus30-May-01 13:53 
GeneralRe: Frustration with BSTR* Pin
30-May-01 14:00
suss30-May-01 14:00 
GeneralRe: Frustration with BSTR* Pin
Christian Graus30-May-01 14:13
protectorChristian Graus30-May-01 14:13 
GeneralTab Control Pin
Craig Phillips30-May-01 13:23
Craig Phillips30-May-01 13:23 
GeneralRe: Tab Control Pin
Christian Graus30-May-01 13:51
protectorChristian Graus30-May-01 13:51 
GeneralRe: Tab Control Pin
Craig Phillips30-May-01 23:06
Craig Phillips30-May-01 23:06 
GeneralRe: Tab Control Pin
Christian Graus30-May-01 23:17
protectorChristian Graus30-May-01 23:17 
GeneralRe: Tab Control Pin
Craig Phillips30-May-01 23:36
Craig Phillips30-May-01 23:36 
GeneralRe: Tab Control Pin
31-May-01 11:11
suss31-May-01 11:11 
GeneralCOleDateTime problem! Pin
Rickard Andersson2030-May-01 8:46
Rickard Andersson2030-May-01 8:46 
GeneralRe: COleDateTime problem! Pin
Ghazi H. Wadi30-May-01 11:50
Ghazi H. Wadi30-May-01 11:50 

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.