Changes in uspace/srv/net/tl/tcp/ucall.c [0edaf0f6:74c99b5] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/tcp/ucall.c
r0edaf0f6 r74c99b5 83 83 /* Wait for connection to be established or reset */ 84 84 log_msg(LVL_DEBUG, "tcp_uc_open: Wait for connection."); 85 fibril_mutex_lock(&nconn-> lock);85 fibril_mutex_lock(&nconn->cstate_lock); 86 86 while (nconn->cstate == st_listen || 87 87 nconn->cstate == st_syn_sent || 88 88 nconn->cstate == st_syn_received) { 89 fibril_condvar_wait(&nconn->cstate_cv, &nconn-> lock);89 fibril_condvar_wait(&nconn->cstate_cv, &nconn->cstate_lock); 90 90 } 91 91 … … 93 93 log_msg(LVL_DEBUG, "tcp_uc_open: Connection was reset."); 94 94 assert(nconn->cstate == st_closed); 95 fibril_mutex_unlock(&nconn-> lock);95 fibril_mutex_unlock(&nconn->cstate_lock); 96 96 return TCP_ERESET; 97 97 } 98 98 99 fibril_mutex_unlock(&nconn-> lock);99 fibril_mutex_unlock(&nconn->cstate_lock); 100 100 log_msg(LVL_DEBUG, "tcp_uc_open: Connection was established."); 101 101 … … 113 113 log_msg(LVL_DEBUG, "%s: tcp_uc_send()", conn->name); 114 114 115 fibril_mutex_lock(&conn->lock); 116 117 if (conn->cstate == st_closed) { 118 fibril_mutex_unlock(&conn->lock); 115 if (conn->cstate == st_closed) 119 116 return TCP_ENOTEXIST; 120 }121 117 122 118 if (conn->cstate == st_listen) { … … 125 121 } 126 122 127 128 if (conn->snd_buf_fin) { 129 fibril_mutex_unlock(&conn->lock); 123 if (conn->snd_buf_fin) 130 124 return TCP_ECLOSING; 131 }132 125 133 126 while (size > 0) { 134 127 buf_free = conn->snd_buf_size - conn->snd_buf_used; 135 while (buf_free == 0 && !conn->reset) { 136 log_msg(LVL_DEBUG, "%s: buf_free == 0, waiting.", 137 conn->name); 138 fibril_condvar_wait(&conn->snd_buf_cv, &conn->lock); 139 buf_free = conn->snd_buf_size - conn->snd_buf_used; 140 } 141 142 if (conn->reset) { 143 fibril_mutex_unlock(&conn->lock); 128 while (buf_free == 0 && !conn->reset) 129 tcp_tqueue_new_data(conn); 130 131 if (conn->reset) 144 132 return TCP_ERESET; 145 }146 133 147 134 xfer_size = min(size, buf_free); … … 152 139 conn->snd_buf_used += xfer_size; 153 140 size -= xfer_size; 154 155 tcp_tqueue_new_data(conn);156 141 } 157 142 158 143 tcp_tqueue_new_data(conn); 159 fibril_mutex_unlock(&conn->lock);160 144 161 145 return TCP_EOK; … … 170 154 log_msg(LVL_DEBUG, "%s: tcp_uc_receive()", conn->name); 171 155 172 fibril_mutex_lock(&conn->lock); 173 174 if (conn->cstate == st_closed) { 175 fibril_mutex_unlock(&conn->lock); 156 if (conn->cstate == st_closed) 176 157 return TCP_ENOTEXIST; 177 } 158 159 fibril_mutex_lock(&conn->rcv_buf_lock); 178 160 179 161 /* Wait for data to become available */ 180 162 while (conn->rcv_buf_used == 0 && !conn->rcv_buf_fin && !conn->reset) { 181 163 log_msg(LVL_DEBUG, "tcp_uc_receive() - wait for data"); 182 fibril_condvar_wait(&conn->rcv_buf_cv, &conn-> lock);164 fibril_condvar_wait(&conn->rcv_buf_cv, &conn->rcv_buf_lock); 183 165 } 184 166 185 167 if (conn->rcv_buf_used == 0) { 168 fibril_mutex_unlock(&conn->rcv_buf_lock); 169 186 170 *rcvd = 0; 187 171 *xflags = 0; … … 189 173 if (conn->rcv_buf_fin) { 190 174 /* End of data, peer closed connection */ 191 fibril_mutex_unlock(&conn->lock);192 175 return TCP_ECLOSING; 193 176 } else { 194 177 /* Connection was reset */ 195 178 assert(conn->reset); 196 fibril_mutex_unlock(&conn->lock);197 179 return TCP_ERESET; 198 180 } … … 210 192 conn->rcv_wnd += xfer_size; 211 193 194 fibril_mutex_unlock(&conn->rcv_buf_lock); 195 212 196 /* TODO */ 213 197 *xflags = 0; … … 219 203 conn->name, xfer_size); 220 204 221 fibril_mutex_unlock(&conn->lock);222 223 205 return TCP_EOK; 224 206 } … … 229 211 log_msg(LVL_DEBUG, "%s: tcp_uc_close()", conn->name); 230 212 231 fibril_mutex_lock(&conn->lock); 232 233 if (conn->cstate == st_closed) { 234 fibril_mutex_unlock(&conn->lock); 213 if (conn->cstate == st_closed) 235 214 return TCP_ENOTEXIST; 236 } 237 238 if (conn->snd_buf_fin) { 239 fibril_mutex_unlock(&conn->lock); 215 216 if (conn->snd_buf_fin) 240 217 return TCP_ECLOSING; 241 }242 218 243 219 conn->snd_buf_fin = true; 244 220 tcp_tqueue_new_data(conn); 245 221 246 fibril_mutex_unlock(&conn->lock);247 222 return TCP_EOK; 248 223 } … … 260 235 } 261 236 262 /** Delete connection user call.263 *264 * (Not in spec.) Inform TCP that the user is done with this connection265 * and will not make any further calls/references to it. TCP can deallocate266 * the connection from now on.267 */268 void tcp_uc_delete(tcp_conn_t *conn)269 {270 log_msg(LVL_DEBUG, "tcp_uc_delete()");271 tcp_conn_delete(conn);272 }273 237 274 238 /* … … 285 249 sp->local.addr.ipv4, sp->local.port); 286 250 287 conn = tcp_conn_find_ref(sp); 288 if (conn == NULL) { 289 log_msg(LVL_WARN, "No connection found."); 251 conn = tcp_conn_find(sp); 252 if (conn != NULL && conn->cstate != st_closed) { 253 if (conn->ident.foreign.addr.ipv4 == TCP_IPV4_ANY) 254 conn->ident.foreign.addr.ipv4 = sp->foreign.addr.ipv4; 255 if (conn->ident.foreign.port == TCP_PORT_ANY) 256 conn->ident.foreign.port = sp->foreign.port; 257 if (conn->ident.local.addr.ipv4 == TCP_IPV4_ANY) 258 conn->ident.local.addr.ipv4 = sp->local.addr.ipv4; 259 260 tcp_conn_segment_arrived(conn, seg); 261 } else { 262 if (conn == NULL) 263 log_msg(LVL_WARN, "No connection found."); 264 else 265 log_msg(LVL_WARN, "Connection is closed."); 290 266 tcp_unexpected_segment(sp, seg); 291 return; 292 } 293 294 fibril_mutex_lock(&conn->lock); 295 296 if (conn->cstate == st_closed) { 297 log_msg(LVL_WARN, "Connection is closed."); 298 tcp_unexpected_segment(sp, seg); 299 fibril_mutex_unlock(&conn->lock); 300 tcp_conn_delref(conn); 301 return; 302 } 303 304 if (conn->ident.foreign.addr.ipv4 == TCP_IPV4_ANY) 305 conn->ident.foreign.addr.ipv4 = sp->foreign.addr.ipv4; 306 if (conn->ident.foreign.port == TCP_PORT_ANY) 307 conn->ident.foreign.port = sp->foreign.port; 308 if (conn->ident.local.addr.ipv4 == TCP_IPV4_ANY) 309 conn->ident.local.addr.ipv4 = sp->local.addr.ipv4; 310 311 tcp_conn_segment_arrived(conn, seg); 312 313 fibril_mutex_unlock(&conn->lock); 314 tcp_conn_delref(conn); 267 } 315 268 } 316 269
Note:
See TracChangeset
for help on using the changeset viewer.