Commit fbeffa45 authored by gydong's avatar gydong

change the backlog of listen() from INT_MAX to 65535 due to the reason described…

change the backlog of listen() from INT_MAX to 65535 due to the reason described in https://codereview.appspot.com/7480046/
parent 3c62e2f1
// 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.
......@@ -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
......@@ -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) {
......@@ -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;
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment