IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7939


Ignore:
Timestamp:
Jul 19, 2006, 10:27:38 AM (20 years ago)
Author:
eugene
Message:

better error condition handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libohana/src/CommOps.c

    r7929 r7939  
    11# include <ohana.h>
     2
     3// XXX this is somewhat poor: the Send commands return TRUE / FALSE for success/failure
     4// the Expect commands return 0 for success, -N for different errors
    25
    36int ExpectMessage (int device, double timeout, IOBuffer *message) {
     
    710
    811  status = ExpectCommand (device, 16, timeout, &command);
    9   if (status != 0) {
     12  if (status) {
    1013    FreeIOBuffer (&command);
    1114    return (status);
     
    8285
    8386  va_start (argp, format);
    84   SendCommand (device, 16, "NBYTES: %6d", Nbyte);
    85   status = SendCommandV (device, Nbyte, format, argp);
     87  if (!SendCommand (device, 16, "NBYTES: %6d", Nbyte)) goto escape;
     88  if (!SendCommandV (device, Nbyte, format, argp)) goto escape;
    8689  va_end (argp);
    87   return (status);
     90  return TRUE;
     91
     92escape:
     93  va_end (argp);
     94  return FALSE;
    8895}
    8996
     
    9198int SendMessageFixed (int device, int length, char *message) {
    9299
    93   int status;
    94 
    95   status = SendCommand (device, 16, "NBYTES: %6d", length);
    96   status = SendCommand (device, length, message);
    97   return (status);
     100  if (!SendCommand (device, 16, "NBYTES: %6d", length)) return FALSE;
     101  if (!SendCommand (device, length, message)) return FALSE;
     102  return TRUE;
    98103}
    99104
     
    111116int SendCommandV (int device, int length, char *format, va_list argp) {
    112117
     118  int status;
    113119  char *string;
    114120
     
    118124  vsnprintf (string, length + 1, format, argp);
    119125
    120   write (device, string, length);
     126  status = write (device, string, length);
    121127  free (string);
     128
     129  if (status == -1) return FALSE;
    122130  return (TRUE);
    123131}
Note: See TracChangeset for help on using the changeset viewer.