Changeset 8b5690f in mainline for uspace/srv/net/tl/tcp/tcp.c
- Timestamp:
- 2011-02-03T05:11:01Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ba38f72c
- Parents:
- 22027b6e (diff), 86d7bfa (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/tcp/tcp.c
r22027b6e r8b5690f 36 36 */ 37 37 38 #include "tcp.h"39 #include "tcp_header.h"40 #include "tcp_module.h"41 42 38 #include <assert.h> 43 39 #include <async.h> … … 48 44 #include <errno.h> 49 45 50 #include <ipc/ipc.h>51 46 #include <ipc/services.h> 52 47 #include <ipc/net.h> … … 68 63 #include <ip_interface.h> 69 64 #include <icmp_client.h> 70 #include <icmp_ interface.h>65 #include <icmp_remote.h> 71 66 #include <net_interface.h> 72 67 #include <socket_core.h> 73 68 #include <tl_common.h> 74 #include <tl_local.h> 75 #include <tl_interface.h> 69 #include <tl_remote.h> 70 #include <tl_skel.h> 71 72 #include "tcp.h" 73 #include "tcp_header.h" 76 74 77 75 /** TCP module name. */ 78 #define NAME "TCP protocol"76 #define NAME "tcp" 79 77 80 78 /** The TCP window default value. */ … … 220 218 /** TCP global data. */ 221 219 tcp_globals_t tcp_globals; 222 223 /** Initializes the TCP module.224 *225 * @param[in] client_connection The client connection processing function. The226 * module skeleton propagates its own one.227 * @return EOK on success.228 * @return ENOMEM if there is not enough memory left.229 */230 int tcp_initialize(async_client_conn_t client_connection)231 {232 int rc;233 234 assert(client_connection);235 236 fibril_rwlock_initialize(&tcp_globals.lock);237 fibril_rwlock_write_lock(&tcp_globals.lock);238 239 tcp_globals.icmp_phone = icmp_connect_module(SERVICE_ICMP,240 ICMP_CONNECT_TIMEOUT);241 tcp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_TCP,242 SERVICE_TCP, client_connection);243 if (tcp_globals.ip_phone < 0) {244 fibril_rwlock_write_unlock(&tcp_globals.lock);245 return tcp_globals.ip_phone;246 }247 248 rc = socket_ports_initialize(&tcp_globals.sockets);249 if (rc != EOK)250 goto out;251 252 rc = packet_dimensions_initialize(&tcp_globals.dimensions);253 if (rc != EOK) {254 socket_ports_destroy(&tcp_globals.sockets);255 goto out;256 }257 258 tcp_globals.last_used_port = TCP_FREE_PORTS_START - 1;259 260 out:261 fibril_rwlock_write_unlock(&tcp_globals.lock);262 return rc;263 }264 220 265 221 int tcp_received_msg(device_id_t device_id, packet_t *packet, … … 1247 1203 } 1248 1204 1205 /** Per-connection initialization 1206 * 1207 */ 1208 void tl_connection(void) 1209 { 1210 } 1211 1249 1212 /** Processes the TCP message. 1250 1213 * … … 1260 1223 * @see IS_NET_TCP_MESSAGE() 1261 1224 */ 1262 int 1263 tcp_message_standalone(ipc_callid_t callid, ipc_call_t *call, 1264 ipc_call_t *answer, int *answer_count) 1265 { 1266 packet_t *packet; 1267 int rc; 1268 1225 int tl_message(ipc_callid_t callid, ipc_call_t *call, 1226 ipc_call_t *answer, size_t *answer_count) 1227 { 1269 1228 assert(call); 1270 1229 assert(answer); … … 1273 1232 *answer_count = 0; 1274 1233 switch (IPC_GET_IMETHOD(*call)) { 1275 case NET_TL_RECEIVED:1276 // fibril_rwlock_read_lock(&tcp_globals.lock);1277 rc = packet_translate_remote(tcp_globals.net_phone, &packet,1278 IPC_GET_PACKET(call));1279 if (rc != EOK) {1280 // fibril_rwlock_read_unlock(&tcp_globals.lock);1281 return rc;1282 }1283 rc = tcp_received_msg(IPC_GET_DEVICE(call), packet, SERVICE_TCP,1284 IPC_GET_ERROR(call));1285 // fibril_rwlock_read_unlock(&tcp_globals.lock);1286 return rc;1287 1234 case IPC_M_CONNECT_TO_ME: 1288 1235 return tcp_process_client_messages(callid, *call); … … 1323 1270 bool keep_on_going = true; 1324 1271 socket_cores_t local_sockets; 1325 int app_phone = IPC_GET_PHONE( &call);1272 int app_phone = IPC_GET_PHONE(call); 1326 1273 struct sockaddr *addr; 1327 1274 int socket_id; … … 1330 1277 fibril_rwlock_t lock; 1331 1278 ipc_call_t answer; 1332 int answer_count;1279 size_t answer_count; 1333 1280 tcp_socket_data_t *socket_data; 1334 1281 socket_core_t *socket; … … 1558 1505 1559 1506 /* Release the application phone */ 1560 ipc_hangup(app_phone);1507 async_hangup(app_phone); 1561 1508 1562 1509 printf("release\n"); … … 2486 2433 } 2487 2434 2488 /** Default thread for new connections.2435 /** Process IPC messages from the IP module 2489 2436 * 2490 * @param[in] iid The initial message identifier.2491 * @param[in ] icall The initial message call structure.2437 * @param[in] iid Message identifier. 2438 * @param[in,out] icall Message parameters. 2492 2439 * 2493 2440 */ 2494 static void tl_client_connection(ipc_callid_t iid, ipc_call_t * icall) 2495 { 2496 /* 2497 * Accept the connection 2498 * - Answer the first IPC_M_CONNECT_ME_TO call. 2499 */ 2500 ipc_answer_0(iid, EOK); 2501 2441 static void tcp_receiver(ipc_callid_t iid, ipc_call_t *icall) 2442 { 2443 packet_t *packet; 2444 int rc; 2445 2502 2446 while (true) { 2503 ipc_call_t answer; 2504 int answer_count; 2505 2506 /* Clear the answer structure */ 2507 refresh_answer(&answer, &answer_count); 2508 2509 /* Fetch the next message */ 2510 ipc_call_t call; 2511 ipc_callid_t callid = async_get_call(&call); 2512 2513 /* Process the message */ 2514 int res = tl_module_message_standalone(callid, &call, &answer, 2515 &answer_count); 2516 2517 /* 2518 * End if told to either by the message or the processing 2519 * result. 2520 */ 2521 if ((IPC_GET_IMETHOD(call) == IPC_M_PHONE_HUNGUP) || 2522 (res == EHANGUP)) 2523 return; 2524 2525 /* 2526 * Answer the message 2527 */ 2528 answer_call(callid, res, &answer, answer_count); 2529 } 2530 } 2531 2532 /** Starts the module. 2447 switch (IPC_GET_IMETHOD(*icall)) { 2448 case NET_TL_RECEIVED: 2449 rc = packet_translate_remote(tcp_globals.net_phone, &packet, 2450 IPC_GET_PACKET(*icall)); 2451 if (rc == EOK) 2452 rc = tcp_received_msg(IPC_GET_DEVICE(*icall), packet, 2453 SERVICE_TCP, IPC_GET_ERROR(*icall)); 2454 2455 async_answer_0(iid, (sysarg_t) rc); 2456 break; 2457 default: 2458 async_answer_0(iid, (sysarg_t) ENOTSUP); 2459 } 2460 2461 iid = async_get_call(icall); 2462 } 2463 } 2464 2465 /** Initialize the TCP module. 2533 2466 * 2534 * @return EOK on success. 2535 * @return Other error codes as defined for each specific module 2536 * start function. 2467 * @param[in] net_phone Network module phone. 2468 * 2469 * @return EOK on success. 2470 * @return ENOMEM if there is not enough memory left. 2471 * 2537 2472 */ 2538 int 2539 main(int argc, char *argv[]) 2540 { 2541 int rc; 2542 2543 rc = tl_module_start_standalone(tl_client_connection); 2473 int tl_initialize(int net_phone) 2474 { 2475 fibril_rwlock_initialize(&tcp_globals.lock); 2476 fibril_rwlock_write_lock(&tcp_globals.lock); 2477 2478 tcp_globals.net_phone = net_phone; 2479 2480 tcp_globals.icmp_phone = icmp_connect_module(ICMP_CONNECT_TIMEOUT); 2481 tcp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_TCP, 2482 SERVICE_TCP, tcp_receiver); 2483 if (tcp_globals.ip_phone < 0) { 2484 fibril_rwlock_write_unlock(&tcp_globals.lock); 2485 return tcp_globals.ip_phone; 2486 } 2487 2488 int rc = socket_ports_initialize(&tcp_globals.sockets); 2489 if (rc != EOK) 2490 goto out; 2491 2492 rc = packet_dimensions_initialize(&tcp_globals.dimensions); 2493 if (rc != EOK) { 2494 socket_ports_destroy(&tcp_globals.sockets); 2495 goto out; 2496 } 2497 2498 tcp_globals.last_used_port = TCP_FREE_PORTS_START - 1; 2499 2500 out: 2501 fibril_rwlock_write_unlock(&tcp_globals.lock); 2544 2502 return rc; 2503 } 2504 2505 int main(int argc, char *argv[]) 2506 { 2507 return tl_module_start(SERVICE_TCP); 2545 2508 } 2546 2509
Note:
See TracChangeset
for help on using the changeset viewer.