Rev 4243 | Rev 4395 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4243 | Rev 4307 | ||
---|---|---|---|
Line 46... | Line 46... | ||
46 | 46 | ||
47 | #include "../../err.h" |
47 | #include "../../err.h" |
48 | #include "../../messages.h" |
48 | #include "../../messages.h" |
49 | 49 | ||
50 | #include "packet.h" |
50 | #include "packet.h" |
- | 51 | #include "packet_client.h" |
|
51 | #include "packet_header.h" |
52 | #include "packet_header.h" |
- | 53 | #include "packet_messages.h" |
|
52 | #include "packet_server.h" |
54 | #include "packet_server.h" |
53 | 55 | ||
- | 56 | #define FREE_QUEUES_COUNT 7 |
|
- | 57 | ||
54 | /** The default address length reserved for new packets. |
58 | /** The default address length reserved for new packets. |
55 | */ |
59 | */ |
56 | #define DEFAULT_ADDR_LEN 32 |
60 | #define DEFAULT_ADDR_LEN 32 |
57 | 61 | ||
58 | /** The default prefix reserved for new packets. |
62 | /** The default prefix reserved for new packets. |
Line 61... | Line 65... | ||
61 | 65 | ||
62 | /** The default suffix reserved for new packets. |
66 | /** The default suffix reserved for new packets. |
63 | */ |
67 | */ |
64 | #define DEFAULT_SUFFIX 0 |
68 | #define DEFAULT_SUFFIX 0 |
65 | 69 | ||
66 | /** Returns the packet identifier message parameter. |
- | |
67 | */ |
- | |
68 | #define IPC_GET_ID( call ) ( packet_id_t ) IPC_GET_ARG1( * call ) |
- | |
69 | - | ||
70 | /** Returns the maximal content length message parameter. |
- | |
71 | */ |
- | |
72 | #define IPC_GET_CONTENT( call ) ( size_t ) IPC_GET_ARG1( * call ) |
- | |
73 | - | ||
74 | /** Returns the maximal address length message parameter. |
- | |
75 | */ |
- | |
76 | #define IPC_GET_ADDR_LEN( call ) ( size_t ) IPC_GET_ARG2( * call ) |
- | |
77 | - | ||
78 | /** Returns the maximal prefix length message parameter. |
- | |
79 | */ |
- | |
80 | #define IPC_GET_PREFIX( call ) ( size_t ) IPC_GET_ARG3( * call ) |
- | |
81 | - | ||
82 | /** Returns the maximal suffix length message parameter. |
- | |
83 | */ |
- | |
84 | #define IPC_GET_SUFFIX( call ) ( size_t ) IPC_GET_ARG4( * call ) |
- | |
85 | - | ||
86 | #define FREE_QUEUES_COUNT 7 |
- | |
87 | - | ||
88 | /** Packet server global data. |
70 | /** Packet server global data. |
89 | */ |
71 | */ |
90 | static struct{ |
72 | static struct{ |
91 | /** Safety lock. |
73 | /** Safety lock. |
92 | */ |
74 | */ |
Line 107... | Line 89... | ||
107 | { NULL, NULL, NULL, NULL, NULL, NULL, NULL }, |
89 | { NULL, NULL, NULL, NULL, NULL, NULL, NULL }, |
108 | { PAGE_SIZE, PAGE_SIZE * 2, PAGE_SIZE * 4, PAGE_SIZE * 8, PAGE_SIZE * 16, PAGE_SIZE * 32, PAGE_SIZE * 64 }, |
90 | { PAGE_SIZE, PAGE_SIZE * 2, PAGE_SIZE * 4, PAGE_SIZE * 8, PAGE_SIZE * 16, PAGE_SIZE * 32, PAGE_SIZE * 64 }, |
109 | 0 |
91 | 0 |
110 | }; |
92 | }; |
111 | 93 | ||
112 | /** Releases the packet and returns it to the appropriate free packet queue. |
- | |
113 | * Should be used only when the global data are locked. |
- | |
114 | * @param packet The packet to be released. Input parameter. |
- | |
115 | */ |
- | |
116 | void packet_release( packet_t packet ); |
- | |
117 | - | ||
118 | /** Returns the packet of dimensions at least as given. |
94 | /** Returns the packet of dimensions at least as given. |
119 | * Tries to reuse free packets first. |
95 | * Tries to reuse free packets first. |
120 | * Creates a new packet aligned to the memory page size if none available. |
96 | * Creates a new packet aligned to the memory page size if none available. |
121 | * Locks the global data during its processing. |
97 | * Locks the global data during its processing. |
122 | * @param addr_len The source and destination addresses maximal length in bytes. Input parameter. |
98 | * @param addr_len The source and destination addresses maximal length in bytes. Input parameter. |
Line 124... | Line 100... | ||
124 | * @param max_content The maximal content length in bytes. Input parameter. |
100 | * @param max_content The maximal content length in bytes. Input parameter. |
125 | * @param max_suffix The maximal suffix length in bytes. Input parameter. |
101 | * @param max_suffix The maximal suffix length in bytes. Input parameter. |
126 | * @returns The packet of dimensions at least as given. |
102 | * @returns The packet of dimensions at least as given. |
127 | * @returns NULL if there is not enough memory left. |
103 | * @returns NULL if there is not enough memory left. |
128 | */ |
104 | */ |
129 | packet_t packet_get( size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ); |
105 | packet_t packet_get( size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix ); |
- | 106 | ||
- | 107 | /** \todo |
|
- | 108 | */ |
|
- | 109 | int packet_release_wrapper( packet_id_t packet_id ); |
|
- | 110 | ||
- | 111 | /** Releases the packet and returns it to the appropriate free packet queue. |
|
- | 112 | * Should be used only when the global data are locked. |
|
- | 113 | * @param packet The packet to be released. Input parameter. |
|
- | 114 | */ |
|
- | 115 | void packet_release( packet_t packet ); |
|
130 | 116 | ||
131 | /** Creates a new packet of dimensions at least as given. |
117 | /** Creates a new packet of dimensions at least as given. |
132 | * Should be used only when the global data are locked. |
118 | * Should be used only when the global data are locked. |
133 | * @param length The total length of the packet, including the header, the addresses and the data of the packet. Input parameter. |
119 | * @param length The total length of the packet, including the header, the addresses and the data of the packet. Input parameter. |
134 | * @param addr_len The source and destination addresses maximal length in bytes. Input parameter. |
120 | * @param addr_len The source and destination addresses maximal length in bytes. Input parameter. |
Line 157... | Line 143... | ||
157 | * @returns ENOMEM if the desired and actual sizes differ. |
143 | * @returns ENOMEM if the desired and actual sizes differ. |
158 | * @returns Other error codes as defined for the ipc_share_in_finalize() function. |
144 | * @returns Other error codes as defined for the ipc_share_in_finalize() function. |
159 | */ |
145 | */ |
160 | int packet_reply( const packet_t packet ); |
146 | int packet_reply( const packet_t packet ); |
161 | 147 | ||
- | 148 | int packet_translate( int phone, packet_ref packet, packet_id_t packet_id ){ |
|
- | 149 | if( ! packet ) return EINVAL; |
|
- | 150 | * packet = pm_find( packet_id ); |
|
- | 151 | return ( * packet ) ? EOK : ENOENT; |
|
- | 152 | } |
|
- | 153 | ||
- | 154 | packet_t packet_get_4( int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix ){ |
|
- | 155 | return packet_get( addr_len, max_prefix, max_content, max_suffix ); |
|
- | 156 | } |
|
- | 157 | ||
- | 158 | packet_t packet_get_1( int phone, size_t content ){ |
|
- | 159 | return packet_get( DEFAULT_ADDR_LEN, DEFAULT_PREFIX, content, DEFAULT_SUFFIX ); |
|
- | 160 | } |
|
- | 161 | ||
- | 162 | void pq_release( int phone, packet_id_t packet_id ){ |
|
- | 163 | ( void ) packet_release_wrapper( packet_id ); |
|
- | 164 | } |
|
- | 165 | ||
162 | int packet_server_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
166 | int packet_server_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
163 | packet_t packet; |
167 | packet_t packet; |
164 | 168 | ||
165 | * answer_count = 0; |
169 | * answer_count = 0; |
166 | switch( IPC_GET_METHOD( * call )){ |
170 | switch( IPC_GET_METHOD( * call )){ |
Line 189... | Line 193... | ||
189 | if( ! packet_is_valid( packet )) return ENOENT; |
193 | if( ! packet_is_valid( packet )) return ENOENT; |
190 | * answer_count = 1; |
194 | * answer_count = 1; |
191 | IPC_SET_ARG1( * answer, packet->length ); |
195 | IPC_SET_ARG1( * answer, packet->length ); |
192 | return EOK; |
196 | return EOK; |
193 | case NET_PACKET_RELEASE: |
197 | case NET_PACKET_RELEASE: |
194 | packet = pm_find( IPC_GET_ID( call )); |
198 | return packet_release_wrapper( IPC_GET_ID( call )); |
195 | if( ! packet_is_valid( packet )) return ENOENT; |
- | |
196 | futex_down( & ps_globals.lock ); |
- | |
197 | pq_destroy( packet, packet_release ); |
- | |
198 | futex_up( & ps_globals.lock ); |
- | |
199 | return EOK; |
- | |
200 | } |
199 | } |
201 | return ENOTSUP; |
200 | return ENOTSUP; |
202 | } |
201 | } |
203 | 202 | ||
- | 203 | int packet_release_wrapper( packet_id_t packet_id ){ |
|
- | 204 | packet_t packet; |
|
- | 205 | ||
- | 206 | packet = pm_find( packet_id ); |
|
- | 207 | if( ! packet_is_valid( packet )) return ENOENT; |
|
- | 208 | futex_down( & ps_globals.lock ); |
|
- | 209 | pq_destroy( packet, packet_release ); |
|
- | 210 | futex_up( & ps_globals.lock ); |
|
- | 211 | return EOK; |
|
- | 212 | } |
|
- | 213 | ||
204 | void packet_release( packet_t packet ){ |
214 | void packet_release( packet_t packet ){ |
205 | int index; |
215 | int index; |
206 | 216 | ||
207 | for( index = 0; ( index < FREE_QUEUES_COUNT - 1 ) && ( packet->length > ps_globals.sizes[ index ] ); ++ index ); |
217 | for( index = 0; ( index < FREE_QUEUES_COUNT - 1 ) && ( packet->length > ps_globals.sizes[ index ] ); ++ index ); |
208 | ps_globals.free[ index ] = pq_add( ps_globals.free[ index ], packet, packet->length, packet->length ); |
218 | ps_globals.free[ index ] = pq_add( ps_globals.free[ index ], packet, packet->length, packet->length ); |