Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Unified Diff: runtime/bin/socket_linux.cc

Issue 11262006: Use the thread safe gethostbyname function on Linux (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_linux.cc
diff --git a/runtime/bin/socket_linux.cc b/runtime/bin/socket_linux.cc
index 05f225bd45728cb8fa16c40c16cd270c40a31be2..896a9da069497bda67f02e03bc55b4a6831ebaf8 100644
--- a/runtime/bin/socket_linux.cc
+++ b/runtime/bin/socket_linux.cc
@@ -20,7 +20,7 @@ bool Socket::Initialize() {
intptr_t Socket::CreateConnect(const char* host, const intptr_t port) {
intptr_t fd;
- struct hostent* server;
+ struct hostent server;
struct sockaddr_in server_address;
fd = TEMP_FAILURE_RETRY(socket(AF_INET, SOCK_STREAM, 0));
@@ -31,8 +31,12 @@ intptr_t Socket::CreateConnect(const char* host, const intptr_t port) {
FDUtils::SetNonBlocking(fd);
- server = gethostbyname(host);
- if (server == NULL) {
+ static const size_t kTempBufSize = 1024;
+ char temp_buf[kTempBufSize];
+ struct hostent *unused;
+ int err;
+ if (gethostbyname_r(
+ host, &server, temp_buf, kTempBufSize, &unused, &err) != 0) {
TEMP_FAILURE_RETRY(close(fd));
fprintf(stderr, "Error CreateConnect: %s\n", strerror(errno));
return -1;
@@ -40,7 +44,7 @@ intptr_t Socket::CreateConnect(const char* host, const intptr_t port) {
server_address.sin_family = AF_INET;
server_address.sin_port = htons(port);
- bcopy(server->h_addr, &server_address.sin_addr.s_addr, server->h_length);
+ bcopy(server.h_addr, &server_address.sin_addr.s_addr, server.h_length);
memset(&server_address.sin_zero, 0, sizeof(server_address.sin_zero));
intptr_t result = TEMP_FAILURE_RETRY(
connect(fd,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698