⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 io.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
            }            else msg_Err( p_this, "recv failed (%i)", WSAGetLastError() );#else            msg_Err( p_this, "recv failed (%s)", strerror(errno) );#endif            return -1;        }        return i_recv ? i_recv : -1;  /* !i_recv -> connection closed if tcp */    }    /* We will never be here */    return -1;}/***************************************************************************** * __net_Select: ***************************************************************************** * Read from several sockets (with timeout). Takes data from the first socket * that has some. *****************************************************************************/int __net_Select( vlc_object_t *p_this, int *pi_fd, v_socket_t **pp_vs,                  int i_fd, uint8_t *p_data, int i_data, mtime_t i_wait ){    struct timeval  timeout;    fd_set          fds_r, fds_e;    int             i_recv;    int             i_ret;    int             i;    int             i_max_fd = 0;    /* Initialize file descriptor set */    FD_ZERO( &fds_r );    FD_ZERO( &fds_e );    for( i = 0 ; i < i_fd ; i++)    {        if( pi_fd[i] > i_max_fd ) i_max_fd = pi_fd[i];        FD_SET( pi_fd[i], &fds_r );        FD_SET( pi_fd[i], &fds_e );    }    timeout.tv_sec = 0;    timeout.tv_usec = i_wait;    i_ret = select( i_max_fd + 1, &fds_r, NULL, &fds_e, &timeout );    if( i_ret < 0 && errno == EINTR )    {        return 0;    }    else if( i_ret < 0 )    {        msg_Err( p_this, "network selection error (%s)", strerror(errno) );        return -1;    }    else if( i_ret == 0 )    {        return 0;    }    else    {        for( i = 0 ; i < i_fd ; i++)        {            if( FD_ISSET( pi_fd[i], &fds_r ) )            {                i_recv = ((pp_vs != NULL) && (pp_vs[i] != NULL))                         ? pp_vs[i]->pf_recv( pp_vs[i]->p_sys, p_data, i_data )                         : recv( pi_fd[i], p_data, i_data, 0 );                if( i_recv < 0 )                {#ifdef WIN32                    /* For udp only */                    /* On win32 recv() will fail if the datagram doesn't                     * fit inside the passed buffer, even though the buffer                     *  will be filled with the first part of the datagram. */                    if( WSAGetLastError() == WSAEMSGSIZE )                    {                        msg_Err( p_this, "recv() failed. "                             "Increase the mtu size (--mtu option)" );                    }                    else msg_Err( p_this, "recv failed (%i)",                                  WSAGetLastError() );#else                    msg_Err( p_this, "recv failed (%s)", strerror(errno) );#endif                    return VLC_EGENERIC;                }                return i_recv;            }        }    }    /* We will never be here */    return -1;}/* Write exact amount requested */int __net_Write( vlc_object_t *p_this, int fd, v_socket_t *p_vs,                 const uint8_t *p_data, int i_data ){    struct timeval  timeout;    fd_set          fds_w, fds_e;    int             i_send;    int             i_total = 0;    int             i_ret;    vlc_bool_t      b_die = p_this->b_die;    while( i_data > 0 )    {        do        {            if( p_this->b_die != b_die )            {                return 0;            }            /* Initialize file descriptor set */            FD_ZERO( &fds_w );            FD_SET( fd, &fds_w );            FD_ZERO( &fds_e );            FD_SET( fd, &fds_e );            /* We'll wait 0.5 second if nothing happens */            timeout.tv_sec = 0;            timeout.tv_usec = 500000;        } while( (i_ret = select(fd + 1, NULL, &fds_w, &fds_e, &timeout)) == 0                 || ( i_ret < 0 && errno == EINTR ) );        if( i_ret < 0 )        {#if defined(WIN32) || defined(UNDER_CE)            msg_Err( p_this, "network selection error (%d)", WSAGetLastError() );#else            msg_Err( p_this, "network selection error (%s)", strerror(errno) );#endif            return i_total > 0 ? i_total : -1;        }        if( ( i_send = (p_vs != NULL)                       ? p_vs->pf_send( p_vs->p_sys, p_data, i_data )                       : send( fd, p_data, i_data, 0 ) ) < 0 )        {            /* XXX With udp for example, it will issue a message if the host             * isn't listening */            /* msg_Err( p_this, "send failed (%s)", strerror(errno) ); */            return i_total > 0 ? i_total : -1;        }        p_data += i_send;        i_data -= i_send;        i_total+= i_send;    }    return i_total;}char *__net_Gets( vlc_object_t *p_this, int fd, v_socket_t *p_vs ){    char *psz_line = NULL, *ptr = NULL;    size_t  i_line = 0, i_max = 0;    for( ;; )    {        if( i_line == i_max )        {            i_max += 1024;            psz_line = realloc( psz_line, i_max );            ptr = psz_line + i_line;        }        if( net_Read( p_this, fd, p_vs, (uint8_t *)ptr, 1, VLC_TRUE ) != 1 )        {            if( i_line == 0 )            {                free( psz_line );                return NULL;            }            break;        }        if ( *ptr == '\n' )            break;        i_line++;        ptr++;    }    *ptr-- = '\0';    if( ( ptr >= psz_line ) && ( *ptr == '\r' ) )        *ptr = '\0';    return psz_line;}int net_Printf( vlc_object_t *p_this, int fd, v_socket_t *p_vs,                const char *psz_fmt, ... ){    int i_ret;    va_list args;    va_start( args, psz_fmt );    i_ret = net_vaPrintf( p_this, fd, p_vs, psz_fmt, args );    va_end( args );    return i_ret;}int __net_vaPrintf( vlc_object_t *p_this, int fd, v_socket_t *p_vs,                    const char *psz_fmt, va_list args ){    char    *psz;    int     i_size, i_ret;    i_size = vasprintf( &psz, psz_fmt, args );    i_ret = __net_Write( p_this, fd, p_vs, (uint8_t *)psz, i_size ) < i_size        ? -1 : i_size;    free( psz );    return i_ret;}/***************************************************************************** * inet_pton replacement for obsolete and/or crap operating systems *****************************************************************************/#ifndef HAVE_INET_PTONint inet_pton(int af, const char *src, void *dst){# ifdef WIN32    /* As we already know, Microsoft always go its own way, so even if they do     * provide IPv6, they don't provide the API. */    struct sockaddr_storage addr;    int len = sizeof( addr );    /* Damn it, they didn't even put LPCSTR for the firs parameter!!! */#ifdef UNICODE    wchar_t *workaround_for_ill_designed_api =        malloc( MAX_PATH * sizeof(wchar_t) );    mbstowcs( workaround_for_ill_designed_api, src, MAX_PATH );    workaround_for_ill_designed_api[MAX_PATH-1] = 0;#else    char *workaround_for_ill_designed_api = strdup( src );#endif    if( !WSAStringToAddress( workaround_for_ill_designed_api, af, NULL,                             (LPSOCKADDR)&addr, &len ) )    {        free( workaround_for_ill_designed_api );        return -1;    }    free( workaround_for_ill_designed_api );    switch( af )    {        case AF_INET6:            memcpy( dst, &((struct sockaddr_in6 *)&addr)->sin6_addr, 16 );            break;        case AF_INET:            memcpy( dst, &((struct sockaddr_in *)&addr)->sin_addr, 4 );            break;        default:            WSASetLastError( WSAEAFNOSUPPORT );            return -1;    }# else    /* Assume IPv6 is not supported. */    /* Would be safer and more simpler to use inet_aton() but it is most     * likely not provided either. */    uint32_t ipv4;    if( af != AF_INET )    {        errno = EAFNOSUPPORT;        return -1;    }    ipv4 = inet_addr( src );    if( ipv4 == INADDR_NONE )        return -1;    memcpy( dst, &ipv4, 4 );# endif /* WIN32 */    return 0;}#endif /* HAVE_INET_PTON */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -