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

Side by Side Diff: runtime/bin/dbg_connection_macos.cc

Issue 1450113003: Avoid strerror_r portability issues (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: oops namespace Created 5 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « no previous file | runtime/bin/eventhandler_macos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_MACOS) 6 #if defined(TARGET_OS_MACOS)
7 7
8 #include <errno.h> // NOLINT 8 #include <errno.h> // NOLINT
9 #include <stdio.h> // NOLINT 9 #include <stdio.h> // NOLINT
10 #include <stdlib.h> // NOLINT 10 #include <stdlib.h> // NOLINT
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 DebuggerConnectionHandler::AcceptDbgConnection(fd); 83 DebuggerConnectionHandler::AcceptDbgConnection(fd);
84 84
85 /* For now, don't poll the debugger connection. 85 /* For now, don't poll the debugger connection.
86 struct kevent ev_add; 86 struct kevent ev_add;
87 EV_SET(&ev_add, fd, EVFILT_READ, EV_ADD, 0, 0, NULL); 87 EV_SET(&ev_add, fd, EVFILT_READ, EV_ADD, 0, 0, NULL);
88 int status = 88 int status =
89 TEMP_FAILURE_RETRY(kevent(kqueue_fd_, &ev_add, 1, NULL, 0, NULL)); 89 TEMP_FAILURE_RETRY(kevent(kqueue_fd_, &ev_add, 1, NULL, 0, NULL));
90 if (status == -1) { 90 if (status == -1) {
91 const int kBufferSize = 1024; 91 const int kBufferSize = 1024;
92 char error_message[kBufferSize]; 92 char error_message[kBufferSize];
93 strerror_r(errno, error_message, kBufferSize); 93 Utils::StrError(errno, error_message, kBufferSize);
94 FATAL1("Failed adding debugger socket to kqueue: %s\n", error_message); 94 FATAL1("Failed adding debugger socket to kqueue: %s\n", error_message);
95 } 95 }
96 */ 96 */
97 } else if (ident == wakeup_fds_[0]) { 97 } else if (ident == wakeup_fds_[0]) {
98 Message msg; 98 Message msg;
99 if (ReceiveMessage(&msg)) { 99 if (ReceiveMessage(&msg)) {
100 Log::Print("Received sync message id %d.\n", msg.msg_id); 100 Log::Print("Received sync message id %d.\n", msg.msg_id);
101 } 101 }
102 } else { 102 } else {
103 Log::Print("unexpected: receiving debugger connection event.\n"); 103 Log::Print("unexpected: receiving debugger connection event.\n");
104 UNIMPLEMENTED(); 104 UNIMPLEMENTED();
105 } 105 }
106 } 106 }
107 107
108 108
109 void DebuggerConnectionImpl::Handler(uword args) { 109 void DebuggerConnectionImpl::Handler(uword args) {
110 static const int kMaxEvents = 4; 110 static const int kMaxEvents = 4;
111 struct kevent events[kMaxEvents]; 111 struct kevent events[kMaxEvents];
112 112
113 while (1) { 113 while (1) {
114 // Wait indefinitely for an event. 114 // Wait indefinitely for an event.
115 int result = TEMP_FAILURE_RETRY( 115 int result = TEMP_FAILURE_RETRY(
116 kevent(kqueue_fd_, NULL, 0, events, kMaxEvents, NULL)); 116 kevent(kqueue_fd_, NULL, 0, events, kMaxEvents, NULL));
117 if (result == -1) { 117 if (result == -1) {
118 const int kBufferSize = 1024; 118 const int kBufferSize = 1024;
119 char error_message[kBufferSize]; 119 char error_message[kBufferSize];
120 strerror_r(errno, error_message, kBufferSize); 120 Utils::StrError(errno, error_message, kBufferSize);
121 FATAL1("kevent failed %s\n", error_message); 121 FATAL1("kevent failed %s\n", error_message);
122 } else { 122 } else {
123 ASSERT(result <= kMaxEvents); 123 ASSERT(result <= kMaxEvents);
124 for (int i = 0; i < result; i++) { 124 for (int i = 0; i < result; i++) {
125 HandleEvent(&events[i]); 125 HandleEvent(&events[i]);
126 } 126 }
127 } 127 }
128 } 128 }
129 Log::Print("shutting down debugger thread\n"); 129 Log::Print("shutting down debugger thread\n");
130 } 130 }
(...skipping 11 matching lines...) Expand all
142 if (kqueue_fd_ == -1) { 142 if (kqueue_fd_ == -1) {
143 FATAL("Failed creating kqueue\n"); 143 FATAL("Failed creating kqueue\n");
144 } 144 }
145 // Register the wakeup_fd_ with the kqueue. 145 // Register the wakeup_fd_ with the kqueue.
146 struct kevent event; 146 struct kevent event;
147 EV_SET(&event, wakeup_fds_[0], EVFILT_READ, EV_ADD, 0, 0, NULL); 147 EV_SET(&event, wakeup_fds_[0], EVFILT_READ, EV_ADD, 0, 0, NULL);
148 int status = NO_RETRY_EXPECTED(kevent(kqueue_fd_, &event, 1, NULL, 0, NULL)); 148 int status = NO_RETRY_EXPECTED(kevent(kqueue_fd_, &event, 1, NULL, 0, NULL));
149 if (status == -1) { 149 if (status == -1) {
150 const int kBufferSize = 1024; 150 const int kBufferSize = 1024;
151 char error_message[kBufferSize]; 151 char error_message[kBufferSize];
152 strerror_r(errno, error_message, kBufferSize); 152 Utils::StrError(errno, error_message, kBufferSize);
153 FATAL1("Failed adding wakeup pipe fd to kqueue: %s\n", error_message); 153 FATAL1("Failed adding wakeup pipe fd to kqueue: %s\n", error_message);
154 } 154 }
155 155
156 // Register the listening socket. 156 // Register the listening socket.
157 EV_SET(&event, DebuggerConnectionHandler::listener_fd_, 157 EV_SET(&event, DebuggerConnectionHandler::listener_fd_,
158 EVFILT_READ, EV_ADD, 0, 0, NULL); 158 EVFILT_READ, EV_ADD, 0, 0, NULL);
159 status = NO_RETRY_EXPECTED(kevent(kqueue_fd_, &event, 1, NULL, 0, NULL)); 159 status = NO_RETRY_EXPECTED(kevent(kqueue_fd_, &event, 1, NULL, 0, NULL));
160 if (status == -1) { 160 if (status == -1) {
161 const int kBufferSize = 1024; 161 const int kBufferSize = 1024;
162 char error_message[kBufferSize]; 162 char error_message[kBufferSize];
163 strerror_r(errno, error_message, kBufferSize); 163 Utils::StrError(errno, error_message, kBufferSize);
164 FATAL1("Failed adding listener socket to kqueue: %s\n", error_message); 164 FATAL1("Failed adding listener socket to kqueue: %s\n", error_message);
165 } 165 }
166 } 166 }
167 167
168 168
169 void DebuggerConnectionImpl::StartHandler(int port_number) { 169 void DebuggerConnectionImpl::StartHandler(int port_number) {
170 ASSERT(DebuggerConnectionHandler::listener_fd_ != -1); 170 ASSERT(DebuggerConnectionHandler::listener_fd_ != -1);
171 SetupPollQueue(); 171 SetupPollQueue();
172 int result = Thread::Start(&DebuggerConnectionImpl::Handler, 0); 172 int result = Thread::Start(&DebuggerConnectionImpl::Handler, 0);
173 if (result != 0) { 173 if (result != 0) {
(...skipping 10 matching lines...) Expand all
184 184
185 185
186 intptr_t DebuggerConnectionImpl::Receive(intptr_t socket, char* buf, int len) { 186 intptr_t DebuggerConnectionImpl::Receive(intptr_t socket, char* buf, int len) {
187 return TEMP_FAILURE_RETRY(read(socket, buf, len)); 187 return TEMP_FAILURE_RETRY(read(socket, buf, len));
188 } 188 }
189 189
190 } // namespace bin 190 } // namespace bin
191 } // namespace dart 191 } // namespace dart
192 192
193 #endif // defined(TARGET_OS_MACOS) 193 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/eventhandler_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698