IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26996


Ignore:
Timestamp:
Feb 18, 2010, 5:19:29 PM (16 years ago)
Author:
eugene
Message:

check for bytes sent and loop until complete message is sent

File:
1 edited

Legend:

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

    r23326 r26996  
    1414    return (status);
    1515  }
    16   // fprintf (stderr, "resp: %s\n", command.buffer);
     16  // fprintf (stderr, "resp: (%d) %s\n", command.Nbuffer, command.buffer);
    1717
    1818  /* buffer contains an EOL NULL, we can just sscan it */
     
    2121 
    2222  status = ExpectCommand (device, length, timeout, message);
     23
    2324  return (status);
    2425}
     
    4546   
    4647    if (Nread > 0) {
     48      // fprintf (stderr, "read %d of %d\n", Nread, length - buffer[0].Nbuffer);
    4749      buffer[0].Nbuffer += Nread;
    4850      continue;
     
    5052
    5153    if (Nread == -1) {
     54      // fprintf (stderr, "errno: %d\n", errno);
     55      // perror ("read error");
    5256      switch (errno) {
    5357        case EAGAIN:
     
    99103int SendMessageFixed (int device, int length, char *message) {
    100104
     105  int status;
     106  int Nbytes, Nsent;
     107  struct timespec request, remain;
     108
     109  // fprintf (stderr, "send fixed message, length = %d\n", length);
     110
    101111  if (!SendCommand (device, 16, "NBYTES: %6d", length)) return FALSE;
    102   if (!SendCommand (device, length, message)) return FALSE;
     112
     113  /* avoid blocking on waitpid, test every 1000 usec, up to timeout msec */
     114  request.tv_sec = 0;
     115  request.tv_nsec = 1000000;
     116
     117  Nsent = 0;
     118  while (Nsent < length) {
     119    Nbytes = write (device, &message[Nsent], length - Nsent);
     120   
     121    // fprintf (stderr, "sent %d of %d\n", Nbytes, length - Nsent);
     122
     123    if (Nbytes > 0) {
     124      Nsent += Nbytes;
     125      continue;
     126    }
     127
     128    if (Nbytes == -1) {
     129      // fprintf (stderr, "errno: %d\n", errno);
     130      // perror ("send error");
     131      switch (errno) {
     132        case EAGAIN:
     133        case EIO:
     134          /** no data available in pipe, wait a bit, check for timeout **/
     135          nanosleep (&request, &remain);
     136          break;
     137        default:
     138          /** error reading from pipe **/
     139          perror ("SendMessageFixed write error");
     140          return FALSE;
     141      }
     142    }
     143    if (Nbytes == 0) return FALSE;
     144  }
     145  // if (!SendCommand (device, length, message)) return FALSE;
     146
    103147  return TRUE;
    104148}
     
    124168  memset (string, 0, length + 1);
    125169  vsnprintf (string, length + 1, format, argp);
     170
     171  // fprintf (stderr, "write command, length = %d\n", length);
    126172
    127173  status = write (device, string, length);
Note: See TracChangeset for help on using the changeset viewer.