Changeset 0edaf0f6 in mainline for uspace/srv/net/tl/tcp/ucall.c
- Timestamp:
- 2011-12-16T18:04:30Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ab9378b4
- Parents:
- 7a8c1c4e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/tcp/ucall.c
r7a8c1c4e r0edaf0f6 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-> cstate_lock);85 fibril_mutex_lock(&nconn->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-> cstate_lock);89 fibril_condvar_wait(&nconn->cstate_cv, &nconn->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-> cstate_lock);95 fibril_mutex_unlock(&nconn->lock); 96 96 return TCP_ERESET; 97 97 } 98 98 99 fibril_mutex_unlock(&nconn-> cstate_lock);99 fibril_mutex_unlock(&nconn->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 if (conn->cstate == st_closed) 115 fibril_mutex_lock(&conn->lock); 116 117 if (conn->cstate == st_closed) { 118 fibril_mutex_unlock(&conn->lock); 116 119 return TCP_ENOTEXIST; 120 } 117 121 118 122 if (conn->cstate == st_listen) { … … 121 125 } 122 126 123 fibril_mutex_lock(&conn->snd_buf_lock);124 127 125 128 if (conn->snd_buf_fin) { 126 fibril_mutex_unlock(&conn-> snd_buf_lock);129 fibril_mutex_unlock(&conn->lock); 127 130 return TCP_ECLOSING; 128 131 } … … 133 136 log_msg(LVL_DEBUG, "%s: buf_free == 0, waiting.", 134 137 conn->name); 135 fibril_condvar_wait(&conn->snd_buf_cv, 136 &conn->snd_buf_lock); 138 fibril_condvar_wait(&conn->snd_buf_cv, &conn->lock); 137 139 buf_free = conn->snd_buf_size - conn->snd_buf_used; 138 140 } 139 141 140 142 if (conn->reset) { 141 fibril_mutex_unlock(&conn-> snd_buf_lock);143 fibril_mutex_unlock(&conn->lock); 142 144 return TCP_ERESET; 143 145 } … … 151 153 size -= xfer_size; 152 154 153 fibril_mutex_unlock(&conn->snd_buf_lock);154 155 tcp_tqueue_new_data(conn); 155 fibril_mutex_lock(&conn->snd_buf_lock); 156 } 157 158 fibril_mutex_unlock(&conn->snd_buf_lock); 156 } 157 159 158 tcp_tqueue_new_data(conn); 159 fibril_mutex_unlock(&conn->lock); 160 160 161 161 return TCP_EOK; … … 170 170 log_msg(LVL_DEBUG, "%s: tcp_uc_receive()", conn->name); 171 171 172 if (conn->cstate == st_closed) 172 fibril_mutex_lock(&conn->lock); 173 174 if (conn->cstate == st_closed) { 175 fibril_mutex_unlock(&conn->lock); 173 176 return TCP_ENOTEXIST; 174 175 fibril_mutex_lock(&conn->rcv_buf_lock); 177 } 176 178 177 179 /* Wait for data to become available */ 178 180 while (conn->rcv_buf_used == 0 && !conn->rcv_buf_fin && !conn->reset) { 179 181 log_msg(LVL_DEBUG, "tcp_uc_receive() - wait for data"); 180 fibril_condvar_wait(&conn->rcv_buf_cv, &conn-> rcv_buf_lock);182 fibril_condvar_wait(&conn->rcv_buf_cv, &conn->lock); 181 183 } 182 184 183 185 if (conn->rcv_buf_used == 0) { 184 fibril_mutex_unlock(&conn->rcv_buf_lock);185 186 186 *rcvd = 0; 187 187 *xflags = 0; … … 189 189 if (conn->rcv_buf_fin) { 190 190 /* End of data, peer closed connection */ 191 fibril_mutex_unlock(&conn->lock); 191 192 return TCP_ECLOSING; 192 193 } else { 193 194 /* Connection was reset */ 194 195 assert(conn->reset); 196 fibril_mutex_unlock(&conn->lock); 195 197 return TCP_ERESET; 196 198 } … … 208 210 conn->rcv_wnd += xfer_size; 209 211 210 fibril_mutex_unlock(&conn->rcv_buf_lock);211 212 212 /* TODO */ 213 213 *xflags = 0; … … 219 219 conn->name, xfer_size); 220 220 221 fibril_mutex_unlock(&conn->lock); 222 221 223 return TCP_EOK; 222 224 } … … 227 229 log_msg(LVL_DEBUG, "%s: tcp_uc_close()", conn->name); 228 230 229 if (conn->cstate == st_closed) 231 fibril_mutex_lock(&conn->lock); 232 233 if (conn->cstate == st_closed) { 234 fibril_mutex_unlock(&conn->lock); 230 235 return TCP_ENOTEXIST; 231 232 if (conn->snd_buf_fin) 236 } 237 238 if (conn->snd_buf_fin) { 239 fibril_mutex_unlock(&conn->lock); 233 240 return TCP_ECLOSING; 241 } 234 242 235 243 conn->snd_buf_fin = true; 236 244 tcp_tqueue_new_data(conn); 237 245 246 fibril_mutex_unlock(&conn->lock); 238 247 return TCP_EOK; 239 248 } … … 276 285 sp->local.addr.ipv4, sp->local.port); 277 286 278 conn = tcp_conn_find(sp); 279 if (conn != NULL && conn->cstate != st_closed) { 280 if (conn->ident.foreign.addr.ipv4 == TCP_IPV4_ANY) 281 conn->ident.foreign.addr.ipv4 = sp->foreign.addr.ipv4; 282 if (conn->ident.foreign.port == TCP_PORT_ANY) 283 conn->ident.foreign.port = sp->foreign.port; 284 if (conn->ident.local.addr.ipv4 == TCP_IPV4_ANY) 285 conn->ident.local.addr.ipv4 = sp->local.addr.ipv4; 286 287 tcp_conn_segment_arrived(conn, seg); 288 } else { 289 if (conn == NULL) 290 log_msg(LVL_WARN, "No connection found."); 291 else 292 log_msg(LVL_WARN, "Connection is closed."); 287 conn = tcp_conn_find_ref(sp); 288 if (conn == NULL) { 289 log_msg(LVL_WARN, "No connection found."); 293 290 tcp_unexpected_segment(sp, seg); 294 } 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); 295 315 } 296 316
Note:
See TracChangeset
for help on using the changeset viewer.