/branches/network/uspace/srv/net/structures/packet/packet_remote.c |
---|
36,6 → 36,7 |
*/ |
#include <async.h> |
#include <errno.h> |
#include <ipc/ipc.h> |
#include <sys/mman.h> |
45,6 → 46,7 |
#include "packet.h" |
#include "packet_client.h" |
#include "packet_header.h" |
#include "packet_messages.h" |
/** Obtains the packet from the packet server as the shared memory block. |
63,13 → 65,18 |
ERROR_DECLARE; |
unsigned int size; |
packet_t next; |
if( ! packet ) return EINVAL; |
* packet = pm_find( packet_id ); |
if( * packet ) return EOK; |
if( !( * packet )){ |
ERROR_PROPAGATE( async_req_1_1( phone, NET_PACKET_GET_SIZE, packet_id, & size )); |
return packet_return( phone, packet, packet_id, size ); |
ERROR_PROPAGATE( packet_return( phone, packet, packet_id, size )); |
} |
if(( ** packet ).next ){ |
return packet_translate( phone, & next, ( ** packet ).next ); |
}else return EOK; |
} |
int packet_return( int phone, packet_ref packet, packet_id_t packet_id, size_t size ){ |
ERROR_DECLARE; |
97,10 → 104,15 |
unsigned int size; |
packet_t packet; |
if( ERROR_OCCURRED( async_req_4_2( phone, NET_PACKET_CREATE_4, max_content, addr_len, max_prefix, max_suffix, ( ipcarg_t * ) & packet_id, & size )) |
|| ERROR_OCCURRED( packet_return( phone, & packet, packet_id, size ))){ |
if( ERROR_OCCURRED( async_req_4_2( phone, NET_PACKET_CREATE_4, max_content, addr_len, max_prefix, max_suffix, ( ipcarg_t * ) & packet_id, & size ))){ |
return NULL; |
} |
packet = pm_find( packet_id ); |
if( ! packet ){ |
if( ERROR_OCCURRED( packet_return( phone, & packet, packet_id, size ))){ |
return NULL; |
} |
} |
return packet; |
} |
111,10 → 123,15 |
unsigned int size; |
packet_t packet; |
if( ERROR_OCCURRED( async_req_1_2( phone, NET_PACKET_CREATE_1, content, ( ipcarg_t * ) & packet_id, & size )) |
|| ERROR_OCCURRED( packet_return( phone, & packet, packet_id, size ))){ |
if( ERROR_OCCURRED( async_req_1_2( phone, NET_PACKET_CREATE_1, content, ( ipcarg_t * ) & packet_id, & size ))){ |
return NULL; |
} |
packet = pm_find( packet_id ); |
if( ! packet ){ |
if( ERROR_OCCURRED( packet_return( phone, & packet, packet_id, size ))){ |
return NULL; |
} |
} |
return packet; |
} |
/branches/network/uspace/srv/net/structures/packet/packet_header.h |
---|
37,8 → 37,6 |
#ifndef __NET_PACKET_HEADER_H__ |
#define __NET_PACKET_HEADER_H__ |
#include "../../messages.h" |
#include "packet.h" |
/** Packet integrity check magic value. |
/branches/network/uspace/srv/net/structures/packet/packet_client.c |
---|
34,16 → 34,13 |
* Packet client implementation. |
*/ |
#include <async.h> |
#include <errno.h> |
#include <mem.h> |
#include <unistd.h> |
//#include <stdio.h> |
#include <ipc/ipc.h> |
#include <sys/mman.h> |
#include "../../err.h" |
#include "../../messages.h" |
#include "packet.h" |
61,7 → 58,7 |
} |
void * packet_prefix( packet_t packet, size_t length ){ |
if(( ! packet_is_valid( packet )) || ( packet->data_start - sizeof( struct packet ) - 2 * packet->addr_len < length )) return NULL; |
if(( ! packet_is_valid( packet )) || ( packet->data_start - sizeof( struct packet ) - 2 * ( packet->dest_addr - packet->src_addr ) < length )) return NULL; |
packet->data_start -= length; |
return ( void * ) packet + packet->data_start; |
} |
/branches/network/uspace/srv/net/structures/packet/packet.c |
---|
40,6 → 40,7 |
#include <mem.h> |
#include <rwlock.h> |
//#include <stdio.h> |
#include <unistd.h> |
#include <sys/mman.h> |
47,8 → 48,8 |
#include "../generic_field.h" |
#include "packet.h" |
#include "packet_header.h" |
#include "packet.h" |
/** Packet map page size. |
*/ |
211,6 → 212,18 |
return packet; |
} |
int pq_insert_after( packet_t packet, packet_t new_packet ){ |
packet_t item; |
if( !( packet_is_valid( packet ) && packet_is_valid( new_packet ))) return EINVAL; |
new_packet->previous = packet->packet_id; |
new_packet->next = packet->next; |
item = pm_find( packet->next ); |
if( item ) item->previous = new_packet->packet_id; |
packet->next = new_packet->packet_id; |
return EOK; |
} |
packet_t pq_detach( packet_t packet ){ |
packet_t next; |
packet_t previous; |
/branches/network/uspace/srv/net/structures/packet/packet.h |
---|
107,6 → 107,14 |
*/ |
packet_t pq_add( packet_t first, packet_t packet, int order, size_t metric ); |
/** Inserts packet after the given one. |
* @param packet The packet in the queue. Input parameter. |
* @param new_packet The new packet to be inserted. |
* @returns EOK on success. |
* @returns EINVAL if etiher of the packets is invalid. |
*/ |
int pq_insert_after( packet_t packet, packet_t new_packet ); |
/** Detach the packet from the queue. |
* @param packet The packet to be detached. Input parameter. |
* @returns The next packet in the queue. If the packet is the first one of the queue, this becomes the new first one. |
/branches/network/uspace/srv/net/structures/packet/packet_server.c |
---|
194,8 → 194,8 |
case NET_PACKET_GET_SIZE: |
packet = pm_find( IPC_GET_ID( call )); |
if( ! packet_is_valid( packet )) return ENOENT; |
IPC_SET_ARG1( * answer, packet->length ); |
* answer_count = 1; |
IPC_SET_ARG1( * answer, packet->length ); |
return EOK; |
case NET_PACKET_RELEASE: |
return packet_release_wrapper( IPC_GET_ID( call )); |
234,7 → 234,12 |
while( packet_is_valid( packet ) && ( packet->length < length )){ |
packet = pm_find( packet->next ); |
} |
if( packet ){ |
if( packet_is_valid( packet )){ |
if( packet == ps_globals.free[ index ] ){ |
ps_globals.free[ index ] = pq_detach( packet ); |
}else{ |
pq_detach( packet ); |
} |
packet_init( packet, addr_len, max_prefix, max_content, max_suffix ); |
futex_up( & ps_globals.lock ); |
return packet; |
258,29 → 263,24 |
packet->packet_id = ps_globals.count; |
packet->length = length; |
packet_init( packet, addr_len, max_prefix, max_content, max_suffix ); |
packet->magic_value = PACKET_MAGIC_VALUE; |
if( ERROR_OCCURRED( pm_add( packet ))){ |
munmap( packet, packet->length ); |
return NULL; |
} |
packet_release( packet ); |
return packet; |
} |
void packet_init( packet_t packet, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ){ |
int length; |
// clear whole packet |
length = packet->length; |
bzero( packet, packet->length ); |
packet->length = length; |
packet->magic_value = PACKET_MAGIC_VALUE; |
/* // clear the packet header |
// clear the packet content |
bzero((( void * ) packet ) + sizeof( struct packet ), packet->length - sizeof( struct packet )); |
// clear the packet header |
packet->order = 0; |
packet->metric = 0; |
packet->previous = 0; |
packet->next = 0; |
packet->addr_len = 0; |
*/ packet->src_addr = sizeof( struct packet ); |
packet->src_addr = sizeof( struct packet ); |
packet->dest_addr = packet->src_addr + addr_len; |
packet->max_prefix = max_prefix; |
packet->max_content = max_content; |
/branches/network/uspace/srv/net/structures/generic_char_map.h |
---|
36,6 → 36,7 |
#ifndef __GENERIC_CHAR_MAP_H__ |
#define __GENERIC_CHAR_MAP_H__ |
#include <errno.h> |
#include <unistd.h> |
#include "../err.h" |