Changes in uspace/srv/net/tcp/ucall.c [8499160:c0f3460] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tcp/ucall.c
r8499160 rc0f3460 1 1 /* 2 * Copyright (c) 201 5Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 35 35 */ 36 36 37 #include <errno.h>38 37 #include <fibril_synch.h> 39 38 #include <io/log.h> … … 51 50 /** OPEN user call 52 51 * 53 * @param epp Endpoint pair 52 * @param lsock Local socket 53 * @param fsock Foreign socket 54 54 * @param acpass Active/passive 55 55 * @param oflags Open flags … … 65 65 * establishment. 66 66 */ 67 tcp_error_t tcp_uc_open( inet_ep2_t *epp, acpass_t acpass,67 tcp_error_t tcp_uc_open(tcp_sock_t *lsock, tcp_sock_t *fsock, acpass_t acpass, 68 68 tcp_open_flags_t oflags, tcp_conn_t **conn) 69 69 { 70 70 tcp_conn_t *nconn; 71 int rc; 72 73 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open(%p, %s, %s, %p)", 74 epp, acpass == ap_active ? "active" : "passive", 71 72 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open(%p, %p, %s, %s, %p)", 73 lsock, fsock, acpass == ap_active ? "active" : "passive", 75 74 oflags == tcp_open_nonblock ? "nonblock" : "none", conn); 76 75 77 nconn = tcp_conn_new(epp); 78 rc = tcp_conn_add(nconn); 79 if (rc != EOK) { 80 tcp_conn_delete(nconn); 81 return TCP_EEXISTS; 82 } 83 84 tcp_conn_lock(nconn); 76 nconn = tcp_conn_new(lsock, fsock); 77 tcp_conn_add(nconn); 85 78 86 79 if (acpass == ap_active) { … … 90 83 91 84 if (oflags == tcp_open_nonblock) { 92 tcp_conn_unlock(nconn);93 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open -> %p", nconn);94 85 *conn = nconn; 95 86 return TCP_EOK; … … 98 89 /* Wait for connection to be established or reset */ 99 90 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open: Wait for connection."); 91 fibril_mutex_lock(&nconn->lock); 100 92 while (nconn->cstate == st_listen || 101 93 nconn->cstate == st_syn_sent || … … 107 99 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open: Connection was reset."); 108 100 assert(nconn->cstate == st_closed); 109 tcp_conn_unlock(nconn);101 fibril_mutex_unlock(&nconn->lock); 110 102 return TCP_ERESET; 111 103 } 112 104 113 tcp_conn_unlock(nconn);105 fibril_mutex_unlock(&nconn->lock); 114 106 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open: Connection was established."); 115 107 … … 128 120 log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: tcp_uc_send()", conn->name); 129 121 130 tcp_conn_lock(conn);122 fibril_mutex_lock(&conn->lock); 131 123 132 124 if (conn->cstate == st_closed) { 133 tcp_conn_unlock(conn);125 fibril_mutex_unlock(&conn->lock); 134 126 return TCP_ENOTEXIST; 135 127 } … … 142 134 143 135 if (conn->snd_buf_fin) { 144 tcp_conn_unlock(conn);136 fibril_mutex_unlock(&conn->lock); 145 137 return TCP_ECLOSING; 146 138 } … … 156 148 157 149 if (conn->reset) { 158 tcp_conn_unlock(conn);150 fibril_mutex_unlock(&conn->lock); 159 151 return TCP_ERESET; 160 152 } … … 172 164 173 165 tcp_tqueue_new_data(conn); 174 tcp_conn_unlock(conn);166 fibril_mutex_unlock(&conn->lock); 175 167 176 168 return TCP_EOK; … … 185 177 log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: tcp_uc_receive()", conn->name); 186 178 187 tcp_conn_lock(conn);179 fibril_mutex_lock(&conn->lock); 188 180 189 181 if (conn->cstate == st_closed) { 190 tcp_conn_unlock(conn);182 fibril_mutex_unlock(&conn->lock); 191 183 return TCP_ENOTEXIST; 192 184 } … … 194 186 /* Wait for data to become available */ 195 187 while (conn->rcv_buf_used == 0 && !conn->rcv_buf_fin && !conn->reset) { 196 tcp_conn_unlock(conn);197 return TCP_EAGAIN;198 188 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_receive() - wait for data"); 199 189 fibril_condvar_wait(&conn->rcv_buf_cv, &conn->lock); … … 206 196 if (conn->rcv_buf_fin) { 207 197 /* End of data, peer closed connection */ 208 tcp_conn_unlock(conn);198 fibril_mutex_unlock(&conn->lock); 209 199 return TCP_ECLOSING; 210 200 } else { 211 201 /* Connection was reset */ 212 202 assert(conn->reset); 213 tcp_conn_unlock(conn);203 fibril_mutex_unlock(&conn->lock); 214 204 return TCP_ERESET; 215 205 } … … 236 226 conn->name, xfer_size); 237 227 238 tcp_conn_unlock(conn);228 fibril_mutex_unlock(&conn->lock); 239 229 240 230 return TCP_EOK; … … 244 234 tcp_error_t tcp_uc_close(tcp_conn_t *conn) 245 235 { 246 log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: tcp_uc_close(%p)", conn->name, 247 conn); 248 249 tcp_conn_lock(conn); 236 log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: tcp_uc_close()", conn->name); 237 238 fibril_mutex_lock(&conn->lock); 250 239 251 240 if (conn->cstate == st_closed) { 252 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_close - ENOTEXIST"); 253 tcp_conn_unlock(conn); 241 fibril_mutex_unlock(&conn->lock); 254 242 return TCP_ENOTEXIST; 255 243 } 256 244 257 if (conn->cstate == st_listen || conn->cstate == st_syn_sent) {258 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_close - listen/syn_sent");259 tcp_conn_reset(conn);260 tcp_conn_unlock(conn);261 return TCP_EOK;262 }263 264 245 if (conn->snd_buf_fin) { 265 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_close - ECLOSING"); 266 tcp_conn_unlock(conn); 246 fibril_mutex_unlock(&conn->lock); 267 247 return TCP_ECLOSING; 268 248 } 269 249 270 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_close - set snd_buf_fin");271 250 conn->snd_buf_fin = true; 272 251 tcp_tqueue_new_data(conn); 273 252 274 tcp_conn_unlock(conn);253 fibril_mutex_unlock(&conn->lock); 275 254 return TCP_EOK; 276 255 } … … 301 280 } 302 281 303 void tcp_uc_set_c b(tcp_conn_t *conn, tcp_cb_t *cb, void *arg)304 { 305 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_set_c b(%p, %p, %p)",282 void tcp_uc_set_cstate_cb(tcp_conn_t *conn, tcp_cstate_cb_t cb, void *arg) 283 { 284 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_set_ctate_cb(%p, %p, %p)", 306 285 conn, cb, arg); 307 286 308 conn->cb = cb; 309 conn->cb_arg = arg; 310 } 311 312 void *tcp_uc_get_userptr(tcp_conn_t *conn) 313 { 314 return conn->cb_arg; 287 conn->cstate_cb = cb; 288 conn->cstate_cb_arg = arg; 315 289 } 316 290 … … 320 294 321 295 /** Segment arrived */ 322 void tcp_as_segment_arrived( inet_ep2_t *epp, tcp_segment_t *seg)296 void tcp_as_segment_arrived(tcp_sockpair_t *sp, tcp_segment_t *seg) 323 297 { 324 298 tcp_conn_t *conn; … … 326 300 log_msg(LOG_DEFAULT, LVL_DEBUG, 327 301 "tcp_as_segment_arrived(f:(%u), l:(%u))", 328 epp->remote.port, epp->local.port);329 330 conn = tcp_conn_find_ref( epp);302 sp->foreign.port, sp->local.port); 303 304 conn = tcp_conn_find_ref(sp); 331 305 if (conn == NULL) { 332 306 log_msg(LOG_DEFAULT, LVL_WARN, "No connection found."); 333 tcp_unexpected_segment( epp, seg);307 tcp_unexpected_segment(sp, seg); 334 308 return; 335 309 } 336 310 337 tcp_conn_segment_arrived(conn, epp, seg); 311 fibril_mutex_lock(&conn->lock); 312 313 if (conn->cstate == st_closed) { 314 log_msg(LOG_DEFAULT, LVL_WARN, "Connection is closed."); 315 tcp_unexpected_segment(sp, seg); 316 fibril_mutex_unlock(&conn->lock); 317 tcp_conn_delref(conn); 318 return; 319 } 320 321 if (inet_addr_is_any(&conn->ident.foreign.addr)) 322 conn->ident.foreign.addr = sp->foreign.addr; 323 324 if (conn->ident.foreign.port == TCP_PORT_ANY) 325 conn->ident.foreign.port = sp->foreign.port; 326 327 if (inet_addr_is_any(&conn->ident.local.addr)) 328 conn->ident.local.addr = sp->local.addr; 329 330 tcp_conn_segment_arrived(conn, seg); 331 332 fibril_mutex_unlock(&conn->lock); 338 333 tcp_conn_delref(conn); 339 334 }
Note:
See TracChangeset
for help on using the changeset viewer.