Skip to content

Commit

Permalink
Fix #775, Support SO_REUSEPORT. 3.0.54
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Oct 3, 2019
1 parent 1a65927 commit d3b142a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ cd srs/trunk
* Usage: How to delivery HLS by embeded HTTP server?([CN][v3_CN_SampleHTTP], [EN][v3_EN_SampleHTTP])
* Usage: How to run the demostration of SRS? ([CN][v1_CN_SampleDemo], [EN][v1_EN_SampleDemo])
* Usage: How to publish h.264 raw stream as RTMP? ([CN][v3_CN_SrsLibrtmp2], [EN][v3_EN_SrsLibrtmp2])
* Usage: How to improve performance by multiple CPUs? ([CN][v3_CN_REUSEPORT], [EN][v3_EN_REUSEPORT])
* Usage: Who are using SRS?([CN][v1_CN_Sample])
* Usage: Why choose SRS? About the milestone and product plan? ([CN][v1_CN_Product], [EN][v1_EN_Product])

Expand Down Expand Up @@ -148,6 +149,7 @@ Please select according to languages:
- [x] Enhanced RTMP url which supports vhost in stream, read [#1059][bug #1059].
- [x] Support origin cluster, please read [#464][bug #464], [RTMP 302][bug #92].
- [x] Support listen at IPv4 and IPv6, read [#460][bug #460].
- [x] Support SO_REUSEPORT, read [#775][bug #775].
- [ ] Utest cover almost all kernel code.
- [ ] Enhanced forwarding with vhost and variables.
- [ ] Support source cleanup for idle streams.
Expand All @@ -164,6 +166,7 @@ Please select according to languages:

### V3 changes

* v3.0, 2019-10-03, Fix [#775][bug #775], Support SO_REUSEPORT. 3.0.54
* v3.0, 2019-10-03, Remove KAFKA. 3.0.53
* v3.0, 2019-05-14, Covert Kernel File reader/writer. 3.0.52
* v3.0, 2019-04-30, Refine typo in files. 3.0.51
Expand Down Expand Up @@ -782,7 +785,7 @@ The performance benchmark data and corelative commits are listed here.

* See also: [Performance for x86/x64 Test Guide][v1_CN_Performance].
* See also: [Performance for RaspberryPi][v1_CN_RaspberryPi].
* For multiple processes performance, read [go-oryx][oryx].
* For multiple processes performance, read [#775: REUSEPORT][bug #775] or [go-oryx][oryx].

#### Play RTMP benchmark

Expand Down Expand Up @@ -1474,6 +1477,7 @@ Winlin
[bug #821]: https://github.com/ossrs/srs/issues/821
[bug #913]: https://github.com/ossrs/srs/issues/913
[bug #460]: https://github.com/ossrs/srs/issues/460
[bug #775]: https://github.com/ossrs/srs/issues/775
[bug #1057]: https://github.com/ossrs/srs/issues/1057
[bug #105]: https://github.com/ossrs/srs/issues/105
[bug #727]: https://github.com/ossrs/srs/issues/727
Expand Down
15 changes: 15 additions & 0 deletions trunk/conf/edge2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# the config for srs origin-edge cluster
# @see https://github.com/ossrs/srs/wiki/v1_CN_Edge
# @see full.conf for detail config.

listen 1935;
max_connections 1000;
pid objs/edge2.pid;
daemon off;
srs_log_tank console;
vhost __defaultVhost__ {
cluster {
mode remote;
origin 127.0.0.1:19350;
}
}
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// The version config.
#define VERSION_MAJOR 3
#define VERSION_MINOR 0
#define VERSION_REVISION 53
#define VERSION_REVISION 54

// The macros generated by configure script.
#include <srs_auto_headers.hpp>
Expand Down
20 changes: 20 additions & 0 deletions trunk/src/service/srs_service_st.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ srs_error_t srs_fd_reuseaddr(int fd)
return srs_success;
}

srs_error_t srs_fd_reuseport(int fd)
{
int v = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &v, sizeof(int)) == -1) {
return srs_error_new(ERROR_SOCKET_SETREUSEADDR, "SO_REUSEPORT fd=%v", fd);
}

return srs_success;
}

srs_error_t srs_fd_keepalive(int fd)
{
#ifdef SO_KEEPALIVE
Expand Down Expand Up @@ -215,6 +225,11 @@ srs_error_t srs_tcp_listen(std::string ip, int port, srs_netfd_t* pfd)
return srs_error_wrap(err, "set reuseaddr fd=%d", fd);
}

if ((err = srs_fd_reuseport(fd)) != srs_success) {
::close(fd);
return srs_error_wrap(err, "set reuseport fd=%d", fd);
}

if (bind(fd, r->ai_addr, r->ai_addrlen) == -1) {
::close(fd);
return srs_error_new(ERROR_SOCKET_BIND, "bind fd=%d", fd);
Expand Down Expand Up @@ -269,6 +284,11 @@ srs_error_t srs_udp_listen(std::string ip, int port, srs_netfd_t* pfd)
return srs_error_wrap(err, "set reuseaddr fd=%d", fd);
}

if ((err = srs_fd_reuseport(fd)) != srs_success) {
::close(fd);
return srs_error_wrap(err, "set reuseport fd=%d", fd);
}

if (bind(fd, r->ai_addr, r->ai_addrlen) == -1) {
::close(fd);
return srs_error_new(ERROR_SOCKET_BIND, "bind fd=%d", fd);
Expand Down
3 changes: 3 additions & 0 deletions trunk/src/service/srs_service_st.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ extern srs_error_t srs_fd_closeexec(int fd);
// Set the SO_REUSEADDR of fd.
extern srs_error_t srs_fd_reuseaddr(int fd);

// Set the SO_REUSEPORT of fd.
extern srs_error_t srs_fd_reuseport(int fd);

// Set the SO_KEEPALIVE of fd.
extern srs_error_t srs_fd_keepalive(int fd);

Expand Down

0 comments on commit d3b142a

Please sign in to comment.