Changeset 7917 for trunk/Ohana/src/libohana
- Timestamp:
- Jul 16, 2006, 10:58:49 PM (20 years ago)
- Location:
- trunk/Ohana/src/libohana
- Files:
-
- 3 edited
-
include/ohana.h (modified) (2 diffs)
-
src/CommOps.c (modified) (1 diff)
-
src/IOBufferOps.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libohana/include/ohana.h
r7039 r7917 166 166 int EmptyIOBuffer (IOBuffer *buffer, int Nmax, int fd); 167 167 void FreeIOBuffer (IOBuffer *buffer); 168 int PrintIOBuffer (IOBuffer *buffer, char *format, ...); 169 int vPrintIOBuffer (IOBuffer *buffer, char *format, va_list argp); 168 170 169 171 /* communication functions */ … … 173 175 int SendCommand (int device, int length, char *format, ...); 174 176 int SendCommandV (int device, int length, char *format, va_list argp); 177 178 char *CheckForMessage (IOBuffer *buffer); 175 179 176 180 /* -
trunk/Ohana/src/libohana/src/CommOps.c
r5273 r7917 113 113 return (TRUE); 114 114 } 115 116 /* 117 118 I need an alternative ExpectCommand function which appends to an existing buffer 119 until the complete message is ready. 120 121 A command looks like this (pre-determined length): 122 NN bytes: XXXXX\0 123 124 A message looks like this (preceded by NBYTES command) : 125 16 bytes: WORD NNN\0 126 NNN bytes: message.... \0 127 128 the expect function needs to monitor the number of bytes already received 129 we need to be able to call it repeatedly until the buffer is full. 130 131 */ 132 133 /* check if the first entry in the buffer corresponds to a message: 134 A message looks like this (preceded by NBYTES command) : 135 16 bytes: WORD NNN 136 NNN bytes: message.... 137 note that the NULL bytes are not sent 138 If a message is found, it is popped off the buffer and sent back as a 139 complete line (the length portion is dropped) 140 */ 141 142 char *CheckForMessage (IOBuffer *buffer) { 143 144 int Nbytes; 145 char command[20], *line; 146 147 if (buffer[0].Nbuffer < 16) return NULL; 148 memcpy (command, buffer[0].buffer, 16); 149 command[16] = 0; 150 151 sscanf (command, "NBYTES: %d", &Nbytes); 152 153 if (buffer[0].Nbuffer < Nbytes + 16) return NULL; 154 155 ALLOCATE (line, char, Nbytes + 1); 156 memcpy (line, &buffer[0].buffer[16], Nbytes); 157 line[Nbytes] = 0; 158 159 buffer[0].Nbuffer -= Nbytes + 16; 160 memmove (buffer[0].buffer, &buffer[0].buffer[Nbytes+16], buffer[0].Nbuffer); 161 return (line); 162 } -
trunk/Ohana/src/libohana/src/IOBufferOps.c
r5273 r7917 84 84 } 85 85 } 86 87 /* print to an IOBuffer (varargs form) */ 88 int PrintIOBuffer (IOBuffer *buffer, char *format, ...) { 89 90 int status; 91 va_list argp; 92 93 va_start (argp, format); 94 status = vPrintIOBuffer (buffer, format, argp); 95 va_end (argp); 96 return (status); 97 } 98 99 /* print to an IOBuffer (va_list form) */ 100 int vPrintIOBuffer (IOBuffer *buffer, char *format, va_list argp) { 101 102 /* add the output line to the given IOBuffer */ 103 104 int Nbyte, status; 105 char tmp, *line; 106 107 Nbyte = vsnprintf (&tmp, 0, format, argp); 108 109 if (buffer[0].Nbuffer + Nbyte + 1 >= buffer[0].Nalloc) { 110 buffer[0].Nalloc = buffer[0].Nbuffer + Nbyte + 64; 111 REALLOCATE (buffer[0].buffer, char, buffer[0].Nalloc); 112 } 113 114 vsnprintf (&buffer[0].buffer[buffer[0].Nbuffer], Nbyte + 1, format, argp); 115 buffer[0].Nbuffer += Nbyte + 1; 116 return (TRUE); 117 } 118
Note:
See TracChangeset
for help on using the changeset viewer.
