/[pengfork]/pengfork/src/p3/misc.c
ViewVC logotype

Diff of /pengfork/src/p3/misc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by chupa, Fri Sep 6 23:03:55 2002 UTC revision 1.3 by chupa, Mon Sep 9 22:59:42 2002 UTC
# Line 29  Line 29 
29    
30  #include "p3/misc.h"  #include "p3/misc.h"
31    
32  /* Synchronize the start of the buffer to something that could be a packet  /*
33     * Synchronize the start of the buffer to something that could be a packet
34   */   */
35  void  void
36  p3_sync_buffer (buffer)  p3_sync_buffer (buffer)
37       buffer_t *buffer;       buffer_t *buffer;
38  {  {
39    void *p;    char *p;
40    int len;    int len;
41      int total = 0;
42    
43    if (buffer->used < 2)    while(buffer->used > 0)
44      {      {
45        len = buffer->used;        /* Try to find a STOP byte first */
46      }        p = memchr (buffer_start (buffer), P3_STOP, buffer->used);
   else  
     {  
       p = memchr (buffer_start (buffer) + 1, P3_MAGIC, buffer->used - 1);  
47        if (p)        if (p)
48          len = (int) p - (int) buffer_start (buffer);          len = (int) p - (int) buffer_start (buffer) + 1;
49        else        else
50          len = buffer->used;          len = buffer->used;
51      
52          buffer_free (buffer, len);
53          total += len;
54          p = buffer_start (buffer);
55          /* if the start of the buffer is now a MAGIC byte this seems good */
56          if(buffer->used > 0 && p[0]==P3_MAGIC) break;
57      }      }
58    
59    debug (0, "P3 - %d bytes dropped from buffer!\n", len);    debug (3, "P3 - %d bytes dropped from buffer.\n", total);
   buffer_free (buffer, len);  
60  }  }
61    
62    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26