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