/branches/network/uspace/srv/net/structures/packet/packet_header.h |
---|
39,6 → 39,21 |
#include "packet.h" |
/** Returns the actual packet data length. |
* @param header The packet header. Input parameter. |
*/ |
#define PACKET_DATA_LENGTH( header ) (( header )->data_end - ( header )->data_start ) |
/** Returns the maximum packet address length. |
* @param header The packet header. Input parameter. |
*/ |
#define PACKET_MAX_ADDRESS_LENGTH( header ) (( header )->dest_addr - ( header )->src_addr ) |
/** Returns the minimum packet suffix. |
* @param header The packet header. Input parameter. |
*/ |
#define PACKET_MIN_SUFFIX( header ) (( header )->length - ( header )->data_start - ( header )->max_content ) |
/** Packet integrity check magic value. |
*/ |
#define PACKET_MAGIC_VALUE 0x11227788 |
52,7 → 67,7 |
/** Packet queue sorting value. |
* The packet queue is sorted the ascending order. |
*/ |
int order; |
size_t order; |
/** Packet metric. |
*/ |
size_t metric; |
/branches/network/uspace/srv/net/structures/packet/packet_client.c |
---|
71,7 → 71,7 |
int packet_trim( packet_t packet, size_t prefix, size_t suffix ){ |
if( ! packet_is_valid( packet )) return EINVAL; |
if( prefix + suffix > packet->data_end - packet->data_start ) return ENOMEM; |
if( prefix + suffix > PACKET_DATA_LENGTH( packet )) return ENOMEM; |
packet->data_start += prefix; |
packet->data_end -= suffix; |
return EOK; |
91,7 → 91,7 |
size_t packet_get_data_length( const packet_t packet ){ |
if( ! packet_is_valid( packet )) return 0; |
return packet->data_end - packet->data_start; |
return PACKET_DATA_LENGTH( packet ); |
} |
void * packet_get_data( const packet_t packet ){ |
104,7 → 104,7 |
size_t allocated; |
if( ! packet_is_valid( packet )) return EINVAL; |
allocated = packet->dest_addr - packet->src_addr; |
allocated = PACKET_MAX_ADDRESS_LENGTH( packet ); |
if( allocated < addr_len ) return ENOMEM; |
padding = allocated - addr_len; |
packet->addr_len = addr_len; |
123,5 → 123,30 |
return EOK; |
} |
packet_t packet_get_copy( int phone, packet_t packet ){ |
packet_t copy; |
uint8_t * src; |
uint8_t * dest; |
size_t addrlen; |
if( ! packet_is_valid( packet )) return NULL; |
// get a new packet |
copy = packet_get_4( phone, PACKET_DATA_LENGTH( packet ), PACKET_MAX_ADDRESS_LENGTH( packet ), packet->max_prefix, PACKET_MIN_SUFFIX( packet )); |
if( ! copy ) return NULL; |
// get addresses |
addrlen = packet_get_addr( packet, & src, & dest ); |
// copy data |
if(( packet_copy_data( copy, packet_get_data( packet ), PACKET_DATA_LENGTH( packet )) == EOK ) |
// copy addresses if present |
&& (( addrlen <= 0 ) || ( packet_set_addr( copy, src, dest, addrlen ) == EOK ))){ |
copy->order = packet->order; |
copy->metric = packet->metric; |
return copy; |
}else{ |
pq_release( phone, copy->packet_id ); |
return NULL; |
} |
} |
/** @} |
*/ |
/branches/network/uspace/srv/net/structures/packet/packet.c |
---|
183,11 → 183,11 |
// leave locked |
} |
packet_t pq_add( packet_t first, packet_t packet, int order, size_t metric ){ |
packet_t pq_add( packet_t first, packet_t packet, size_t order, size_t metric ){ |
packet_t item; |
if( ! packet_is_valid( packet )) return NULL; |
pq_set( packet, order, metric ); |
pq_set_order( packet, order, metric ); |
if( packet_is_valid( first )){ |
item = first; |
do{ |
205,7 → 205,7 |
item->previous = packet->packet_id; |
item = pm_find( packet->previous ); |
if( item ) item->next = packet->packet_id; |
return item; |
return item ? first : packet; |
} |
}while( packet_is_valid( item )); |
} |
212,6 → 212,21 |
return packet; |
} |
packet_t pq_find( packet_t packet, size_t order ){ |
packet_t item; |
if( ! packet_is_valid( packet )) return NULL; |
if( packet->order == order ) return packet; |
item = pm_find( packet->next ); |
while( item && ( item != packet )){ |
item = pm_find( item->next ); |
if( item->order == order ){ |
return item; |
} |
} |
return NULL; |
} |
int pq_insert_after( packet_t packet, packet_t new_packet ){ |
packet_t item; |
242,7 → 257,7 |
return next; |
} |
int pq_set( packet_t packet, int order, size_t metric ){ |
int pq_set_order( packet_t packet, size_t order, size_t metric ){ |
if( ! packet_is_valid( packet )) return EINVAL; |
packet->order = order; |
packet->metric = metric; |
249,6 → 264,13 |
return EOK; |
} |
int pq_get_order( packet_t packet, size_t * order, size_t * metric ){ |
if( ! packet_is_valid( packet )) return EINVAL; |
if( order ) * order = packet->order; |
if( metric ) * metric = packet->metric; |
return EOK; |
} |
void pq_destroy( packet_t first, void ( * packet_release )( packet_t packet )){ |
packet_t actual; |
packet_t next; |
/branches/network/uspace/srv/net/structures/packet/packet_client.h |
---|
203,6 → 203,10 |
*/ |
void pq_release( int phone, packet_id_t packet_id ); |
/** \todo |
*/ |
packet_t packet_get_copy( int phone, packet_t packet ); |
/*@}*/ |
#endif |
/branches/network/uspace/srv/net/structures/packet/packet.h |
---|
109,11 → 109,20 |
* @returns The first packet of the queue. The original first packet may be shifted by the new packet. |
* @returns NULL if the packet is not valid. |
*/ |
packet_t pq_add( packet_t first, packet_t packet, int order, size_t metric ); |
packet_t pq_add( packet_t first, packet_t packet, size_t order, size_t metric ); |
/** Finds the packet with the given order. |
* @param first The first packet of the queue. Input parameter. |
* @param order The packet order value. Input parameter. |
* @returns The packet with the given order. |
* @returns NULL if the first packet is not valid. |
* @returns NULL if the packet is not found. |
*/ |
packet_t pq_find( packet_t first, size_t order ); |
/** Inserts packet after the given one. |
* @param packet The packet in the queue. Input parameter. |
* @param new_packet The new packet to be inserted. |
* @param new_packet The new packet to be inserted. Input parameter. |
* @returns EOK on success. |
* @returns EINVAL if etiher of the packets is invalid. |
*/ |
131,9 → 140,20 |
* @param packet The packet to be set. Input parameter. |
* @param order The packet order value. Input parameter. |
* @param metric The metric value of the packet. Input parameter. |
* @returns EOK on success. |
* @returns EINVAL if the packet is invalid.. |
*/ |
int pq_set( packet_t packet, int order, size_t metric ); |
int pq_set_order( packet_t packet, size_t order, size_t metric ); |
/** Sets the packet order and metric attributes. |
* @param packet The packet to be set. Input parameter. |
* @param order The packet order value. Output parameter. |
* @param metric The metric value of the packet. Ouput parameter. |
* @returns EOK on success. |
* @returns EINVAL if the packet is invalid.. |
*/ |
int pq_get_order( packet_t packet, size_t * order, size_t * metric ); |
/** Releases the whole queue. |
* Detaches all packets of the queue and calls the packet_release() for each of them. |
* @param first The first packet of the queue. Input parameter. |
/branches/network/uspace/srv/net/structures/packet/packet_server.c |
---|
35,10 → 35,10 |
*/ |
#include <align.h> |
#include <assert.h> |
#include <async.h> |
#include <errno.h> |
#include <fibril_sync.h> |
//#include <stdio.h> |
#include <unistd.h> |
#include <ipc/ipc.h> |
225,6 → 225,7 |
for( index = 0; ( index < FREE_QUEUES_COUNT - 1 ) && ( packet->length > ps_globals.sizes[ index ] ); ++ index ); |
ps_globals.free[ index ] = pq_add( ps_globals.free[ index ], packet, packet->length, packet->length ); |
assert( ps_globals.free[ index ] ); |
} |
packet_t packet_get( size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ){ |