Changeset 004a5fe in mainline
- Timestamp:
- 2011-11-20T19:13:53Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- eea65f4
- Parents:
- 854e79a6
- Location:
- uspace/srv/net/tl/tcp
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/tcp/conn.c
r854e79a6 r004a5fe 111 111 tqueue_inited = true; 112 112 113 /* Connection state change signalling */ 114 fibril_mutex_initialize(&conn->cstate_lock); 115 fibril_condvar_initialize(&conn->cstate_cv); 116 113 117 conn->cstate = st_listen; 114 118 conn->fin_is_acked = false; … … 152 156 } 153 157 158 static void tcp_conn_state_set(tcp_conn_t *conn, tcp_cstate_t nstate) 159 { 160 fibril_mutex_lock(&conn->cstate_lock); 161 conn->cstate = nstate; 162 fibril_condvar_broadcast(&conn->cstate_cv); 163 fibril_mutex_unlock(&conn->cstate_lock); 164 } 165 154 166 /** Synchronize connection. 155 167 * … … 165 177 166 178 tcp_tqueue_ctrl_seg(conn, CTL_SYN); 167 conn->cstate = st_syn_sent;179 tcp_conn_state_set(conn, st_syn_sent); 168 180 } 169 181 … … 179 191 case st_established: 180 192 log_msg(LVL_DEBUG, "FIN sent -> Fin-Wait-1"); 181 conn->cstate = st_fin_wait_1;193 tcp_conn_state_set(conn, st_fin_wait_1); 182 194 break; 183 195 case st_close_wait: 184 196 log_msg(LVL_DEBUG, "FIN sent -> Last-Ack"); 185 conn->cstate = st_last_ack;197 tcp_conn_state_set(conn, st_last_ack); 186 198 break; 187 199 default: … … 328 340 conn->snd_wl2 = seg->seq; 329 341 330 conn->cstate = st_syn_received;342 tcp_conn_state_set(conn, st_syn_received); 331 343 332 344 tcp_tqueue_ctrl_seg(conn, CTL_SYN | CTL_ACK /* XXX */); … … 357 369 log_msg(LVL_DEBUG, "Connection reset. -> Closed"); 358 370 /* XXX Signal user error */ 359 conn->cstate = st_closed;371 tcp_conn_state_set(conn, st_closed); 360 372 /* XXX delete connection */ 361 373 return; … … 397 409 if (seq_no_syn_acked(conn)) { 398 410 log_msg(LVL_DEBUG, " syn acked -> Established"); 399 conn->cstate = st_established;411 tcp_conn_state_set(conn, st_established); 400 412 tcp_tqueue_ctrl_seg(conn, CTL_ACK /* XXX */); 401 413 } else { 402 414 log_msg(LVL_DEBUG, " syn not acked -> Syn-Received"); 403 conn->cstate = st_syn_received;415 tcp_conn_state_set(conn, st_syn_received); 404 416 tcp_tqueue_ctrl_seg(conn, CTL_SYN | CTL_ACK /* XXX */); 405 417 } … … 517 529 log_msg(LVL_DEBUG, "SYN ACKed -> Established"); 518 530 519 conn->cstate = st_established;531 tcp_conn_state_set(conn, st_established); 520 532 521 533 /* XXX Not mentioned in spec?! */ … … 590 602 if (conn->fin_is_acked) { 591 603 log_msg(LVL_DEBUG, " FIN acked -> Fin-Wait-2"); 592 conn->cstate = st_fin_wait_2;604 tcp_conn_state_set(conn, st_fin_wait_2); 593 605 } 594 606 … … 656 668 log_msg(LVL_DEBUG, " FIN acked -> Closed"); 657 669 tcp_conn_remove(conn); 658 conn->cstate = st_closed;670 tcp_conn_state_set(conn, st_closed); 659 671 return cp_done; 660 672 } … … 844 856 case st_established: 845 857 log_msg(LVL_DEBUG, "FIN received -> Close-Wait"); 846 conn->cstate = st_close_wait;858 tcp_conn_state_set(conn, st_close_wait); 847 859 break; 848 860 case st_fin_wait_1: 849 861 log_msg(LVL_DEBUG, "FIN received -> Closing"); 850 conn->cstate = st_closing;862 tcp_conn_state_set(conn, st_closing); 851 863 break; 852 864 case st_fin_wait_2: 853 865 log_msg(LVL_DEBUG, "FIN received -> Time-Wait"); 854 conn->cstate = st_time_wait;866 tcp_conn_state_set(conn, st_time_wait); 855 867 /* Start the Time-Wait timer */ 856 868 tcp_conn_tw_timer_set(conn); … … 980 992 981 993 tcp_conn_remove(conn); 982 conn->cstate = st_closed;994 tcp_conn_state_set(conn, st_closed); 983 995 } 984 996 -
uspace/srv/net/tl/tcp/state.c
r854e79a6 r004a5fe 58 58 * connection. 59 59 */ 60 voidtcp_uc_open(uint16_t lport, tcp_sock_t *fsock, acpass_t acpass,60 tcp_error_t tcp_uc_open(uint16_t lport, tcp_sock_t *fsock, acpass_t acpass, 61 61 tcp_conn_t **conn) 62 62 { … … 77 77 /* Synchronize (initiate) connection */ 78 78 tcp_conn_sync(nconn); 79 80 /* Wait for connection to be established or reset */ 81 log_msg(LVL_DEBUG, "tcp_uc_open: Wait for connection."); 82 fibril_mutex_lock(&nconn->cstate_lock); 83 while (nconn->cstate == st_syn_sent || 84 nconn->cstate == st_syn_received) { 85 fibril_condvar_wait(&nconn->cstate_cv, &nconn->cstate_lock); 86 } 87 if (nconn->cstate != st_established) { 88 log_msg(LVL_DEBUG, "tcp_uc_open: Connection was reset."); 89 assert(nconn->cstate == st_closed); 90 fibril_mutex_unlock(&nconn->cstate_lock); 91 return TCP_ERESET; 92 } 93 fibril_mutex_unlock(&nconn->cstate_lock); 94 log_msg(LVL_DEBUG, "tcp_uc_open: Connection was established."); 79 95 } 80 96 81 97 *conn = nconn; 98 return TCP_EOK; 82 99 } 83 100 -
uspace/srv/net/tl/tcp/state.h
r854e79a6 r004a5fe 42 42 * User calls 43 43 */ 44 extern voidtcp_uc_open(uint16_t, tcp_sock_t *, acpass_t, tcp_conn_t **);44 extern tcp_error_t tcp_uc_open(uint16_t, tcp_sock_t *, acpass_t, tcp_conn_t **); 45 45 extern tcp_error_t tcp_uc_send(tcp_conn_t *, void *, size_t, xflags_t); 46 46 extern tcp_error_t tcp_uc_receive(tcp_conn_t *, void *, size_t, size_t *, xflags_t *); -
uspace/srv/net/tl/tcp/tcp_type.h
r854e79a6 r004a5fe 146 146 /** Connection state */ 147 147 tcp_cstate_t cstate; 148 /** Protects @c cstate */ 149 fibril_mutex_t cstate_lock; 150 /** Signalled when @c cstate changes */ 151 fibril_condvar_t cstate_cv; 148 152 149 153 /** Set when FIN is removed from the retransmission queue */
Note:
See TracChangeset
for help on using the changeset viewer.