Changeset 06b0211b in mainline for uspace/srv/net/udp/sock.c
- Timestamp:
- 2013-04-29T11:29:45Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- aa2b32c
- Parents:
- ba4799a (diff), df956b9b (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/udp/sock.c
rba4799a r06b0211b 90 90 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_notify_data(%d)", sock_core->socket_id); 91 91 async_exch_t *exch = async_exchange_begin(sock_core->sess); 92 async_msg_5(exch, NET_SOCKET_RECEIVED, (sysarg_t) sock_core->socket_id,92 async_msg_5(exch, NET_SOCKET_RECEIVED, (sysarg_t) sock_core->socket_id, 93 93 UDP_FRAGMENT_SIZE, 0, 0, 1); 94 94 async_exchange_end(exch); … … 177 177 goto out; 178 178 } 179 179 180 if (addr_size != sizeof(struct sockaddr_in)) { 181 async_answer_0(callid, EINVAL); 182 goto out; 183 } 184 180 185 log_msg(LOG_DEFAULT, LVL_DEBUG, " - call socket_bind"); 181 186 rc = socket_bind(&client->sockets, &gsock, SOCKET_GET_SOCKET_ID(call), … … 186 191 goto out; 187 192 } 188 189 if (addr_size != sizeof(struct sockaddr_in)) { 190 async_answer_0(callid, EINVAL); 191 goto out; 192 } 193 193 194 194 log_msg(LOG_DEFAULT, LVL_DEBUG, " - call socket_cores_find"); 195 195 sock_core = socket_cores_find(&client->sockets, SOCKET_GET_SOCKET_ID(call)); … … 249 249 static void udp_sock_sendto(udp_client_t *client, ipc_callid_t callid, ipc_call_t call) 250 250 { 251 int socket_id;252 int fragments;253 int index;254 struct sockaddr_in *addr;255 size_t addr_size;256 socket_core_t *sock_core;257 udp_sockdata_t *socket;258 udp_sock_t fsock, *fsockp;259 ipc_call_t answer;260 ipc_callid_t wcallid;261 size_t length;262 uint8_t buffer[UDP_FRAGMENT_SIZE];263 udp_error_t urc;264 int rc;265 266 251 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_send()"); 267 268 addr = NULL; 269 252 253 struct sockaddr_in *addr = NULL; 254 udp_sock_t fsock; 255 udp_sock_t *fsock_ptr; 256 270 257 if (IPC_GET_IMETHOD(call) == NET_SOCKET_SENDTO) { 271 rc = async_data_write_accept((void **) &addr, false, 258 size_t addr_size; 259 int rc = async_data_write_accept((void **) &addr, false, 272 260 0, 0, 0, &addr_size); 273 261 if (rc != EOK) { … … 275 263 goto out; 276 264 } 277 265 278 266 if (addr_size != sizeof(struct sockaddr_in)) { 279 267 async_answer_0(callid, EINVAL); 280 268 goto out; 281 269 } 282 270 283 271 fsock.addr.ipv4 = uint32_t_be2host(addr->sin_addr.s_addr); 284 272 fsock.port = uint16_t_be2host(addr->sin_port); 285 fsockp = &fsock; 286 } else { 287 fsockp = NULL; 288 } 289 290 socket_id = SOCKET_GET_SOCKET_ID(call); 291 fragments = SOCKET_GET_DATA_FRAGMENTS(call); 273 fsock_ptr = &fsock; 274 } else 275 fsock_ptr = NULL; 276 277 int socket_id = SOCKET_GET_SOCKET_ID(call); 278 292 279 SOCKET_GET_FLAGS(call); 293 294 sock_core = socket_cores_find(&client->sockets, socket_id); 280 281 socket_core_t *sock_core = 282 socket_cores_find(&client->sockets, socket_id); 295 283 if (sock_core == NULL) { 296 284 async_answer_0(callid, ENOTSOCK); 297 285 goto out; 298 286 } 299 300 if (sock_core->port == 0) { 287 288 udp_sockdata_t *socket = 289 (udp_sockdata_t *) sock_core->specific_data; 290 291 if (sock_core->port <= 0) { 301 292 /* Implicitly bind socket to port */ 302 rc = socket_bind(&client->sockets, &gsock, SOCKET_GET_SOCKET_ID(call), 303 addr, addr_size, UDP_FREE_PORTS_START, UDP_FREE_PORTS_END, 304 last_used_port); 293 int rc = socket_bind_free_port(&gsock, sock_core, 294 UDP_FREE_PORTS_START, UDP_FREE_PORTS_END, last_used_port); 305 295 if (rc != EOK) { 306 296 async_answer_0(callid, rc); 307 297 goto out; 308 298 } 309 } 310 311 socket = (udp_sockdata_t *)sock_core->specific_data; 299 300 assert(sock_core->port > 0); 301 302 udp_error_t urc = udp_uc_set_local_port(socket->assoc, 303 sock_core->port); 304 305 if (urc != UDP_EOK) { 306 // TODO: better error handling 307 async_answer_0(callid, EINTR); 308 goto out; 309 } 310 311 last_used_port = sock_core->port; 312 } 313 312 314 fibril_mutex_lock(&socket->lock); 313 315 314 316 if (socket->assoc->ident.local.addr.ipv4 == UDP_IPV4_ANY) { 315 317 /* Determine local IP address */ 316 318 inet_addr_t loc_addr, rem_addr; 317 318 rem_addr.ipv4 = fsock p? fsock.addr.ipv4 :319 320 rem_addr.ipv4 = fsock_ptr ? fsock.addr.ipv4 : 319 321 socket->assoc->ident.foreign.addr.ipv4; 320 321 rc = inet_get_srcaddr(&rem_addr, 0, &loc_addr);322 323 int rc = inet_get_srcaddr(&rem_addr, 0, &loc_addr); 322 324 if (rc != EOK) { 323 325 fibril_mutex_unlock(&socket->lock); … … 327 329 return; 328 330 } 329 331 330 332 socket->assoc->ident.local.addr.ipv4 = loc_addr.ipv4; 331 333 log_msg(LOG_DEFAULT, LVL_DEBUG, "Local IP address is %x", 332 334 socket->assoc->ident.local.addr.ipv4); 333 335 } 334 335 336 336 337 assert(socket->assoc != NULL); 337 338 for (index = 0; index < fragments; index++) { 338 339 int fragments = SOCKET_GET_DATA_FRAGMENTS(call); 340 for (int index = 0; index < fragments; index++) { 341 ipc_callid_t wcallid; 342 size_t length; 343 339 344 if (!async_data_write_receive(&wcallid, &length)) { 340 345 fibril_mutex_unlock(&socket->lock); … … 342 347 goto out; 343 348 } 344 349 345 350 if (length > UDP_FRAGMENT_SIZE) 346 351 length = UDP_FRAGMENT_SIZE; 347 348 rc = async_data_write_finalize(wcallid, buffer, length); 352 353 uint8_t buffer[UDP_FRAGMENT_SIZE]; 354 int rc = async_data_write_finalize(wcallid, buffer, length); 349 355 if (rc != EOK) { 350 356 fibril_mutex_unlock(&socket->lock); … … 352 358 goto out; 353 359 } 354 355 urc = udp_uc_send(socket->assoc, fsockp, buffer, length, 0); 356 360 361 udp_error_t urc = 362 udp_uc_send(socket->assoc, fsock_ptr, buffer, length, 0); 363 357 364 switch (urc) { 358 365 case UDP_EOK: 359 366 rc = EOK; 360 367 break; 361 /* case TCP_ENOTEXIST:362 rc = ENO TCONN;363 break; 364 case TCP_ECLOSING:365 rc = E NOTCONN;366 break; 367 case TCP_ERESET:368 rc = E CONNABORTED;369 break; */368 case UDP_ENORES: 369 rc = ENOMEM; 370 break; 371 case UDP_EUNSPEC: 372 rc = EINVAL; 373 break; 374 case UDP_ENOROUTE: 375 rc = EIO; 376 break; 370 377 default: 371 378 assert(false); 372 379 } 373 380 374 381 if (rc != EOK) { 375 382 fibril_mutex_unlock(&socket->lock); … … 378 385 } 379 386 } 387 388 ipc_call_t answer; 380 389 381 390 IPC_SET_ARG1(answer, 0); … … 526 535 static void udp_sock_close(udp_client_t *client, ipc_callid_t callid, ipc_call_t call) 527 536 { 528 int socket_id;529 socket_core_t *sock_core;530 udp_sockdata_t *socket;531 int rc;532 533 537 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_sock_close()"); 534 socket_id = SOCKET_GET_SOCKET_ID(call); 535 536 sock_core = socket_cores_find(&client->sockets, socket_id); 538 int socket_id = SOCKET_GET_SOCKET_ID(call); 539 540 socket_core_t *sock_core = 541 socket_cores_find(&client->sockets, socket_id); 537 542 if (sock_core == NULL) { 538 543 async_answer_0(callid, ENOTSOCK); 539 544 return; 540 545 } 541 542 socket = (udp_sockdata_t *)sock_core->specific_data; 546 547 udp_sockdata_t *socket = 548 (udp_sockdata_t *) sock_core->specific_data; 543 549 fibril_mutex_lock(&socket->lock); 544 545 rc = socket_destroy(NULL, socket_id, &client->sockets, &gsock,550 551 int rc = socket_destroy(NULL, socket_id, &client->sockets, &gsock, 546 552 udp_free_sock_data); 547 553 if (rc != EOK) { … … 550 556 return; 551 557 } 552 558 553 559 fibril_mutex_unlock(&socket->lock); 554 560 async_answer_0(callid, EOK); … … 583 589 &sock->recv_buffer_lock); 584 590 } 585 591 586 592 log_msg(LOG_DEFAULT, LVL_DEBUG, "[] call udp_uc_receive()"); 587 593 urc = udp_uc_receive(sock->assoc, sock->recv_buffer, 588 594 UDP_FRAGMENT_SIZE, &rcvd, &xflags, &sock->recv_fsock); 589 595 sock->recv_error = urc; 590 596 591 597 udp_sock_notify_data(sock->sock_core); 592 598 593 599 if (urc != UDP_EOK) { 594 600 fibril_condvar_broadcast(&sock->recv_buffer_cv); … … 596 602 break; 597 603 } 598 604 599 605 log_msg(LOG_DEFAULT, LVL_DEBUG, "[] got data - broadcast recv_buffer_cv"); 600 606 601 607 sock->recv_buffer_used = rcvd; 602 608 fibril_mutex_unlock(&sock->recv_buffer_lock);
Note:
See TracChangeset
for help on using the changeset viewer.