Changeset 26996
- Timestamp:
- Feb 18, 2010, 5:19:29 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/libohana/src/CommOps.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libohana/src/CommOps.c
r23326 r26996 14 14 return (status); 15 15 } 16 // fprintf (stderr, "resp: %s\n", command.buffer);16 // fprintf (stderr, "resp: (%d) %s\n", command.Nbuffer, command.buffer); 17 17 18 18 /* buffer contains an EOL NULL, we can just sscan it */ … … 21 21 22 22 status = ExpectCommand (device, length, timeout, message); 23 23 24 return (status); 24 25 } … … 45 46 46 47 if (Nread > 0) { 48 // fprintf (stderr, "read %d of %d\n", Nread, length - buffer[0].Nbuffer); 47 49 buffer[0].Nbuffer += Nread; 48 50 continue; … … 50 52 51 53 if (Nread == -1) { 54 // fprintf (stderr, "errno: %d\n", errno); 55 // perror ("read error"); 52 56 switch (errno) { 53 57 case EAGAIN: … … 99 103 int SendMessageFixed (int device, int length, char *message) { 100 104 105 int status; 106 int Nbytes, Nsent; 107 struct timespec request, remain; 108 109 // fprintf (stderr, "send fixed message, length = %d\n", length); 110 101 111 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 103 147 return TRUE; 104 148 } … … 124 168 memset (string, 0, length + 1); 125 169 vsnprintf (string, length + 1, format, argp); 170 171 // fprintf (stderr, "write command, length = %d\n", length); 126 172 127 173 status = write (device, string, length);
Note:
See TracChangeset
for help on using the changeset viewer.
