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

Unified Diff: runtime/bin/socket_linux.cc

Issue 9699017: Start better error reporting for sockets (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added tests Created 8 years, 9 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
Index: runtime/bin/socket_linux.cc
diff --git a/runtime/bin/socket_linux.cc b/runtime/bin/socket_linux.cc
index bc4cd932a7fe4f4c9a8a36713befcf23c48448f6..2428798404a593e35be26081088a057d1d6ec7fc 100644
--- a/runtime/bin/socket_linux.cc
+++ b/runtime/bin/socket_linux.cc
@@ -107,6 +107,40 @@ intptr_t Socket::GetStdioHandle(int num) {
}
+const char* Socket::LookupIPv4Address(char* host, OSError** os_error) {
+ // Perform a name lookup for an IPv4 address.
+ struct addrinfo hints;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = IPPROTO_TCP;
+ struct addrinfo* info = NULL;
+ int status = getaddrinfo(host, 0, &hints, &info);
+ if (status != 0) {
+ ASSERT(*os_error == NULL);
+ *os_error = new OSError(status,
+ gai_strerror(status),
+ OSError::kGetAddressInfo);
+ (*os_error)->set_code(status);
+ (*os_error)->SetMessage(gai_strerror(status));
+ return NULL;
+ }
+ // Convert the address into IPv4 dotted decomal notation.
Mads Ager (google) 2012/03/14 12:51:51 decomal -> decimal
Søren Gjesse 2012/03/19 10:05:43 Done.
+ char* buffer = reinterpret_cast<char*>(malloc(INET_ADDRSTRLEN));
+ sockaddr_in *sockaddr = reinterpret_cast<sockaddr_in *>(info->ai_addr);
+ const char* result = inet_ntop(AF_INET,
+ reinterpret_cast<void *>(&sockaddr->sin_addr),
+ buffer,
+ INET_ADDRSTRLEN);
+ if (result == NULL) {
+ free(buffer);
+ return NULL;
+ }
+ ASSERT(result == buffer);
+ return buffer;
+}
+
+
intptr_t ServerSocket::CreateBindListen(const char* host,
intptr_t port,
intptr_t backlog) {

Powered by Google App Engine
This is Rietveld 408576698