Using CDPipeListen Asynchronously in Windows Applications

One of the Newton 2.x OS Q&As
Copyright © 1997 Newton, Inc. All Rights Reserved. Newton, Newton Technology, Newton Works, the Newton, Inc. logo, the Newton Technology logo, the Light Bulb logo and MessagePad are trademarks of Newton, Inc. and may be registered in the U.S.A. and other countries. Windows is a registered trademark of Microsoft Corp. All other trademarks and company names are the intellectual property of their respective owners.


For the most recent version of the Q&As on the World Wide Web, check the URL: http://www.newton-inc.com/dev/techinfo/qa/qa.htm
If you've copied this file locally, click here to go to the main Newton Q&A page.
This document was exported on 7/23/97.


Using CDPipeListen Asynchronously in Windows Applications (7/15/96)

Q: I am passing in a callback function to CDPipeListen, but it never seems to be called. What is going wrong?

A: Due to a bug in CDPipeListen, the callback function never gets called in Windows applications. You will have to use a synchronous listen, then wait for the state of the DIL pipe to change before accepting the connection. The following code shows how to properly accept a connection.
anErr = CDPipeListen( gOurPipe, kDefaultTimeout, NULL, 0 );

if (!anErr) 
{
    // This code doesn't need to be executed on MacOS, but 
    // is currently required for Windows.  We need to loop,
    // waiting for the connection state to change to
    // kCDIL_ConnectPending.
    endTime = (GetTickCount()/1000) + 30;  // to timeout in 30 seconds
    while ((GetTickCount()/1000) < endTime ) 
    {
        if (CDGetPipeState( gOurPipe ) == kCDIL_ConnectPending) {
            anErr = CDPipeAccept( gOurPipe );
            break;
        } else
            CDIdle( gOurPipe );
    }
}


Note: this has been fixed in the Windows DILs 1.0.2.