Differences From Artifact [b7f838da94]:
- File
src/OFUDPSocket.m
— part of check-in
[ed4549ddd3]
at
2015-10-17 10:59:15
on branch trunk
— Add a port registry for the Wii
This is necessary as the Wii does not allow picking a random free port,
and thus we need to track which ports are used. (user: js, size: 13789) [annotate] [blame] [check-ins using]
To Artifact [3db951aa5f]:
- File src/OFUDPSocket.m — part of check-in [1ba08eebc5] at 2015-10-19 22:15:13 on branch trunk — Add platform.h & make platform defines consistent (user: js, size: 13796) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
181 182 183 184 185 186 187 | #endif if (address1->address.ss_family != address2->address.ss_family) return false; switch (address1->address.ss_family) { case AF_INET: | | | 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | #endif if (address1->address.ss_family != address2->address.ss_family) return false; switch (address1->address.ss_family) { case AF_INET: #ifndef OF_WII if (address1->length < sizeof(struct sockaddr_in) || address2->length < sizeof(struct sockaddr_in)) @throw [OFInvalidArgumentException exception]; #else if (address1->length < 8 || address2->length < 8) @throw [OFInvalidArgumentException exception]; #endif |
︙ | ︙ | |||
239 240 241 242 243 244 245 | size_t i; #endif hash += address->address.ss_family; switch (address->address.ss_family) { case AF_INET: | | | 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | size_t i; #endif hash += address->address.ss_family; switch (address->address.ss_family) { case AF_INET: #ifndef OF_WII if (address->length < sizeof(struct sockaddr_in)) @throw [OFInvalidArgumentException exception]; #else if (address->length < 8) @throw [OFInvalidArgumentException exception]; #endif |
︙ | ︙ | |||
382 383 384 385 386 387 388 | return [self retain]; } - (uint16_t)bindToHost: (OFString*)host port: (uint16_t)port { of_resolver_result_t **results; | | | | | 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | return [self retain]; } - (uint16_t)bindToHost: (OFString*)host port: (uint16_t)port { of_resolver_result_t **results; #ifndef OF_WII union { struct sockaddr_storage storage; struct sockaddr_in in; # ifdef AF_INET6 struct sockaddr_in6 in6; # endif } addr; socklen_t addrLen; #endif #ifdef OF_WII if (port == 0) port = of_socket_port_find(SOCK_DGRAM); else if (!of_socket_port_register(port, SOCK_DGRAM)) @throw [OFBindFailedException exceptionWithHost: host port: port socket: self errNo: EADDRINUSE]; #endif @try { results = of_resolve_host(host, port, SOCK_DGRAM); } @catch (id e) { #ifdef OF_WII of_socket_port_free(port, SOCK_DGRAM); #endif @throw e; } @try { #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) |
︙ | ︙ | |||
444 445 446 447 448 449 450 | @throw [OFBindFailedException exceptionWithHost: host port: port socket: self errNo: errNo]; } } @catch (id e) { | | | | | 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | @throw [OFBindFailedException exceptionWithHost: host port: port socket: self errNo: errNo]; } } @catch (id e) { #ifdef OF_WII of_socket_port_free(port, SOCK_DGRAM); #endif @throw e; } @finally { of_resolver_free(results); } if (port > 0) { #ifdef OF_WII _port = port; #endif return port; } #ifndef OF_WII addrLen = (socklen_t)sizeof(addr.storage); if (of_getsockname(_socket, (struct sockaddr*)&addr.storage, &addrLen) != 0) { int errNo = of_socket_errno(); close(_socket); _socket = INVALID_SOCKET; |
︙ | ︙ | |||
501 502 503 504 505 506 507 | ssize_t ret; if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; sender->length = (socklen_t)sizeof(sender->address); | | | 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 | ssize_t ret; if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; sender->length = (socklen_t)sizeof(sender->address); #ifndef OF_WINDOWS if ((ret = recvfrom(_socket, buffer, length, 0, (struct sockaddr*)&sender->address, &sender->length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: of_socket_errno()]; #else |
︙ | ︙ | |||
554 555 556 557 558 559 560 | - (void)sendBuffer: (const void*)buffer length: (size_t)length receiver: (const of_udp_socket_address_t*)receiver { if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; | | | 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 | - (void)sendBuffer: (const void*)buffer length: (size_t)length receiver: (const of_udp_socket_address_t*)receiver { if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_WINDOWS if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if (sendto(_socket, buffer, length, 0, (struct sockaddr*)&receiver->address, receiver->length) != (ssize_t)length) @throw [OFWriteFailedException |
︙ | ︙ | |||
586 587 588 589 590 591 592 | - (void)cancelAsyncRequests { [OFRunLoop OF_cancelAsyncRequestsForObject: self]; } - (int)fileDescriptorForReading { | | | | | 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 | - (void)cancelAsyncRequests { [OFRunLoop OF_cancelAsyncRequestsForObject: self]; } - (int)fileDescriptorForReading { #ifndef OF_WINDOWS return _socket; #else if (_socket == INVALID_SOCKET) return -1; if (_socket > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)_socket; #endif } - (int)fileDescriptorForWriting { #ifndef OF_WINDOWS return _socket; #else if (_socket == INVALID_SOCKET) return -1; if (_socket > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)_socket; #endif } - (void)close { if (_socket == INVALID_SOCKET) @throw [OFNotOpenException exceptionWithObject: self]; close(_socket); _socket = INVALID_SOCKET; #ifdef OF_WII if (_port > 0) { of_socket_port_free(_port, SOCK_DGRAM); _port = 0; } #endif } @end |