Changeset c6588ce in mainline for uspace/srv/net/tcp/sock.c
- Timestamp:
- 2012-05-05T08:12:17Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ee04c28
- Parents:
- 2cc7f16 (diff), d21e935c (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 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tcp/sock.c
r2cc7f16 rc6588ce 38 38 #include <async.h> 39 39 #include <errno.h> 40 #include <inet/inet.h> 40 41 #include <io/log.h> 41 #include <ip _client.h>42 #include <ipc/services.h> 42 43 #include <ipc/socket.h> 43 #include <net/modules.h>44 44 #include <net/socket.h> 45 #include <ns.h> 45 46 46 47 #include "sock.h" … … 63 64 static socket_ports_t gsock; 64 65 66 static void tcp_sock_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg); 65 67 static void tcp_sock_cstate_cb(tcp_conn_t *conn, void *arg); 66 68 67 void tcp_sock_init(void) 68 { 69 int tcp_sock_init(void) 70 { 71 int rc; 72 69 73 socket_ports_initialize(&gsock); 74 75 async_set_client_connection(tcp_sock_connection); 76 77 rc = service_register(SERVICE_TCP); 78 if (rc != EOK) 79 return EEXIST; 80 81 return EOK; 70 82 } 71 83 … … 76 88 socket = (tcp_sockdata_t *)sock_core->specific_data; 77 89 (void)socket; 90 91 /* XXX We need to initiate connection cleanup here */ 78 92 } 79 93 … … 129 143 sock->sock_core = sock_core; 130 144 131 refresh_answer(&answer, NULL);132 145 SOCKET_SET_SOCKET_ID(answer, sock_id); 133 146 134 147 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, FRAGMENT_SIZE); 135 148 SOCKET_SET_HEADER_SIZE(answer, sizeof(tcp_header_t)); 136 answer_call(callid, EOK, &answer, 3); 149 150 async_answer_3(callid, EOK, IPC_GET_ARG1(answer), 151 IPC_GET_ARG2(answer), IPC_GET_ARG3(answer)); 137 152 } 138 153 … … 273 288 tcp_sock_t lsocket; 274 289 tcp_sock_t fsocket; 275 nic_device_id_t dev_id;276 tcp_phdr_t *phdr;277 size_t phdr_len;278 290 279 291 log_msg(LVL_DEBUG, "tcp_sock_connect()"); … … 309 321 310 322 if (socket->laddr.ipv4 == TCP_IPV4_ANY) { 311 /* Find route to determine local IP address. */ 312 rc = ip_get_route_req(ip_sess, IPPROTO_TCP, 313 (struct sockaddr *)addr, sizeof(*addr), &dev_id, 314 (void **)&phdr, &phdr_len); 323 /* Determine local IP address */ 324 inet_addr_t loc_addr, rem_addr; 325 326 rem_addr.ipv4 = uint32_t_be2host(addr->sin_addr.s_addr); 327 rc = inet_get_srcaddr(&rem_addr, 0, &loc_addr); 315 328 if (rc != EOK) { 316 329 fibril_mutex_unlock(&socket->lock); 317 330 async_answer_0(callid, rc); 318 log_msg(LVL_DEBUG, "tcp_transmit_connect: Failed to find route."); 319 return; 320 } 321 322 socket->laddr.ipv4 = uint32_t_be2host(phdr->src_addr); 331 log_msg(LVL_DEBUG, "tcp_sock_connect: Failed to " 332 "determine local address."); 333 return; 334 } 335 336 socket->laddr.ipv4 = loc_addr.ipv4; 323 337 log_msg(LVL_DEBUG, "Local IP address is %x", socket->laddr.ipv4); 324 free(phdr);325 338 } 326 339 … … 455 468 assert(asock_core != NULL); 456 469 457 refresh_answer(&answer, NULL);458 459 470 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, FRAGMENT_SIZE); 460 471 SOCKET_SET_SOCKET_ID(answer, asock_id); 461 472 SOCKET_SET_ADDRESS_LENGTH(answer, sizeof(struct sockaddr_in)); 462 463 answer_call(callid, asock_core->socket_id, &answer, 3); 464 473 474 async_answer_3(callid, asock_core->socket_id, 475 IPC_GET_ARG1(answer), IPC_GET_ARG2(answer), 476 IPC_GET_ARG3(answer)); 477 465 478 /* Push one fragment notification to client's queue */ 466 479 log_msg(LVL_DEBUG, "tcp_sock_accept(): notify data\n"); … … 546 559 } 547 560 548 refresh_answer(&answer, NULL);561 IPC_SET_ARG1(answer, 0); 549 562 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, FRAGMENT_SIZE); 550 answer_call(callid, EOK, &answer, 2); 563 async_answer_2(callid, EOK, IPC_GET_ARG1(answer), 564 IPC_GET_ARG2(answer)); 551 565 fibril_mutex_unlock(&socket->lock); 552 566 } … … 666 680 667 681 SOCKET_SET_READ_DATA_LENGTH(answer, length); 668 a nswer_call(callid, EOK, &answer, 1);669 682 async_answer_1(callid, EOK, IPC_GET_ARG1(answer)); 683 670 684 /* Push one fragment notification to client's queue */ 671 685 tcp_sock_notify_data(sock_core); … … 713 727 } 714 728 715 rc = socket_destroy( net_sess, socket_id, &client->sockets, &gsock,729 rc = socket_destroy(NULL, socket_id, &client->sockets, &gsock, 716 730 tcp_free_sock_data); 717 731 if (rc != EOK) { … … 764 778 } 765 779 766 int tcp_sock_connection(async_sess_t *sess, ipc_callid_t iid, ipc_call_t icall)780 static void tcp_sock_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 767 781 { 768 782 ipc_callid_t callid; … … 773 787 async_answer_0(iid, EOK); 774 788 775 client.sess = sess;789 client.sess = async_callback_receive(EXCHANGE_SERIALIZE); 776 790 socket_cores_initialize(&client.sockets); 777 791 … … 825 839 } 826 840 827 return EOK; 841 /* Clean up */ 842 log_msg(LVL_DEBUG, "tcp_sock_connection: Clean up"); 843 async_hangup(client.sess); 844 socket_cores_release(NULL, &client.sockets, &gsock, tcp_free_sock_data); 828 845 } 829 846
Note:
See TracChangeset
for help on using the changeset viewer.