Changeset 451481c8 in mainline
- Timestamp:
- 2013-03-14T12:15:24Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3ca2e36
- Parents:
- 8fc8969
- Location:
- uspace/srv/net/udp
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/udp/assoc.c
r8fc8969 r451481c8 200 200 /** Set local socket in association. 201 201 * 202 * @param assoc Association 203 * @param fsock Foreign socket (deeply copied) 202 * @param assoc Association 203 * @param lsock Local socket (deeply copied) 204 * 204 205 */ 205 206 void udp_assoc_set_local(udp_assoc_t *assoc, udp_sock_t *lsock) … … 208 209 fibril_mutex_lock(&assoc->lock); 209 210 assoc->ident.local = *lsock; 211 fibril_mutex_unlock(&assoc->lock); 212 } 213 214 /** Set local port in association. 215 * 216 * @param assoc Association 217 * @param lport Local port 218 * 219 */ 220 void udp_assoc_set_local_port(udp_assoc_t *assoc, uint16_t lport) 221 { 222 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_set_local(%p, %" PRIu16 ")", assoc, lport); 223 fibril_mutex_lock(&assoc->lock); 224 assoc->ident.local.port = lport; 210 225 fibril_mutex_unlock(&assoc->lock); 211 226 } -
uspace/srv/net/udp/assoc.h
r8fc8969 r451481c8 47 47 extern void udp_assoc_set_foreign(udp_assoc_t *, udp_sock_t *); 48 48 extern void udp_assoc_set_local(udp_assoc_t *, udp_sock_t *); 49 extern void udp_assoc_set_local_port(udp_assoc_t *, uint16_t); 49 50 extern int udp_assoc_send(udp_assoc_t *, udp_sock_t *, udp_msg_t *); 50 51 extern int udp_assoc_recv(udp_assoc_t *, udp_msg_t **, udp_sock_t *); -
uspace/srv/net/udp/sock.c
r8fc8969 r451481c8 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) || (sock_core->port == -1)) { 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 udp_error_t urc = udp_uc_set_local_port(socket->assoc, 302 sock_core->port); 303 304 if (urc != UDP_EOK) { 305 // TODO: better error handling 306 async_answer_0(callid, EINTR); 307 goto out; 308 } 309 } 310 312 311 fibril_mutex_lock(&socket->lock); 313 312 314 313 if (socket->assoc->ident.local.addr.ipv4 == UDP_IPV4_ANY) { 315 314 /* Determine local IP address */ 316 315 inet_addr_t loc_addr, rem_addr; 317 318 rem_addr.ipv4 = fsock p? fsock.addr.ipv4 :316 317 rem_addr.ipv4 = fsock_ptr ? fsock.addr.ipv4 : 319 318 socket->assoc->ident.foreign.addr.ipv4; 320 321 rc = inet_get_srcaddr(&rem_addr, 0, &loc_addr);319 320 int rc = inet_get_srcaddr(&rem_addr, 0, &loc_addr); 322 321 if (rc != EOK) { 323 322 fibril_mutex_unlock(&socket->lock); … … 327 326 return; 328 327 } 329 328 330 329 socket->assoc->ident.local.addr.ipv4 = loc_addr.ipv4; 331 330 log_msg(LOG_DEFAULT, LVL_DEBUG, "Local IP address is %x", 332 331 socket->assoc->ident.local.addr.ipv4); 333 332 } 334 335 333 336 334 assert(socket->assoc != NULL); 337 338 for (index = 0; index < fragments; index++) { 335 336 int fragments = SOCKET_GET_DATA_FRAGMENTS(call); 337 for (int index = 0; index < fragments; index++) { 338 ipc_callid_t wcallid; 339 size_t length; 340 339 341 if (!async_data_write_receive(&wcallid, &length)) { 340 342 fibril_mutex_unlock(&socket->lock); … … 342 344 goto out; 343 345 } 344 346 345 347 if (length > UDP_FRAGMENT_SIZE) 346 348 length = UDP_FRAGMENT_SIZE; 347 348 rc = async_data_write_finalize(wcallid, buffer, length); 349 350 uint8_t buffer[UDP_FRAGMENT_SIZE]; 351 int rc = async_data_write_finalize(wcallid, buffer, length); 349 352 if (rc != EOK) { 350 353 fibril_mutex_unlock(&socket->lock); … … 352 355 goto out; 353 356 } 354 355 urc = udp_uc_send(socket->assoc, fsockp, buffer, length, 0); 356 357 358 udp_error_t urc = 359 udp_uc_send(socket->assoc, fsock_ptr, buffer, length, 0); 360 357 361 switch (urc) { 358 362 case UDP_EOK: … … 371 375 assert(false); 372 376 } 373 377 374 378 if (rc != EOK) { 375 379 fibril_mutex_unlock(&socket->lock); … … 378 382 } 379 383 } 384 385 ipc_call_t answer; 380 386 381 387 IPC_SET_ARG1(answer, 0); -
uspace/srv/net/udp/ucall.c
r8fc8969 r451481c8 68 68 { 69 69 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_set_local(%p, %p)", assoc, lsock); 70 71 udp_assoc_set_local(assoc, lsock); 72 return UDP_EOK; 73 } 70 74 71 udp_assoc_set_local(assoc, lsock); 75 udp_error_t udp_uc_set_local_port(udp_assoc_t *assoc, uint16_t lport) 76 { 77 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_uc_set_local(%p, %" PRIu16 ")", assoc, lport); 78 79 udp_assoc_set_local_port(assoc, lport); 72 80 return UDP_EOK; 73 81 } -
uspace/srv/net/udp/ucall.h
r8fc8969 r451481c8 42 42 extern udp_error_t udp_uc_set_foreign(udp_assoc_t *, udp_sock_t *); 43 43 extern udp_error_t udp_uc_set_local(udp_assoc_t *, udp_sock_t *); 44 extern udp_error_t udp_uc_set_local_port(udp_assoc_t *, uint16_t); 44 45 extern udp_error_t udp_uc_send(udp_assoc_t *, udp_sock_t *, void *, size_t, 45 46 xflags_t);
Note:
See TracChangeset
for help on using the changeset viewer.