Changeset ecbbbc15c84f94dba5d9d3a1d54ae9802256a7bf
- Timestamp:
- 01/05/08 19:04:10
(8 months ago)
- Author:
- Rémi Denis-Courmont <rem@videolan.org>
- git-committer:
- Rémi Denis-Courmont <rem@videolan.org> 1199556250 +0000
- git-parent:
[318d3056c5234df7651172ba8a89e346c478d5cd]
- git-author:
- Rémi Denis-Courmont <rem@videolan.org> 1199556250 +0000
- Message:
Use the event pipe in net_Read instead of an arbitrary timer
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r590701d |
recbbbc1 |
|
| 257 | 257 | * __net_Read: |
|---|
| 258 | 258 | ***************************************************************************** |
|---|
| 259 | | * Read from a network socket |
|---|
| | 259 | * Reads from a network socket. |
|---|
| 260 | 260 | * If waitall is true, then we repeat until we have read the right amount of |
|---|
| 261 | 261 | * data; in that case, a short count means EOF has been reached. |
|---|
| … | … | |
| 266 | 266 | { |
|---|
| 267 | 267 | size_t i_total = 0; |
|---|
| 268 | | struct pollfd ufd[1]; |
|---|
| 269 | | ufd[0].fd = fd; |
|---|
| 270 | | ufd[0].events = POLLIN; |
|---|
| 271 | | |
|---|
| | 268 | struct pollfd ufd[2] = { |
|---|
| | 269 | { .fd = fd, .events = POLLIN }, |
|---|
| | 270 | { .fd = -1, .events = POLLIN }, |
|---|
| | 271 | }; |
|---|
| | 272 | |
|---|
| | 273 | msg_Dbg (p_this, "reading socket %d", fd); |
|---|
| | 274 | vlc_object_lock (p_this); |
|---|
| | 275 | ufd[1].fd = vlc_object_waitpipe (p_this); |
|---|
| 272 | 276 | |
|---|
| 273 | 277 | while (i_buflen > 0) |
|---|
| 274 | 278 | { |
|---|
| 275 | | if( ( p_this->b_die ) || ( p_this->p_libvlc->b_die ) ) |
|---|
| | 279 | int val; |
|---|
| | 280 | |
|---|
| | 281 | if (!vlc_object_alive (p_this)) |
|---|
| 276 | 282 | { |
|---|
| 277 | 283 | #if defined(WIN32) || defined(UNDER_CE) |
|---|
| … | … | |
| 282 | 288 | goto error; |
|---|
| 283 | 289 | } |
|---|
| 284 | | |
|---|
| 285 | | ufd[0].revents = 0; |
|---|
| 286 | | /* TODO: don't use arbitrary timer just for b_die */ |
|---|
| 287 | | switch (poll (ufd, sizeof (ufd) / sizeof (ufd[0]), 500)) |
|---|
| 288 | | { |
|---|
| 289 | | case -1: |
|---|
| 290 | | goto error; |
|---|
| 291 | | |
|---|
| 292 | | case 0: // timeout |
|---|
| 293 | | continue; |
|---|
| | 290 | ufd[0].revents = ufd[1].revents = 0; |
|---|
| | 291 | |
|---|
| | 292 | vlc_object_unlock (p_this); |
|---|
| | 293 | val = poll (ufd, sizeof (ufd) / sizeof (ufd[0]), -1); |
|---|
| | 294 | vlc_object_lock (p_this); |
|---|
| | 295 | |
|---|
| | 296 | if (val < 0) |
|---|
| | 297 | goto error; |
|---|
| | 298 | |
|---|
| | 299 | if (ufd[1].revents) |
|---|
| | 300 | { |
|---|
| | 301 | msg_Dbg (p_this, "socket %d polling interrupted", fd); |
|---|
| | 302 | vlc_object_wait (p_this); |
|---|
| | 303 | msg_Dbg (p_this, "socket %d polling restarting", fd); |
|---|
| | 304 | continue; |
|---|
| 294 | 305 | } |
|---|
| 295 | 306 | |
|---|
| … | … | |
| 305 | 316 | * bad idea™. */ |
|---|
| 306 | 317 | if (ufd[0].revents & (POLLERR|POLLNVAL|POLLRDHUP)) |
|---|
| 307 | | return i_total; |
|---|
| | 318 | break; |
|---|
| 308 | 319 | } |
|---|
| 309 | 320 | |
|---|
| … | … | |
| 368 | 379 | break; |
|---|
| 369 | 380 | } |
|---|
| | 381 | |
|---|
| | 382 | vlc_object_unlock (p_this); |
|---|
| | 383 | msg_Dbg (p_this, "read %u bytes from socket %d", (unsigned)i_total, fd); |
|---|
| 370 | 384 | return i_total; |
|---|
| 371 | 385 | |
|---|
| 372 | 386 | error: |
|---|
| 373 | 387 | msg_Err (p_this, "Read error: %m"); |
|---|
| 374 | | return i_total ? (ssize_t)i_total : -1; |
|---|
| | 388 | |
|---|
| | 389 | vlc_object_unlock (p_this); |
|---|
| | 390 | return -1; |
|---|
| 375 | 391 | } |
|---|
| 376 | 392 | |
|---|