mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2025-08-03 21:14:40 +08:00
Adpated comments to match Doxygen/JavaDoc style.
This commit is contained in:
parent
8bb3cab9d2
commit
5e13b9528d
@ -460,25 +460,27 @@ pbuf_realloc(struct pbuf *p, u16_t new_len)
|
|||||||
* PBUF_ROM and PBUF_REF type buffers cannot have their sizes increased, so
|
* PBUF_ROM and PBUF_REF type buffers cannot have their sizes increased, so
|
||||||
* the call will fail. A check is made that the increase in header size does
|
* the call will fail. A check is made that the increase in header size does
|
||||||
* not move the payload pointer in front of the start of the buffer.
|
* not move the payload pointer in front of the start of the buffer.
|
||||||
* @return 1 on failure, 0 on success.
|
* @return non-zero on failure, zero on success.
|
||||||
*
|
*
|
||||||
* @note May not be called on a packet queue.
|
|
||||||
*/
|
*/
|
||||||
u8_t
|
u8_t
|
||||||
pbuf_header(struct pbuf *p, s16_t header_size)
|
pbuf_header(struct pbuf *p, s16_t header_size_increment)
|
||||||
{
|
{
|
||||||
void *payload;
|
void *payload;
|
||||||
|
|
||||||
|
LWIP_ASSERT("p != NULL", p != NULL);
|
||||||
|
if ((header_size_increment == 0) || (p == NULL)) return 0;
|
||||||
|
|
||||||
/* remember current payload pointer */
|
/* remember current payload pointer */
|
||||||
payload = p->payload;
|
payload = p->payload;
|
||||||
|
|
||||||
/* pbuf types containing payloads? */
|
/* pbuf types containing payloads? */
|
||||||
if (p->flags == PBUF_FLAG_RAM || p->flags == PBUF_FLAG_POOL) {
|
if (p->flags == PBUF_FLAG_RAM || p->flags == PBUF_FLAG_POOL) {
|
||||||
/* set new payload pointer */
|
/* set new payload pointer */
|
||||||
p->payload = (u8_t *)p->payload - header_size;
|
p->payload = (u8_t *)p->payload - header_size_increment;
|
||||||
/* boundary check fails? */
|
/* boundary check fails? */
|
||||||
if ((u8_t *)p->payload < (u8_t *)p + sizeof(struct pbuf)) {
|
if ((u8_t *)p->payload < (u8_t *)p + sizeof(struct pbuf)) {
|
||||||
LWIP_DEBUGF( PBUF_DEBUG | 2, ("pbuf_header: failed as %p < %p\n",
|
LWIP_DEBUGF( PBUF_DEBUG | 2, ("pbuf_header: failed as %p < %p (not enough space for new header size)\n",
|
||||||
(u8_t *)p->payload,
|
(u8_t *)p->payload,
|
||||||
(u8_t *)p + sizeof(struct pbuf)) );\
|
(u8_t *)p + sizeof(struct pbuf)) );\
|
||||||
/* restore old payload pointer */
|
/* restore old payload pointer */
|
||||||
@ -486,22 +488,24 @@ pbuf_header(struct pbuf *p, s16_t header_size)
|
|||||||
/* bail out unsuccesfully */
|
/* bail out unsuccesfully */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* pbuf types refering to payloads? */
|
/* pbuf types refering to external payloads? */
|
||||||
} else if (p->flags == PBUF_FLAG_REF || p->flags == PBUF_FLAG_ROM) {
|
} else if (p->flags == PBUF_FLAG_REF || p->flags == PBUF_FLAG_ROM) {
|
||||||
/* hide a header in the payload? */
|
/* hide a header in the payload? */
|
||||||
if ((header_size < 0) && (header_size - p->len <= 0)) {
|
if ((header_size_increment < 0) && (header_size_increment - p->len <= 0)) {
|
||||||
/* increase payload pointer */
|
/* increase payload pointer */
|
||||||
p->payload = (u8_t *)p->payload - header_size;
|
p->payload = (u8_t *)p->payload - header_size_increment;
|
||||||
} else {
|
} else {
|
||||||
/* cannot expand payload to front (yet!)
|
/* cannot expand payload to front (yet!)
|
||||||
* bail out unsuccesfully */
|
* bail out unsuccesfully */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LWIP_DEBUGF( PBUF_DEBUG, ("pbuf_header: old %p new %p (%d)\n", (void *)payload, (void *)p->payload, header_size) );
|
|
||||||
/* modify pbuf length fields */
|
/* modify pbuf length fields */
|
||||||
p->len += header_size;
|
p->len += header_size_increment;
|
||||||
p->tot_len += header_size;
|
p->tot_len += header_size_increment;
|
||||||
|
|
||||||
|
LWIP_DEBUGF( PBUF_DEBUG, ("pbuf_header: old %p new %p (%d)\n",
|
||||||
|
(void *)payload, (void *)p->payload, header_size_increment));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -510,8 +514,8 @@ pbuf_header(struct pbuf *p, s16_t header_size)
|
|||||||
* Dereference a pbuf chain or queue and deallocate any no-longer-used
|
* Dereference a pbuf chain or queue and deallocate any no-longer-used
|
||||||
* pbufs at the head of this chain or queue.
|
* pbufs at the head of this chain or queue.
|
||||||
*
|
*
|
||||||
* Decrements the pbuf reference count. If it reaches
|
* Decrements the pbuf reference count. If it reaches zero, the pbuf is
|
||||||
* zero, the pbuf is deallocated.
|
* deallocated.
|
||||||
*
|
*
|
||||||
* For a pbuf chain, this is repeated for each pbuf in the chain,
|
* For a pbuf chain, this is repeated for each pbuf in the chain,
|
||||||
* up to the first pbuf which has a non-zero reference count after
|
* up to the first pbuf which has a non-zero reference count after
|
||||||
@ -522,7 +526,7 @@ pbuf_header(struct pbuf *p, s16_t header_size)
|
|||||||
* @return the number of pbufs that were de-allocated
|
* @return the number of pbufs that were de-allocated
|
||||||
* from the head of the chain.
|
* from the head of the chain.
|
||||||
*
|
*
|
||||||
* @note MUST NOT be called on a packet queue.
|
* @note MUST NOT be called on a packet queue (Not verified to work yet).
|
||||||
* @note the reference counter of a pbuf equals the number of pointers
|
* @note the reference counter of a pbuf equals the number of pointers
|
||||||
* that refer to the pbuf (or into the pbuf).
|
* that refer to the pbuf (or into the pbuf).
|
||||||
*
|
*
|
||||||
@ -711,12 +715,15 @@ pbuf_chain(struct pbuf *h, struct pbuf *t)
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
pbuf_queue(struct pbuf *p, struct pbuf *n)
|
pbuf_queue(struct pbuf *q, struct pbuf *n)
|
||||||
{
|
{
|
||||||
|
struct pbuf *p;
|
||||||
|
/* programmer stupidity checks */
|
||||||
LWIP_ASSERT("p != NULL", p != NULL);
|
LWIP_ASSERT("p != NULL", p != NULL);
|
||||||
LWIP_ASSERT("n != NULL", n != NULL);
|
LWIP_ASSERT("n != NULL", n != NULL);
|
||||||
if ((p == NULL) || (n == NULL)) return;
|
if ((p == NULL) || (n == NULL)) return;
|
||||||
|
|
||||||
|
p = q;
|
||||||
/* iterate through all packets on queue */
|
/* iterate through all packets on queue */
|
||||||
while (p->next != NULL) {
|
while (p->next != NULL) {
|
||||||
/* be very picky about pbuf chain correctness */
|
/* be very picky about pbuf chain correctness */
|
||||||
@ -728,10 +735,10 @@ pbuf_queue(struct pbuf *p, struct pbuf *n)
|
|||||||
/* make sure each packet is complete */
|
/* make sure each packet is complete */
|
||||||
LWIP_ASSERT("p->next != NULL", p->next != NULL);
|
LWIP_ASSERT("p->next != NULL", p->next != NULL);
|
||||||
p = p->next;
|
p = p->next;
|
||||||
/* { p->tot_len == p->len } => p is last pbuf of a packet */
|
/* { p->tot_len == p->len => p is last pbuf of a packet } */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* { p->tot_len == p->len } => p is last pbuf of a packet */
|
/* { p->tot_len == p->len and p is last pbuf of a packet } */
|
||||||
/* proceed to next packet on queue */
|
/* proceed to next packet on queue */
|
||||||
if (p->next != NULL) p = p->next;
|
if (p->next != NULL) p = p->next;
|
||||||
}
|
}
|
||||||
@ -739,9 +746,11 @@ pbuf_queue(struct pbuf *p, struct pbuf *n)
|
|||||||
* { p is last pbuf of last packet on queue } */
|
* { p is last pbuf of last packet on queue } */
|
||||||
/* chain last pbuf of queue with n */
|
/* chain last pbuf of queue with n */
|
||||||
p->next = n;
|
p->next = n;
|
||||||
/* n is now referenced to one more time */
|
/* n is now referenced to by the (packet p in the) queue */
|
||||||
pbuf_ref(n);
|
pbuf_ref(n);
|
||||||
LWIP_DEBUGF(PBUF_DEBUG | DBG_FRESH | 2, ("pbuf_queue: referencing queued packet %p\n", (void *)n));
|
LWIP_DEBUGF(PBUF_DEBUG | DBG_FRESH | 2,
|
||||||
|
("pbuf_queue: newly queued packet %p sits after packet %p in queue %p\n",
|
||||||
|
(void *)n, (void *)p, (void *)q));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,8 +53,8 @@ typedef enum {
|
|||||||
PBUF_POOL
|
PBUF_POOL
|
||||||
} pbuf_flag;
|
} pbuf_flag;
|
||||||
|
|
||||||
/* Definitions for the pbuf flag field (these are not the flags that
|
/* Definitions for the pbuf flag field. These are NOT the flags that
|
||||||
are passed to pbuf_alloc()). */
|
* are passed to pbuf_alloc(). */
|
||||||
#define PBUF_FLAG_RAM 0x00U /* Flags that pbuf data is stored in RAM */
|
#define PBUF_FLAG_RAM 0x00U /* Flags that pbuf data is stored in RAM */
|
||||||
#define PBUF_FLAG_ROM 0x01U /* Flags that pbuf data is stored in ROM */
|
#define PBUF_FLAG_ROM 0x01U /* Flags that pbuf data is stored in ROM */
|
||||||
#define PBUF_FLAG_POOL 0x02U /* Flags that the pbuf comes from the pbuf pool */
|
#define PBUF_FLAG_POOL 0x02U /* Flags that the pbuf comes from the pbuf pool */
|
||||||
@ -79,10 +79,10 @@ struct pbuf {
|
|||||||
*/
|
*/
|
||||||
u16_t tot_len;
|
u16_t tot_len;
|
||||||
|
|
||||||
/* length of this buffer */
|
/** length of this buffer */
|
||||||
u16_t len;
|
u16_t len;
|
||||||
|
|
||||||
/* flags telling the type of pbuf */
|
/** flags telling the type of pbuf, see PBUF_FLAG_ */
|
||||||
u16_t flags;
|
u16_t flags;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,11 +94,6 @@ struct pbuf {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* pbuf_init():
|
|
||||||
|
|
||||||
Initializes the pbuf module. The num parameter determines how many
|
|
||||||
pbufs that should be allocated to the pbuf pool, and the size
|
|
||||||
parameter specifies the size of the data allocated to those. */
|
|
||||||
void pbuf_init(void);
|
void pbuf_init(void);
|
||||||
|
|
||||||
struct pbuf *pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag);
|
struct pbuf *pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user