Changeset 1440eae in mainline for uspace/srv/net/tl/tcp/ucall.c
- Timestamp:
- 2011-12-22T12:04:54Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3819ce5
- Parents:
- 65d7b0a (diff), a438de4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/tcp/ucall.c
r65d7b0a r1440eae 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 if (conn->snd_buf_fin) 127 128 if (conn->snd_buf_fin) { 129 fibril_mutex_unlock(&conn->lock); 124 130 return TCP_ECLOSING; 131 } 125 132 126 133 while (size > 0) { 127 134 buf_free = conn->snd_buf_size - conn->snd_buf_used; 128 while (buf_free == 0 && !conn->reset) 129 tcp_tqueue_new_data(conn); 130 131 if (conn->reset) 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); 132 144 return TCP_ERESET; 145 } 133 146 134 147 xfer_size = min(size, buf_free); … … 139 152 conn->snd_buf_used += xfer_size; 140 153 size -= xfer_size; 154 155 tcp_tqueue_new_data(conn); 141 156 } 142 157 143 158 tcp_tqueue_new_data(conn); 159 fibril_mutex_unlock(&conn->lock); 144 160 145 161 return TCP_EOK; … … 154 170 log_msg(LVL_DEBUG, "%s: tcp_uc_receive()", conn->name); 155 171 156 if (conn->cstate == st_closed) 172 fibril_mutex_lock(&conn->lock); 173 174 if (conn->cstate == st_closed) { 175 fibril_mutex_unlock(&conn->lock); 157 176 return TCP_ENOTEXIST; 158 159 fibril_mutex_lock(&conn->rcv_buf_lock); 177 } 160 178 161 179 /* Wait for data to become available */ 162 180 while (conn->rcv_buf_used == 0 && !conn->rcv_buf_fin && !conn->reset) { 163 181 log_msg(LVL_DEBUG, "tcp_uc_receive() - wait for data"); 164 fibril_condvar_wait(&conn->rcv_buf_cv, &conn-> rcv_buf_lock);182 fibril_condvar_wait(&conn->rcv_buf_cv, &conn->lock); 165 183 } 166 184 167 185 if (conn->rcv_buf_used == 0) { 168 fibril_mutex_unlock(&conn->rcv_buf_lock);169 170 186 *rcvd = 0; 171 187 *xflags = 0; … … 173 189 if (conn->rcv_buf_fin) { 174 190 /* End of data, peer closed connection */ 191 fibril_mutex_unlock(&conn->lock); 175 192 return TCP_ECLOSING; 176 193 } else { 177 194 /* Connection was reset */ 178 195 assert(conn->reset); 196 fibril_mutex_unlock(&conn->lock); 179 197 return TCP_ERESET; 180 198 } … … 192 210 conn->rcv_wnd += xfer_size; 193 211 194 fibril_mutex_unlock(&conn->rcv_buf_lock);195 196 212 /* TODO */ 197 213 *xflags = 0; … … 203 219 conn->name, xfer_size); 204 220 221 fibril_mutex_unlock(&conn->lock); 222 205 223 return TCP_EOK; 206 224 } … … 211 229 log_msg(LVL_DEBUG, "%s: tcp_uc_close()", conn->name); 212 230 213 if (conn->cstate == st_closed) 231 fibril_mutex_lock(&conn->lock); 232 233 if (conn->cstate == st_closed) { 234 fibril_mutex_unlock(&conn->lock); 214 235 return TCP_ENOTEXIST; 215 216 if (conn->snd_buf_fin) 236 } 237 238 if (conn->snd_buf_fin) { 239 fibril_mutex_unlock(&conn->lock); 217 240 return TCP_ECLOSING; 241 } 218 242 219 243 conn->snd_buf_fin = true; 220 244 tcp_tqueue_new_data(conn); 221 245 246 fibril_mutex_unlock(&conn->lock); 222 247 return TCP_EOK; 223 248 } … … 235 260 } 236 261 262 /** Delete connection user call. 263 * 264 * (Not in spec.) Inform TCP that the user is done with this connection 265 * and will not make any further calls/references to it. TCP can deallocate 266 * 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 } 237 273 238 274 /* … … 249 285 sp->local.addr.ipv4, sp->local.port); 250 286 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."); 287 conn = tcp_conn_find_ref(sp); 288 if (conn == NULL) { 289 log_msg(LVL_WARN, "No connection found."); 266 290 tcp_unexpected_segment(sp, seg); 267 } 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); 268 315 } 269 316
Note:
See TracChangeset
for help on using the changeset viewer.