Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFmpeg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libremedia
Tethys
FFmpeg
Commits
09787fb8
Commit
09787fb8
authored
21 years ago
by
Fabrice Bellard
Browse files
Options
Downloads
Patches
Plain Diff
support aborting in TCP
Originally committed as revision 2061 to
svn://svn.ffmpeg.org/ffmpeg/trunk
parent
b7b8fc34
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libavformat/tcp.c
+70
-14
70 additions, 14 deletions
libavformat/tcp.c
with
70 additions
and
14 deletions
libavformat/tcp.c
+
70
−
14
View file @
09787fb8
...
@@ -28,6 +28,8 @@
...
@@ -28,6 +28,8 @@
# include "barpainet.h"
# include "barpainet.h"
#endif
#endif
#include
<netdb.h>
#include
<netdb.h>
#include
<sys/time.h>
#include
<fcntl.h>
typedef
struct
TCPContext
{
typedef
struct
TCPContext
{
int
fd
;
int
fd
;
...
@@ -55,7 +57,11 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
...
@@ -55,7 +57,11 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
int
port
,
fd
=
-
1
;
int
port
,
fd
=
-
1
;
TCPContext
*
s
;
TCPContext
*
s
;
const
char
*
p
;
const
char
*
p
;
fd_set
wfds
;
int
fd_max
,
ret
;
struct
timeval
tv
;
socklen_t
optlen
;
s
=
av_malloc
(
sizeof
(
TCPContext
));
s
=
av_malloc
(
sizeof
(
TCPContext
));
if
(
!
s
)
if
(
!
s
)
return
-
ENOMEM
;
return
-
ENOMEM
;
...
@@ -85,32 +91,72 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
...
@@ -85,32 +91,72 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
fd
=
socket
(
PF_INET
,
SOCK_STREAM
,
0
);
fd
=
socket
(
PF_INET
,
SOCK_STREAM
,
0
);
if
(
fd
<
0
)
if
(
fd
<
0
)
goto
fail
;
goto
fail
;
fcntl
(
fd
,
F_SETFL
,
O_NONBLOCK
);
redo:
ret
=
connect
(
fd
,
(
struct
sockaddr
*
)
&
dest_addr
,
sizeof
(
dest_addr
));
if
(
ret
<
0
)
{
if
(
errno
==
EINTR
)
goto
redo
;
if
(
errno
!=
EINPROGRESS
)
goto
fail
;
if
(
connect
(
fd
,
(
struct
sockaddr
*
)
&
dest_addr
,
/* wait until we are connected or until abort */
sizeof
(
dest_addr
))
<
0
)
for
(;;)
{
goto
fail
;
if
(
url_interrupt_cb
())
{
ret
=
-
EINTR
;
goto
fail1
;
}
fd_max
=
fd
;
FD_ZERO
(
&
wfds
);
FD_SET
(
fd
,
&
wfds
);
tv
.
tv_sec
=
0
;
tv
.
tv_usec
=
100
*
1000
;
ret
=
select
(
fd_max
+
1
,
NULL
,
&
wfds
,
NULL
,
&
tv
);
if
(
ret
>
0
&&
FD_ISSET
(
fd
,
&
wfds
))
break
;
}
/* test error */
optlen
=
sizeof
(
ret
);
getsockopt
(
fd
,
SOL_SOCKET
,
SO_ERROR
,
&
ret
,
&
optlen
);
if
(
ret
!=
0
)
goto
fail
;
}
s
->
fd
=
fd
;
s
->
fd
=
fd
;
return
0
;
return
0
;
fail:
fail:
ret
=
-
EIO
;
fail1:
if
(
fd
>=
0
)
if
(
fd
>=
0
)
close
(
fd
);
close
(
fd
);
av_free
(
s
);
av_free
(
s
);
return
-
EIO
;
return
ret
;
}
}
static
int
tcp_read
(
URLContext
*
h
,
uint8_t
*
buf
,
int
size
)
static
int
tcp_read
(
URLContext
*
h
,
uint8_t
*
buf
,
int
size
)
{
{
TCPContext
*
s
=
h
->
priv_data
;
TCPContext
*
s
=
h
->
priv_data
;
int
size1
,
len
;
int
size1
,
len
,
fd_max
;
fd_set
rfds
;
struct
timeval
tv
;
size1
=
size
;
size1
=
size
;
while
(
size
>
0
)
{
while
(
size
>
0
)
{
#ifdef CONFIG_BEOS_NETSERVER
if
(
url_interrupt_cb
())
len
=
recv
(
s
->
fd
,
buf
,
size
,
0
);
return
-
EINTR
;
fd_max
=
s
->
fd
;
FD_ZERO
(
&
rfds
);
FD_SET
(
s
->
fd
,
&
rfds
);
tv
.
tv_sec
=
0
;
tv
.
tv_usec
=
100
*
1000
;
select
(
fd_max
+
1
,
&
rfds
,
NULL
,
NULL
,
&
tv
);
#ifdef __BEOS__
len
=
recv
(
s
->
fd
,
buf
,
size
,
0
);
#else
#else
len
=
read
(
s
->
fd
,
buf
,
size
);
len
=
read
(
s
->
fd
,
buf
,
size
);
#endif
#endif
if
(
len
<
0
)
{
if
(
len
<
0
)
{
if
(
errno
!=
EINTR
&&
errno
!=
EAGAIN
)
if
(
errno
!=
EINTR
&&
errno
!=
EAGAIN
)
...
@@ -133,14 +179,24 @@ static int tcp_read(URLContext *h, uint8_t *buf, int size)
...
@@ -133,14 +179,24 @@ static int tcp_read(URLContext *h, uint8_t *buf, int size)
static
int
tcp_write
(
URLContext
*
h
,
uint8_t
*
buf
,
int
size
)
static
int
tcp_write
(
URLContext
*
h
,
uint8_t
*
buf
,
int
size
)
{
{
TCPContext
*
s
=
h
->
priv_data
;
TCPContext
*
s
=
h
->
priv_data
;
int
ret
,
size1
;
int
ret
,
size1
,
fd_max
;
fd_set
wfds
;
struct
timeval
tv
;
size1
=
size
;
size1
=
size
;
while
(
size
>
0
)
{
while
(
size
>
0
)
{
#ifdef CONFIG_BEOS_NETSERVER
if
(
url_interrupt_cb
())
ret
=
send
(
s
->
fd
,
buf
,
size
,
0
);
return
-
EINTR
;
fd_max
=
s
->
fd
;
FD_ZERO
(
&
wfds
);
FD_SET
(
s
->
fd
,
&
wfds
);
tv
.
tv_sec
=
0
;
tv
.
tv_usec
=
100
*
1000
;
select
(
fd_max
+
1
,
NULL
,
&
wfds
,
NULL
,
&
tv
);
#ifdef __BEOS__
ret
=
send
(
s
->
fd
,
buf
,
size
,
0
);
#else
#else
ret
=
write
(
s
->
fd
,
buf
,
size
);
ret
=
write
(
s
->
fd
,
buf
,
size
);
#endif
#endif
if
(
ret
<
0
&&
errno
!=
EINTR
&&
errno
!=
EAGAIN
)
if
(
ret
<
0
&&
errno
!=
EINTR
&&
errno
!=
EAGAIN
)
#ifdef __BEOS__
#ifdef __BEOS__
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment