@ -108,39 +108,18 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
cur_ai = ai ;
cur_ai = ai ;
restart :
restart :
ret = AVERROR ( EIO ) ;
fd = socket ( cur_ai - > ai_family , cur_ai - > ai_socktype , cur_ai - > ai_protocol ) ;
fd = socket ( cur_ai - > ai_family , cur_ai - > ai_socktype , cur_ai - > ai_protocol ) ;
if ( fd < 0 )
if ( fd < 0 ) {
ret = ff_neterrno ( ) ;
goto fail ;
goto fail ;
}
if ( s - > listen ) {
if ( s - > listen ) {
int fd1 ;
if ( ( fd = ff_listen_bind ( fd , cur_ai - > ai_addr , cur_ai - > ai_addrlen ,
int reuse = 1 ;
s - > listen_timeout ) ) < 0 ) {
struct pollfd lp = { fd , POLLIN , 0 } ;
ret = fd ;
setsockopt ( fd , SOL_SOCKET , SO_REUSEADDR , & reuse , sizeof ( reuse ) ) ;
ret = bind ( fd , cur_ai - > ai_addr , cur_ai - > ai_addrlen ) ;
if ( ret ) {
ret = ff_neterrno ( ) ;
goto fail1 ;
}
ret = listen ( fd , 1 ) ;
if ( ret ) {
ret = ff_neterrno ( ) ;
goto fail1 ;
}
ret = poll ( & lp , 1 , s - > listen_timeout > = 0 ? s - > listen_timeout : - 1 ) ;
if ( ret < = 0 ) {
ret = AVERROR ( ETIMEDOUT ) ;
goto fail1 ;
}
fd1 = accept ( fd , NULL , NULL ) ;
if ( fd1 < 0 ) {
ret = ff_neterrno ( ) ;
goto fail1 ;
goto fail1 ;
}
}
closesocket ( fd ) ;
fd = fd1 ;
ff_socket_nonblock ( fd , 1 ) ;
} else {
} else {
redo :
redo :
ff_socket_nonblock ( fd , 1 ) ;
ff_socket_nonblock ( fd , 1 ) ;
@ -202,6 +181,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
cur_ai = cur_ai - > ai_next ;
cur_ai = cur_ai - > ai_next ;
if ( fd > = 0 )
if ( fd > = 0 )
closesocket ( fd ) ;
closesocket ( fd ) ;
ret = 0 ;
goto restart ;
goto restart ;
}
}
fail1 :
fail1 :