Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
9d02c991
Commit
9d02c991
authored
Jan 10, 2016
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
src: add vlc_socketpair() helper
(works like vlc_socket())
parent
11c606b1
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
14 deletions
+64
-14
include/vlc_network.h
include/vlc_network.h
+1
-0
src/libvlccore.sym
src/libvlccore.sym
+1
-0
src/os2/filesystem.c
src/os2/filesystem.c
+19
-7
src/posix/filesystem.c
src/posix/filesystem.c
+36
-7
src/win32/filesystem.c
src/win32/filesystem.c
+7
-0
No files found.
include/vlc_network.h
View file @
9d02c991
...
...
@@ -76,6 +76,7 @@ struct msghdr
#endif
VLC_API
int
vlc_socket
(
int
,
int
,
int
,
bool
nonblock
)
VLC_USED
;
VLC_API
int
vlc_socketpair
(
int
,
int
,
int
,
int
[
2
],
bool
nonblock
);
struct
sockaddr
;
VLC_API
int
vlc_accept
(
int
,
struct
sockaddr
*
,
socklen_t
*
,
bool
)
VLC_USED
;
...
...
src/libvlccore.sym
View file @
9d02c991
...
...
@@ -471,6 +471,7 @@ vlc_pipe
vlc_write
vlc_writev
vlc_socket
vlc_socketpair
vlc_accept
utf8_vfprintf
var_AddCallback
...
...
src/os2/filesystem.c
View file @
9d02c991
...
...
@@ -302,18 +302,30 @@ ssize_t vlc_writev(int fd, const struct iovec *iov, int count)
return
val
;
}
static
void
vlc_socket_setup
(
int
fd
,
bool
nonblock
)
{
fcntl
(
fd
,
F_SETFD
,
FD_CLOEXEC
);
if
(
nonblock
)
fcntl
(
fd
,
F_SETFL
,
fcntl
(
fd
,
F_GETFL
,
0
)
|
O_NONBLOCK
);
}
int
vlc_socket
(
int
pf
,
int
type
,
int
proto
,
bool
nonblock
)
{
int
fd
;
int
fd
=
socket
(
pf
,
type
,
proto
);
if
(
fd
!=
-
1
)
vlc_socket_setup
(
fd
,
nonblock
);
return
fd
;
}
fd
=
socket
(
pf
,
type
,
proto
);
if
(
fd
==
-
1
)
int
vlc_socketpair
(
int
pf
,
int
type
,
int
proto
,
int
fds
[
2
],
bool
nonblock
)
{
if
(
socketpair
(
pf
,
type
,
proto
,
fds
))
return
-
1
;
fcntl
(
fd
,
F_SETFD
,
FD_CLOEXEC
);
if
(
nonblock
)
fcntl
(
fd
,
F_SETFL
,
fcntl
(
fd
,
F_GETFL
,
0
)
|
O_NONBLOCK
);
return
fd
;
vlc_socket_setup
(
fds
[
0
],
nonblock
);
vlc_socket_setup
(
fds
[
1
],
nonblock
);
return
0
;
}
int
vlc_accept
(
int
lfd
,
struct
sockaddr
*
addr
,
socklen_t
*
alen
,
bool
nonblock
)
...
...
src/posix/filesystem.c
View file @
9d02c991
...
...
@@ -271,6 +271,18 @@ ssize_t vlc_writev(int fd, const struct iovec *iov, int count)
#include <vlc_network.h>
static
void
vlc_socket_setup
(
int
fd
,
bool
nonblock
)
{
fcntl
(
fd
,
F_SETFD
,
FD_CLOEXEC
);
if
(
nonblock
)
fcntl
(
fd
,
F_SETFL
,
fcntl
(
fd
,
F_GETFL
,
0
)
|
O_NONBLOCK
);
#ifdef SO_NOSIGPIPE
setsockopt
(
fd
,
SOL_SOCKET
,
SO_NOSIGPIPE
,
&
(
int
){
1
},
sizeof
(
int
));
#endif
}
/**
* Creates a socket file descriptor. The new file descriptor has the
* close-on-exec flag set.
...
...
@@ -288,6 +300,7 @@ int vlc_socket (int pf, int type, int proto, bool nonblock)
type
|=
SOCK_CLOEXEC
;
if
(
nonblock
)
type
|=
SOCK_NONBLOCK
;
fd
=
socket
(
pf
,
type
,
proto
);
if
(
fd
!=
-
1
||
errno
!=
EINVAL
)
return
fd
;
...
...
@@ -296,16 +309,32 @@ int vlc_socket (int pf, int type, int proto, bool nonblock)
#endif
fd
=
socket
(
pf
,
type
,
proto
);
if
(
fd
==
-
1
)
return
-
1
;
if
(
fd
!=
-
1
)
vlc_socket_setup
(
fd
,
nonblock
);
return
fd
;
}
fcntl
(
fd
,
F_SETFD
,
FD_CLOEXEC
);
int
vlc_socketpair
(
int
pf
,
int
type
,
int
proto
,
int
fds
[
2
],
bool
nonblock
)
{
#ifdef SOCK_CLOEXEC
type
|=
SOCK_CLOEXEC
;
if
(
nonblock
)
fcntl
(
fd
,
F_SETFL
,
fcntl
(
fd
,
F_GETFL
,
0
)
|
O_NONBLOCK
);
#ifdef SO_NOSIGPIPE
setsockopt
(
fd
,
SOL_SOCKET
,
SO_NOSIGPIPE
,
&
(
int
){
1
},
sizeof
(
int
));
type
|=
SOCK_NONBLOCK
;
if
(
socketpair
(
pf
,
type
,
proto
,
fds
)
==
0
)
return
0
;
if
(
errno
!=
EINVAL
)
return
-
1
;
type
&=
~
(
SOCK_CLOEXEC
|
SOCK_NONBLOCK
);
#endif
return
fd
;
if
(
socketpair
(
pf
,
type
,
proto
,
fds
))
return
-
1
;
vlc_socket_setup
(
fds
[
0
],
nonblock
);
vlc_socket_setup
(
fds
[
1
],
nonblock
);
return
0
;
}
/**
...
...
src/win32/filesystem.c
View file @
9d02c991
...
...
@@ -327,6 +327,13 @@ int vlc_socket (int pf, int type, int proto, bool nonblock)
return
fd
;
}
int
vlc_socketpair
(
int
pf
,
int
type
,
int
proto
,
int
fds
[
2
],
bool
nonblock
)
{
(
void
)
pf
;
(
void
)
type
;
(
void
)
proto
;
(
void
)
fds
;
(
void
)
nonblock
;
errno
=
ENOSYS
;
return
-
1
;
}
int
vlc_accept
(
int
lfd
,
struct
sockaddr
*
addr
,
socklen_t
*
alen
,
bool
nonblock
)
{
int
fd
=
accept
(
lfd
,
addr
,
alen
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment