| 256 | | static ssize_t |
|---|
| 257 | | net_ReadInner (vlc_object_t *restrict p_this, unsigned fdc, const int *fdv, |
|---|
| 258 | | const v_socket_t *const *restrict vsv, |
|---|
| 259 | | uint8_t *restrict p_buf, size_t i_buflen, vlc_bool_t waitall) |
|---|
| | 256 | /***************************************************************************** |
|---|
| | 257 | * __net_Read: |
|---|
| | 258 | ***************************************************************************** |
|---|
| | 259 | * Read from a network socket |
|---|
| | 260 | * If waitall is true, then we repeat until we have read the right amount of |
|---|
| | 261 | * data; in that case, a short count means EOF has been reached. |
|---|
| | 262 | *****************************************************************************/ |
|---|
| | 263 | ssize_t |
|---|
| | 264 | __net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs, |
|---|
| | 265 | uint8_t *restrict p_buf, size_t i_buflen, vlc_bool_t waitall) |
|---|
| 303 | | if (i_total > 0) |
|---|
| 304 | | { |
|---|
| 305 | | // Errors (-1) and EOF (0) will be returned on next run |
|---|
| 306 | | if (ufd[i].revents & (POLLERR|POLLNVAL|POLLRDHUP)) |
|---|
| 307 | | return i_total; |
|---|
| 308 | | } |
|---|
| 309 | | else |
|---|
| 310 | | { |
|---|
| 311 | | if (ufd[i].revents & POLLRDHUP) |
|---|
| 312 | | return 0; // EOF, read() would yield 0 |
|---|
| 313 | | } |
|---|
| 314 | | |
|---|
| 315 | | fdc = 1; |
|---|
| 316 | | fdv += i; |
|---|
| 317 | | vsv += i; |
|---|
| 318 | | |
|---|
| 319 | | break; |
|---|
| | 301 | if (i_total > 0) |
|---|
| | 302 | { |
|---|
| | 303 | /* Errors (-1) and EOF (0) will be returned on next call, |
|---|
| | 304 | * otherwise we'd "hide" the error from the caller, which is a |
|---|
| | 305 | * bad idea™. */ |
|---|
| | 306 | if (ufd[0].revents & (POLLERR|POLLNVAL|POLLRDHUP)) |
|---|
| | 307 | return i_total; |
|---|
| 332 | | n = read (*fdv, p_buf, i_buflen); |
|---|
| 333 | | #endif |
|---|
| 334 | | } |
|---|
| 335 | | |
|---|
| 336 | | if (n == 0) |
|---|
| 337 | | /* For streams, this means end of file, and there will not be any |
|---|
| 338 | | * further data ever on the stream. For datagram sockets, this |
|---|
| 339 | | * means empty datagram, and there could be more data coming. |
|---|
| 340 | | * However, it makes no sense to set <waitall> with datagrams. |
|---|
| 341 | | */ |
|---|
| 342 | | break; // EOF |
|---|
| | 320 | n = read (fd, p_buf, i_buflen); |
|---|
| | 321 | #endif |
|---|
| | 322 | } |
|---|
| 386 | | } |
|---|
| 387 | | |
|---|
| 388 | | |
|---|
| 389 | | /***************************************************************************** |
|---|
| 390 | | * __net_Read: |
|---|
| 391 | | ***************************************************************************** |
|---|
| 392 | | * Read from a network socket |
|---|
| 393 | | * If b_retry is true, then we repeat until we have read the right amount of |
|---|
| 394 | | * data; in that case, a short count means EOF has been reached. |
|---|
| 395 | | *****************************************************************************/ |
|---|
| 396 | | ssize_t __net_Read( vlc_object_t *restrict p_this, int fd, |
|---|
| 397 | | const v_socket_t *restrict p_vs, |
|---|
| 398 | | uint8_t *restrict buf, size_t len, vlc_bool_t b_retry ) |
|---|
| 399 | | { |
|---|
| 400 | | return net_ReadInner( p_this, 1, &(int){ fd }, |
|---|
| 401 | | &(const v_socket_t *){ p_vs }, |
|---|
| 402 | | buf, len, b_retry ); |
|---|
| 403 | | } |
|---|
| 404 | | |
|---|
| 405 | | |
|---|
| 406 | | /***************************************************************************** |
|---|
| 407 | | * __net_Select: |
|---|
| 408 | | ***************************************************************************** |
|---|
| 409 | | * Read from several sockets. Takes data from the first socket that has some. |
|---|
| 410 | | *****************************************************************************/ |
|---|
| 411 | | ssize_t __net_Select( vlc_object_t *restrict p_this, |
|---|
| 412 | | const int *restrict fds, int nfd, |
|---|
| 413 | | uint8_t *restrict buf, size_t len ) |
|---|
| 414 | | { |
|---|
| 415 | | const v_socket_t *vsv[nfd]; |
|---|
| 416 | | memset( vsv, 0, sizeof (vsv) ); |
|---|
| 417 | | |
|---|
| 418 | | return net_ReadInner( p_this, nfd, fds, vsv, |
|---|
| 419 | | buf, len, VLC_FALSE ); |
|---|