Changeset 14f1db0 in mainline for uspace/lib/socket
- Timestamp:
- 2010-04-09T12:54:57Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a1caa3c2
- Parents:
- 24ab58b3
- Location:
- uspace/lib/socket
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/socket/generic/net_modules.c
r24ab58b3 r14f1db0 77 77 } 78 78 79 int bind_service(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver){ 79 /** Create bidirectional connection with the needed module service and registers the message receiver. 80 * 81 * @param[in] need The needed module service. 82 * @param[in] arg1 The first parameter. 83 * @param[in] arg2 The second parameter. 84 * @param[in] arg3 The third parameter. 85 * @param[in] client_receiver The message receiver. 86 * 87 * @return The phone of the needed service. 88 * @return Other error codes as defined for the ipc_connect_to_me() function. 89 * 90 */ 91 int bind_service(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, 92 async_client_conn_t client_receiver) 93 { 80 94 return bind_service_timeout(need, arg1, arg2, arg3, client_receiver, 0); 81 95 } 82 96 83 int bind_service_timeout(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout){ 97 /** Create bidirectional connection with the needed module service and registers the message receiver. 98 * 99 * @param[in] need The needed module service. 100 * @param[in] arg1 The first parameter. 101 * @param[in] arg2 The second parameter. 102 * @param[in] arg3 The third parameter. 103 * @param[in] client_receiver The message receiver. 104 * @param[in] timeout The connection timeout in microseconds. 105 * No timeout if set to zero (0). 106 * 107 * @return The phone of the needed service. 108 * @return ETIMEOUT if the connection timeouted. 109 * @return Other error codes as defined for the ipc_connect_to_me() function. 110 * 111 */ 112 int bind_service_timeout(services_t need, ipcarg_t arg1, ipcarg_t arg2, 113 ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout) 114 { 84 115 ERROR_DECLARE; 85 86 int phone; 87 ipcarg_t phonehash; 88 89 // connect to the needed service 90 phone = connect_to_service_timeout(need, timeout); 91 // if connected 92 if(phone >= 0){ 93 // request the bidirectional connection 94 if(ERROR_OCCURRED(ipc_connect_to_me(phone, arg1, arg2, arg3, &phonehash))){ 116 117 /* Connect to the needed service */ 118 int phone = connect_to_service_timeout(need, timeout); 119 if (phone >= 0) { 120 /* Request the bidirectional connection */ 121 ipcarg_t phonehash; 122 if (ERROR_OCCURRED(ipc_connect_to_me(phone, arg1, arg2, arg3, 123 &phonehash))) { 95 124 ipc_hangup(phone); 96 125 return ERROR_CODE; … … 98 127 async_new_connection(phonehash, 0, NULL, client_receiver); 99 128 } 129 100 130 return phone; 101 131 } -
uspace/lib/socket/generic/socket_core.c
r24ab58b3 r14f1db0 90 90 // release all received packets 91 91 while((packet_id = dyn_fifo_pop(&socket->received)) >= 0){ 92 pq_release (packet_phone, packet_id);92 pq_release_local(packet_phone, packet_id); 93 93 } 94 94 dyn_fifo_destroy(&socket->received); -
uspace/lib/socket/include/net_messages.h
r24ab58b3 r14f1db0 462 462 /*@}*/ 463 463 464 /** Notifies the module about the device state change. 465 * @param[in] phone The service module phone. 466 * @param[in] message The service specific message. 467 * @param[in] device_id The device identifier. 468 * @param[in] state The new device state. 469 * @param[in] target The target module service. 470 * @returns EOK on success. 471 */ 472 static inline int generic_device_state_msg(int phone, int message, device_id_t device_id, int state, services_t target){ 473 async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) state, target); 464 /** Notify the module about the device state change. 465 * 466 * @param[in] phone The service module phone. 467 * @param[in] message The service specific message. 468 * @param[in] device_id The device identifier. 469 * @param[in] state The new device state. 470 * @param[in] target The target module service. 471 * 472 * @return EOK on success. 473 * 474 */ 475 static inline int generic_device_state_msg_remote(int phone, int message, 476 device_id_t device_id, int state, services_t target) 477 { 478 async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, 479 (ipcarg_t) state, target); 480 474 481 return EOK; 475 482 } 476 483 477 /** Notifies a module about the device. 478 * @param[in] phone The service module phone. 479 * @param[in] message The service specific message. 480 * @param[in] device_id The device identifier. 481 * @param[in] arg2 The second argument of the message. 482 * @param[in] service The device module service. 483 * @returns EOK on success. 484 * @returns Other error codes as defined for the specific service message. 485 */ 486 static inline int generic_device_req(int phone, int message, device_id_t device_id, int arg2, services_t service){ 487 return (int) async_req_3_0(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) arg2, (ipcarg_t) service); 484 /** Notify a module about the device. 485 * 486 * @param[in] phone The service module phone. 487 * @param[in] message The service specific message. 488 * @param[in] device_id The device identifier. 489 * @param[in] arg2 The second argument of the message. 490 * @param[in] service The device module service. 491 * 492 * @return EOK on success. 493 * @return Other error codes as defined for the specific service message. 494 * 495 */ 496 static inline int generic_device_req_remote(int phone, int message, 497 device_id_t device_id, int arg2, services_t service) 498 { 499 return (int) async_req_3_0(phone, (ipcarg_t) message, (ipcarg_t) device_id, 500 (ipcarg_t) arg2, (ipcarg_t) service); 488 501 } 489 502 … … 521 534 } 522 535 523 /** Returns the device packet dimension for sending. 524 * @param[in] phone The service module phone. 525 * @param[in] message The service specific message. 526 * @param[in] device_id The device identifier. 527 * @param[out] packet_dimension The packet dimension. 528 * @returns EOK on success. 529 * @returns EBADMEM if the packet_dimension parameter is NULL. 530 * @returns Other error codes as defined for the specific service message. 531 */ 532 static inline int generic_packet_size_req(int phone, int message, device_id_t device_id, packet_dimension_ref packet_dimension){ 533 ipcarg_t result; 536 /** Return the device packet dimension for sending. 537 * 538 * @param[in] phone The service module phone. 539 * @param[in] message The service specific message. 540 * @param[in] device_id The device identifier. 541 * @param[out] packet_dimension The packet dimension. 542 * 543 * @return EOK on success. 544 * @return EBADMEM if the packet_dimension parameter is NULL. 545 * @return Other error codes as defined for the specific service message. 546 * 547 */ 548 static inline int generic_packet_size_req_remote(int phone, int message, 549 device_id_t device_id, packet_dimension_ref packet_dimension) 550 { 551 if (!packet_dimension) 552 return EBADMEM; 553 554 ipcarg_t addr_len; 534 555 ipcarg_t prefix; 535 556 ipcarg_t content; 536 557 ipcarg_t suffix; 537 ipcarg_t addr_len; 538 539 if(! packet_dimension){ 540 return EBADMEM; 541 } 542 result = async_req_1_4(phone, (ipcarg_t) message, (ipcarg_t) device_id, &addr_len, &prefix, &content, &suffix); 558 559 ipcarg_t result = async_req_1_4(phone, (ipcarg_t) message, 560 (ipcarg_t) device_id, &addr_len, &prefix, &content, &suffix); 561 543 562 packet_dimension->prefix = (size_t) prefix; 544 563 packet_dimension->content = (size_t) content; 545 564 packet_dimension->suffix = (size_t) suffix; 546 565 packet_dimension->addr_len = (size_t) addr_len; 566 547 567 return (int) result; 548 568 } 549 569 550 /** Passes the packet queue to the module. 551 * @param[in] phone The service module phone. 552 * @param[in] message The service specific message. 553 * @param[in] device_id The device identifier. 554 * @param[in] packet_id The received packet or the received packet queue identifier. 555 * @param[in] target The target module service. 556 * @param[in] error The error module service. 557 * @returns EOK on success. 558 */ 559 static inline int generic_received_msg(int phone, int message, device_id_t device_id, packet_id_t packet_id, services_t target, services_t error){ 560 if(error){ 561 async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) target, (ipcarg_t) error); 562 }else{ 563 async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) target); 564 } 570 /** Pass the packet queue to the module. 571 * 572 * @param[in] phone The service module phone. 573 * @param[in] message The service specific message. 574 * @param[in] device_id The device identifier. 575 * @param[in] packet_id The received packet or the received packet queue 576 * identifier. 577 * @param[in] target The target module service. 578 * @param[in] error The error module service. 579 * 580 * @return EOK on success. 581 * 582 */ 583 static inline int generic_received_msg_remote(int phone, int message, 584 device_id_t device_id, packet_id_t packet_id, services_t target, 585 services_t error) 586 { 587 if (error) 588 async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id, 589 (ipcarg_t) packet_id, (ipcarg_t) target, (ipcarg_t) error); 590 else 591 async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, 592 (ipcarg_t) packet_id, (ipcarg_t) target); 593 565 594 return EOK; 566 595 } 567 596 568 /** Sends the packet queue. 569 * @param[in] phone The service module phone. 570 * @param[in] message The service specific message. 571 * @param[in] device_id The device identifier. 572 * @param[in] packet_id The packet or the packet queue identifier. 573 * @param[in] sender The sending module service. 574 * @param[in] error The error module service. 575 * @returns EOK on success. 576 */ 577 static inline int generic_send_msg(int phone, int message, device_id_t device_id, packet_id_t packet_id, services_t sender, services_t error){ 578 if(error){ 579 async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) sender, (ipcarg_t) error); 580 }else{ 581 async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) sender); 582 } 597 /** Send the packet queue. 598 * 599 * @param[in] phone The service module phone. 600 * @param[in] message The service specific message. 601 * @param[in] device_id The device identifier. 602 * @param[in] packet_id The packet or the packet queue identifier. 603 * @param[in] sender The sending module service. 604 * @param[in] error The error module service. 605 * 606 * @return EOK on success. 607 * 608 */ 609 static inline int generic_send_msg_remote(int phone, int message, 610 device_id_t device_id, packet_id_t packet_id, services_t sender, 611 services_t error) 612 { 613 if (error) 614 async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id, 615 (ipcarg_t) packet_id, (ipcarg_t) sender, (ipcarg_t) error); 616 else 617 async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, 618 (ipcarg_t) packet_id, (ipcarg_t) sender); 619 583 620 return EOK; 584 621 } -
uspace/lib/socket/include/net_modules.h
r24ab58b3 r14f1db0 72 72 extern void answer_call(ipc_callid_t callid, int result, ipc_call_t * answer, int answer_count); 73 73 74 /** Creates bidirectional connection with the needed module service and registers the message receiver. 75 * @param[in] need The needed module service. 76 * @param[in] arg1 The first parameter. 77 * @param[in] arg2 The second parameter. 78 * @param[in] arg3 The third parameter. 79 * @param[in] client_receiver The message receiver. 80 * @returns The phone of the needed service. 81 * @returns Other error codes as defined for the ipc_connect_to_me() function. 82 */ 83 extern int bind_service(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver); 84 85 /** Creates bidirectional connection with the needed module service and registers the message receiver. 86 * @param[in] need The needed module service. 87 * @param[in] arg1 The first parameter. 88 * @param[in] arg2 The second parameter. 89 * @param[in] arg3 The third parameter. 90 * @param[in] client_receiver The message receiver. 91 * @param[in] timeout The connection timeout in microseconds. No timeout if set to zero (0). 92 * @returns The phone of the needed service. 93 * @returns ETIMEOUT if the connection timeouted. 94 * @returns Other error codes as defined for the ipc_connect_to_me() function. 95 */ 96 extern int bind_service_timeout(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout); 74 extern int bind_service(services_t, ipcarg_t, ipcarg_t, ipcarg_t, 75 async_client_conn_t); 76 extern int bind_service_timeout(services_t, ipcarg_t, ipcarg_t, ipcarg_t, 77 async_client_conn_t, suseconds_t); 97 78 98 79 /** Connects to the needed module. -
uspace/lib/socket/include/packet/packet_client.h
r24ab58b3 r14f1db0 45 45 #define __NET_PACKET_CLIENT_H__ 46 46 47 #include "packet.h"47 #include <packet/packet.h> 48 48 49 49 /** @name Packet client interface … … 172 172 * @returns Other error codes as defined for the packet_return() function. 173 173 */ 174 extern int packet_translate (int phone, packet_ref packet, packet_id_t packet_id);174 extern int packet_translate_local(int phone, packet_ref packet, packet_id_t packet_id); 175 175 176 176 /** Obtains the packet of the given dimensions. … … 184 184 * @returns NULL on error. 185 185 */ 186 extern packet_t packet_get_4 (int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix);186 extern packet_t packet_get_4_local(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix); 187 187 188 188 /** Obtains the packet of the given content size. … … 193 193 * @returns NULL on error. 194 194 */ 195 extern packet_t packet_get_1 (int phone, size_t content);195 extern packet_t packet_get_1_local(int phone, size_t content); 196 196 197 197 /** Releases the packet queue. … … 202 202 * @param[in] packet_id The packet identifier. 203 203 */ 204 extern void pq_release (int phone, packet_id_t packet_id);204 extern void pq_release_local(int phone, packet_id_t packet_id); 205 205 206 206 /** Returns the packet copy. -
uspace/lib/socket/packet/packet_client.c
r24ab58b3 r14f1db0 164 164 } 165 165 // get a new packet 166 copy = packet_get_4 (phone, PACKET_DATA_LENGTH(packet), PACKET_MAX_ADDRESS_LENGTH(packet), packet->max_prefix, PACKET_MIN_SUFFIX(packet));166 copy = packet_get_4_local(phone, PACKET_DATA_LENGTH(packet), PACKET_MAX_ADDRESS_LENGTH(packet), packet->max_prefix, PACKET_MIN_SUFFIX(packet)); 167 167 if(! copy){ 168 168 return NULL; … … 178 178 return copy; 179 179 }else{ 180 pq_release (phone, copy->packet_id);180 pq_release_local(phone, copy->packet_id); 181 181 return NULL; 182 182 } -
uspace/lib/socket/packet/packet_server.c
r24ab58b3 r14f1db0 97 97 }; 98 98 99 int packet_translate(int phone, packet_ref packet, packet_id_t packet_id){ 100 if(! packet){ 99 int packet_translate_local(int phone, packet_ref packet, packet_id_t packet_id) 100 { 101 if (!packet) 101 102 return EINVAL; 102 }103 103 104 *packet = pm_find(packet_id); 104 105 return (*packet) ? EOK : ENOENT; … … 161 162 } 162 163 163 /** Returns the packet of dimensions at least as given. 164 * Tries to reuse free packets first. 165 * Creates a new packet aligned to the memory page size if none available. 166 * Locks the global data during its processing. 167 * @param[in] addr_len The source and destination addresses maximal length in bytes. 168 * @param[in] max_prefix The maximal prefix length in bytes. 169 * @param[in] max_content The maximal content length in bytes. 170 * @param[in] max_suffix The maximal suffix length in bytes. 171 * @returns The packet of dimensions at least as given. 172 * @returns NULL if there is not enough memory left. 173 */ 174 static packet_t packet_get(size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix){ 175 int index; 164 /** Return the packet of dimensions at least as given. 165 * 166 * Try to reuse free packets first. 167 * Create a new packet aligned to the memory page size if none available. 168 * Lock the global data during its processing. 169 * 170 * @param[in] addr_len The source and destination addresses 171 * maximal length in bytes. 172 * @param[in] max_prefix The maximal prefix length in bytes. 173 * @param[in] max_content The maximal content length in bytes. 174 * @param[in] max_suffix The maximal suffix length in bytes. 175 * 176 * @return The packet of dimensions at least as given. 177 * @return NULL if there is not enough memory left. 178 * 179 */ 180 static packet_t packet_get_local(size_t addr_len, size_t max_prefix, 181 size_t max_content, size_t max_suffix) 182 { 183 size_t length = ALIGN_UP(sizeof(struct packet) + 2 * addr_len + max_prefix 184 + max_content + max_suffix, PAGE_SIZE); 185 186 fibril_mutex_lock(&ps_globals.lock); 187 176 188 packet_t packet; 177 size_t length; 178 179 length = ALIGN_UP(sizeof(struct packet) + 2 * addr_len + max_prefix + max_content + max_suffix, PAGE_SIZE); 180 fibril_mutex_lock(&ps_globals.lock); 181 for(index = 0; index < FREE_QUEUES_COUNT - 1; ++ index){ 182 if(length <= ps_globals.sizes[index]){ 189 unsigned int index; 190 191 for (index = 0; index < FREE_QUEUES_COUNT - 1; index++) { 192 if (length <= ps_globals.sizes[index]) { 183 193 packet = ps_globals.free[index]; 184 while(packet_is_valid(packet) && (packet->length < length)){ 194 195 while (packet_is_valid(packet) && (packet->length < length)) 185 196 packet = pm_find(packet->next); 186 }187 if (packet_is_valid(packet)){188 if (packet == ps_globals.free[index]){197 198 if (packet_is_valid(packet)) { 199 if (packet == ps_globals.free[index]) 189 200 ps_globals.free[index] = pq_detach(packet); 190 }else{201 else 191 202 pq_detach(packet); 192 } 193 packet_init(packet, addr_len, max_prefix, max_content, max_suffix); 203 204 packet_init(packet, addr_len, max_prefix, max_content, 205 max_suffix); 194 206 fibril_mutex_unlock(&ps_globals.lock); 195 // remove debug dump 196 // printf("packet %d got\n", packet->packet_id); 207 197 208 return packet; 198 209 } 199 210 } 200 211 } 201 packet = packet_create(length, addr_len, max_prefix, max_content, max_suffix); 212 213 packet = packet_create(length, addr_len, max_prefix, max_content, 214 max_suffix); 215 202 216 fibril_mutex_unlock(&ps_globals.lock); 203 // remove debug dump 204 // printf("packet %d created\n", packet->packet_id); 217 205 218 return packet; 206 219 } 207 220 208 packet_t packet_get_4(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix){ 209 return packet_get(addr_len, max_prefix, max_content, max_suffix); 210 } 211 212 packet_t packet_get_1(int phone, size_t content){ 213 return packet_get(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, content, DEFAULT_SUFFIX); 214 } 215 216 /** Releases the packet and returns it to the appropriate free packet queue. 221 packet_t packet_get_4_local(int phone, size_t max_content, size_t addr_len, 222 size_t max_prefix, size_t max_suffix) 223 { 224 return packet_get_local(addr_len, max_prefix, max_content, max_suffix); 225 } 226 227 packet_t packet_get_1_local(int phone, size_t content) 228 { 229 return packet_get_local(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, content, 230 DEFAULT_SUFFIX); 231 } 232 233 /** Release the packet and returns it to the appropriate free packet queue. 234 * 217 235 * Should be used only when the global data are locked. 236 * 218 237 * @param[in] packet The packet to be released. 238 * 219 239 */ 220 240 static void packet_release(packet_t packet){ … … 247 267 } 248 268 249 void pq_release(int phone, packet_id_t packet_id){ 269 void pq_release_local(int phone, packet_id_t packet_id) 270 { 250 271 (void) packet_release_wrapper(packet_id); 251 272 } … … 281 302 return EOK; 282 303 case NET_PACKET_CREATE_1: 283 packet = packet_get (DEFAULT_ADDR_LEN, DEFAULT_PREFIX, IPC_GET_CONTENT(call), DEFAULT_SUFFIX);304 packet = packet_get_local(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, IPC_GET_CONTENT(call), DEFAULT_SUFFIX); 284 305 if(! packet){ 285 306 return ENOMEM; … … 290 311 return EOK; 291 312 case NET_PACKET_CREATE_4: 292 packet = packet_get (((DEFAULT_ADDR_LEN < IPC_GET_ADDR_LEN(call)) ? IPC_GET_ADDR_LEN(call) : DEFAULT_ADDR_LEN), DEFAULT_PREFIX + IPC_GET_PREFIX(call), IPC_GET_CONTENT(call), DEFAULT_SUFFIX + IPC_GET_SUFFIX(call));313 packet = packet_get_local(((DEFAULT_ADDR_LEN < IPC_GET_ADDR_LEN(call)) ? IPC_GET_ADDR_LEN(call) : DEFAULT_ADDR_LEN), DEFAULT_PREFIX + IPC_GET_PREFIX(call), IPC_GET_CONTENT(call), DEFAULT_SUFFIX + IPC_GET_SUFFIX(call)); 293 314 if(! packet){ 294 315 return ENOMEM;
Note:
See TracChangeset
for help on using the changeset viewer.