home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 April: Mac OS SDK / Dev.CD Apr 97 SDK1.toast / Development Kits (Disc 1) / Open Transport / Sample Code / DTS Sample Code / Option Management Samples / SetIntervalOptionSample.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-19  |  1.9 KB  |  71 lines  |  [TEXT/CWIE]

  1. #include <OpenTransport.h>            // open transport files            
  2. #include <OpenTptAppletalk.h>
  3.  
  4. OSStatus DoNegotiateIntervalOption(EndpointRef ep, UInt32 interval);
  5.  
  6. /*
  7.     Sample function to set the OPT_INTERVAL option for an ATP 
  8.     endpoint.  This function can also be used by PAP endpoints prior to
  9.     connecting to a printer to reduce the time delay when a lost packet
  10.     occurs.
  11.     
  12.     Unless explicitely defined by XTI, all Open Transport options
  13.     use a kOTFourByteOptionSize buffer.
  14.     
  15.     Input
  16.     EndpointRef ep - endpoint on which to set EOM option on
  17.     UInt32 interval - expected interval in milliseconds
  18.  
  19.    Return: kOTNoError indicates that the option was successfully negotiated
  20.                OSStatus is an error if < 0, otherwise, the status field is
  21.                returned and is > 0.
  22.     
  23. */
  24. OSStatus DoNegotiateIntervalOption(EndpointRef ep, UInt32 interval)
  25.  
  26. {
  27.     UInt8        buf[kOTFourByteOptionSize];    // define buffer for fourByte Option size
  28.     TOption*    opt;                        // option ptr to make items easier to access
  29.     TOptMgmt    req;
  30.     TOptMgmt    ret;
  31.     OSStatus    err;
  32.     Boolean        isAsync = false;
  33.     
  34.     opt = (TOption*)buf;                    // set option ptr to buffer
  35.     req.opt.buf    = buf;
  36.     req.opt.len    = sizeof(buf);
  37.     req.flags    = T_NEGOTIATE;                // negotiate for rawmode option
  38.  
  39.     ret.opt.buf = buf;
  40.     ret.opt.maxlen = kOTFourByteOptionSize;
  41.     
  42.  
  43.     opt->level    = ATK_ATP;                    // dealing with ATP level 
  44.     opt->name    = OPT_INTERVAL;
  45.     opt->len    = kOTFourByteOptionSize;
  46.     opt->status = 0;
  47.     *(UInt32*)opt->value = interval;        // set the desired interval in milliseconds
  48.     
  49.     if (OTIsSynchronous(ep) == false)        // check whether ep sync or not
  50.     {
  51.         isAsync = true;                        // set flag if async
  52.         OTSetSynchronous(ep);                // set endpoint to sync    
  53.     }
  54.                 
  55.     err = OTOptionManagement(ep, &req, &ret);
  56.     
  57.     if (isAsync == true)                    // restore ep state if necessary
  58.         OTSetAsynchronous(ep);
  59.     
  60.         // if no error then return the option status value
  61.     if (err == kOTNoError)
  62.     {
  63.         if (opt->status != T_SUCCESS)
  64.             err = opt->status;
  65.         else
  66.             err = kOTNoError;
  67.     }
  68.         
  69.     return err;
  70. }
  71.