Changeset 3c3259132706c07bf0046e922945974c0993f469
- Timestamp:
- 12/21/07 19:52:21
(8 months ago)
- Author:
- Pierre d'Herbemont <pdherbemont@videolan.org>
- git-committer:
- Pierre d'Herbemont <pdherbemont@videolan.org> 1198263141 +0000
- git-parent:
[54b8548a2f59a53851ecb2ab71047d712b4639af]
- git-author:
- Pierre d'Herbemont <pdherbemont@videolan.org> 1198263141 +0000
- Message:
modules/services_discovery/sap.c: Don't trust announcement down packet, but support implicit timeout.
* As suggested in the RFC we remove the discovered media if there is no new packet after three average packet period. (implicit timeout).
* Announcement of removal packet can be used to silently replace an announce by an other.
* Add a timeout argument to net_Select.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r5b7e0b5 |
r3c32591 |
|
| 124 | 124 | VLC_EXPORT( ssize_t, __net_Read, ( vlc_object_t *p_this, int fd, const v_socket_t *, uint8_t *p_data, size_t i_data, vlc_bool_t b_retry ) ); |
|---|
| 125 | 125 | |
|---|
| 126 | | #define net_Select(a,b,c,d,e) __net_Select(VLC_OBJECT(a),b,c,d,e) |
|---|
| 127 | | VLC_EXPORT( ssize_t, __net_Select, ( vlc_object_t *p_this, const int *pi_fd, int i_fd, uint8_t *p_data, size_t i_data ) ); |
|---|
| | 126 | #define net_Select(a,b,c,d,e,f) __net_Select(VLC_OBJECT(a),b,c,d,e,f) |
|---|
| | 127 | VLC_EXPORT( ssize_t, __net_Select, ( vlc_object_t *p_this, const int *pi_fd, int i_fd, uint8_t *p_data, size_t i_data, int i_timeout ) ); |
|---|
| 128 | 128 | |
|---|
| 129 | 129 | #define net_Write(a,b,c,d,e) __net_Write(VLC_OBJECT(a),b,c,d,e) |
|---|
| r23b12fc |
r3c32591 |
|
| 211 | 211 | { |
|---|
| 212 | 212 | mtime_t i_last; |
|---|
| | 213 | mtime_t i_period; |
|---|
| | 214 | uint8_t i_period_trust; |
|---|
| 213 | 215 | |
|---|
| 214 | 216 | uint16_t i_hash; |
|---|
| … | … | |
| 540 | 542 | i_read = net_Select( p_sd, p_sd->p_sys->pi_fd, |
|---|
| 541 | 543 | p_sd->p_sys->i_fd, p_buffer, |
|---|
| 542 | | MAX_SAP_BUFFER ); |
|---|
| | 544 | MAX_SAP_BUFFER, 500 ); |
|---|
| 543 | 545 | |
|---|
| 544 | 546 | /* Check for items that need deletion */ |
|---|
| … | … | |
| 546 | 548 | { |
|---|
| 547 | 549 | mtime_t i_timeout = ( mtime_t ) 1000000 * p_sd->p_sys->i_timeout; |
|---|
| 548 | | |
|---|
| 549 | | if( mdate() - p_sd->p_sys->pp_announces[i]->i_last > i_timeout ) |
|---|
| | 550 | sap_announce_t * p_announce = p_sd->p_sys->pp_announces[i]; |
|---|
| | 551 | mtime_t i_last_period = mdate() - p_announce->i_last; |
|---|
| | 552 | |
|---|
| | 553 | /* Remove the annoucement, if the last announcement was 1 hour ago |
|---|
| | 554 | * or if the last packet emitted was 3 times the average time |
|---|
| | 555 | * between two packets */ |
|---|
| | 556 | if( ( p_announce->i_period_trust > 5 && i_last_period > 3 * p_announce->i_period ) || |
|---|
| | 557 | i_last_period > i_timeout ) |
|---|
| 550 | 558 | { |
|---|
| 551 | | RemoveAnnounce( p_sd, p_sd->p_sys->pp_announces[i] ); |
|---|
| | 559 | RemoveAnnounce( p_sd, p_announce ); |
|---|
| 552 | 560 | } |
|---|
| 553 | 561 | } |
|---|
| … | … | |
| 738 | 746 | for( i = 0 ; i< p_sd->p_sys->i_announces ; i++ ) |
|---|
| 739 | 747 | { |
|---|
| | 748 | sap_announce_t * p_announce = p_sd->p_sys->pp_announces[i]; |
|---|
| 740 | 749 | /* FIXME: slow */ |
|---|
| 741 | 750 | /* FIXME: we create a new announce each time the sdp changes */ |
|---|
| 742 | | if( IsSameSession( p_sd->p_sys->pp_announces[i]->p_sdp, p_sdp ) ) |
|---|
| 743 | | { |
|---|
| 744 | | if( b_need_delete ) |
|---|
| | 751 | if( IsSameSession( p_announce->p_sdp, p_sdp ) ) |
|---|
| | 752 | { |
|---|
| | 753 | /* We don't support delete announcement as they can easily |
|---|
| | 754 | * Be used to highjack an announcement by a third party. |
|---|
| | 755 | * Intead we cleverly implement Implicit Announcement removal. |
|---|
| | 756 | * |
|---|
| | 757 | * if( b_need_delete ) |
|---|
| | 758 | * RemoveAnnounce( p_sd, p_sd->p_sys->pp_announces[i]); |
|---|
| | 759 | * else |
|---|
| | 760 | */ |
|---|
| | 761 | |
|---|
| | 762 | if( !b_need_delete ) |
|---|
| 745 | 763 | { |
|---|
| 746 | | RemoveAnnounce( p_sd, p_sd->p_sys->pp_announces[i]); |
|---|
| 747 | | } |
|---|
| 748 | | else |
|---|
| 749 | | { |
|---|
| 750 | | p_sd->p_sys->pp_announces[i]->i_last = mdate(); |
|---|
| | 764 | /* No need to go after six, as we start to trust the |
|---|
| | 765 | * average period at six */ |
|---|
| | 766 | if( p_announce->i_period_trust <= 5 ) |
|---|
| | 767 | p_announce->i_period_trust++; |
|---|
| | 768 | |
|---|
| | 769 | /* Compute the average period */ |
|---|
| | 770 | p_announce->i_period = (p_announce->i_period + (mdate() - p_announce->i_last)) / 2; |
|---|
| | 771 | p_announce->i_last = mdate(); |
|---|
| 751 | 772 | } |
|---|
| 752 | 773 | FreeSDP( p_sdp ); p_sdp = NULL; |
|---|
| … | … | |
| 775 | 796 | |
|---|
| 776 | 797 | p_sap->i_last = mdate(); |
|---|
| | 798 | p_sap->i_period = 0; |
|---|
| | 799 | p_sap->i_period_trust = 0; |
|---|
| 777 | 800 | p_sap->i_hash = i_hash; |
|---|
| 778 | 801 | p_sap->p_sdp = p_sdp; |
|---|
| r69d48f0 |
r3c32591 |
|
| 257 | 257 | net_ReadInner (vlc_object_t *restrict p_this, unsigned fdc, const int *fdv, |
|---|
| 258 | 258 | const v_socket_t *const *restrict vsv, |
|---|
| 259 | | uint8_t *restrict p_buf, size_t i_buflen, vlc_bool_t waitall) |
|---|
| | 259 | uint8_t *restrict p_buf, size_t i_buflen, vlc_bool_t waitall, |
|---|
| | 260 | int timeout) |
|---|
| 260 | 261 | { |
|---|
| 261 | 262 | size_t i_total = 0; |
|---|
| … | … | |
| 282 | 283 | } |
|---|
| 283 | 284 | |
|---|
| 284 | | switch (poll (ufd, fdc, 500)) |
|---|
| | 285 | switch (poll (ufd, fdc, timeout ? timeout : 500)) |
|---|
| 285 | 286 | { |
|---|
| 286 | 287 | case -1: |
|---|
| … | … | |
| 288 | 289 | |
|---|
| 289 | 290 | case 0: // timeout |
|---|
| | 291 | if( timeout ) return 0; |
|---|
| 290 | 292 | continue; |
|---|
| 291 | 293 | } |
|---|
| … | … | |
| 400 | 402 | return net_ReadInner( p_this, 1, &(int){ fd }, |
|---|
| 401 | 403 | &(const v_socket_t *){ p_vs }, |
|---|
| 402 | | buf, len, b_retry ); |
|---|
| | 404 | buf, len, b_retry, 0 ); |
|---|
| 403 | 405 | } |
|---|
| 404 | 406 | |
|---|
| … | … | |
| 408 | 410 | ***************************************************************************** |
|---|
| 409 | 411 | * Read from several sockets. Takes data from the first socket that has some. |
|---|
| | 412 | * if timeout is zero, net_Select will wait indefinitely. timeout is in |
|---|
| | 413 | * millisecond. |
|---|
| 410 | 414 | *****************************************************************************/ |
|---|
| 411 | 415 | ssize_t __net_Select( vlc_object_t *restrict p_this, |
|---|
| 412 | 416 | const int *restrict fds, int nfd, |
|---|
| 413 | | uint8_t *restrict buf, size_t len ) |
|---|
| | 417 | uint8_t *restrict buf, size_t len, |
|---|
| | 418 | int timeout ) |
|---|
| 414 | 419 | { |
|---|
| 415 | 420 | const v_socket_t *vsv[nfd]; |
|---|
| … | … | |
| 417 | 422 | |
|---|
| 418 | 423 | return net_ReadInner( p_this, nfd, fds, vsv, |
|---|
| 419 | | buf, len, VLC_FALSE ); |
|---|
| | 424 | buf, len, VLC_FALSE, timeout ); |
|---|
| 420 | 425 | } |
|---|
| 421 | 426 | |
|---|