mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
parent
2ed2513f08
commit
ea9a5f26d9
18 changed files with 174 additions and 274 deletions
|
@ -23,6 +23,8 @@
|
|||
|
||||
#include <srs_service_st.hpp>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
using namespace std;
|
||||
|
||||
#include <srs_kernel_error.hpp>
|
||||
|
@ -88,6 +90,19 @@ void srs_close_stfd(st_netfd_t& stfd)
|
|||
}
|
||||
}
|
||||
|
||||
void srs_fd_close_exec(int fd)
|
||||
{
|
||||
int flags = fcntl(fd, F_GETFD);
|
||||
flags |= FD_CLOEXEC;
|
||||
fcntl(fd, F_SETFD, flags);
|
||||
}
|
||||
|
||||
void srs_socket_reuse_addr(int fd)
|
||||
{
|
||||
int v = 1;
|
||||
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(int));
|
||||
}
|
||||
|
||||
SrsStSocket::SrsStSocket()
|
||||
{
|
||||
stfd = NULL;
|
||||
|
|
|
@ -38,6 +38,12 @@ extern int srs_st_init();
|
|||
// @remark when close, user must ensure io completed.
|
||||
extern void srs_close_stfd(st_netfd_t& stfd);
|
||||
|
||||
// Set the FD_CLOEXEC of FD.
|
||||
extern void srs_fd_close_exec(int fd);
|
||||
|
||||
// Set the SO_REUSEADDR of socket.
|
||||
extern void srs_socket_reuse_addr(int fd);
|
||||
|
||||
/**
|
||||
* the socket provides TCP socket over st,
|
||||
* that is, the sync socket mechanism.
|
||||
|
|
|
@ -56,6 +56,8 @@ int srs_socket_connect(string server, int port, int64_t tm, st_netfd_t* pstfd)
|
|||
return ret;
|
||||
}
|
||||
|
||||
srs_fd_close_exec(sock);
|
||||
|
||||
srs_assert(!stfd);
|
||||
stfd = st_netfd_open_socket(sock);
|
||||
if(stfd == NULL){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue