Skip to content

Commit

Permalink
Merge pull request apache#466 from gydong/master
Browse files Browse the repository at this point in the history
 change the backlog of listen() from INT_MAX to 65535
  • Loading branch information
jamesge authored Aug 27, 2018
2 parents 0b4117d + fbeffa4 commit 0522791
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/butil/endpoint.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) 2011 Baidu, Inc.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -134,7 +134,7 @@ int hostname2ip(const char* hostname, ip_t* ip) {
struct hostent* result = NULL;
if (gethostbyname_r(hostname, &ent, aux_buf, sizeof(aux_buf),
&result, &error) != 0 || result == NULL) {
return -1;
return -1;
}
#endif // defined(OS_MACOSX)
// Only fetch the first address here
Expand All @@ -146,7 +146,7 @@ struct MyAddressInfo {
char my_hostname[256];
ip_t my_ip;
IPStr my_ip_str;

MyAddressInfo() {
my_ip = IP_ANY;
if (gethostname(my_hostname, sizeof(my_hostname)) < 0) {
Expand Down Expand Up @@ -222,7 +222,7 @@ int hostname2endpoint(const char* str, EndPoint* point) {
if (i == sizeof(buf) - 1) {
return -1;
}

buf[i] = '\0';
if (hostname2ip(buf, &point->ip) != 0) {
return -1;
Expand Down Expand Up @@ -333,13 +333,14 @@ int tcp_listen(EndPoint point, bool reuse_addr) {
bzero((char*)&serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr = point.ip;
serv_addr.sin_port = htons(point.port);
serv_addr.sin_port = htons(point.port);
if (bind(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) != 0) {
return -1;
}
if (listen(sockfd, INT_MAX) != 0) {
if (listen(sockfd, 65535) != 0) {
// ^^^ kernel would silently truncate backlog to the value
// defined in /proc/sys/net/core/somaxconn
// defined in /proc/sys/net/core/somaxconn if it is less
// than 65535
return -1;
}
return sockfd.release();
Expand Down

0 comments on commit 0522791

Please sign in to comment.