Unverified Commit 05227912 authored by Ge Jun's avatar Ge Jun Committed by GitHub

Merge pull request #466 from gydong/master

 change the backlog of listen() from INT_MAX to 65535
parents 0b4117d8 fbeffa45
// Copyright (c) 2011 Baidu, Inc. // Copyright (c) 2011 Baidu, Inc.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...@@ -134,7 +134,7 @@ int hostname2ip(const char* hostname, ip_t* ip) { ...@@ -134,7 +134,7 @@ int hostname2ip(const char* hostname, ip_t* ip) {
struct hostent* result = NULL; struct hostent* result = NULL;
if (gethostbyname_r(hostname, &ent, aux_buf, sizeof(aux_buf), if (gethostbyname_r(hostname, &ent, aux_buf, sizeof(aux_buf),
&result, &error) != 0 || result == NULL) { &result, &error) != 0 || result == NULL) {
return -1; return -1;
} }
#endif // defined(OS_MACOSX) #endif // defined(OS_MACOSX)
// Only fetch the first address here // Only fetch the first address here
...@@ -146,7 +146,7 @@ struct MyAddressInfo { ...@@ -146,7 +146,7 @@ struct MyAddressInfo {
char my_hostname[256]; char my_hostname[256];
ip_t my_ip; ip_t my_ip;
IPStr my_ip_str; IPStr my_ip_str;
MyAddressInfo() { MyAddressInfo() {
my_ip = IP_ANY; my_ip = IP_ANY;
if (gethostname(my_hostname, sizeof(my_hostname)) < 0) { if (gethostname(my_hostname, sizeof(my_hostname)) < 0) {
...@@ -222,7 +222,7 @@ int hostname2endpoint(const char* str, EndPoint* point) { ...@@ -222,7 +222,7 @@ int hostname2endpoint(const char* str, EndPoint* point) {
if (i == sizeof(buf) - 1) { if (i == sizeof(buf) - 1) {
return -1; return -1;
} }
buf[i] = '\0'; buf[i] = '\0';
if (hostname2ip(buf, &point->ip) != 0) { if (hostname2ip(buf, &point->ip) != 0) {
return -1; return -1;
...@@ -333,13 +333,14 @@ int tcp_listen(EndPoint point, bool reuse_addr) { ...@@ -333,13 +333,14 @@ int tcp_listen(EndPoint point, bool reuse_addr) {
bzero((char*)&serv_addr, sizeof(serv_addr)); bzero((char*)&serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET; serv_addr.sin_family = AF_INET;
serv_addr.sin_addr = point.ip; 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) { if (bind(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) != 0) {
return -1; return -1;
} }
if (listen(sockfd, INT_MAX) != 0) { if (listen(sockfd, 65535) != 0) {
// ^^^ kernel would silently truncate backlog to the value // ^^^ 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 -1;
} }
return sockfd.release(); 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