packet.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. typedef struct Packet Packet;
  10. typedef struct Mem Mem;
  11. typedef struct Frag Frag;
  12. enum {
  13. BigMemSize = MaxFragSize,
  14. SmallMemSize = BigMemSize/8,
  15. NLocalFrag = 2,
  16. };
  17. /* position to carve out of a Mem */
  18. enum {
  19. PFront,
  20. PMiddle,
  21. PEnd,
  22. };
  23. struct Mem
  24. {
  25. Lock lk;
  26. int ref;
  27. unsigned char *bp;
  28. unsigned char *ep;
  29. unsigned char *rp;
  30. unsigned char *wp;
  31. Mem *next;
  32. };
  33. enum {
  34. FragLocalFree,
  35. FragLocalAlloc,
  36. FragGlobal,
  37. };
  38. struct Frag
  39. {
  40. int state;
  41. Mem *mem;
  42. unsigned char *rp;
  43. unsigned char *wp;
  44. Frag *next;
  45. };
  46. struct Packet
  47. {
  48. int size;
  49. int asize; /* allocated memmory - always greater than size */
  50. Packet *next;
  51. Frag *first;
  52. Frag *last;
  53. Frag local[NLocalFrag];
  54. };