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

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

Issue 22634003: Replaced strerror() calls with threadsafe strerror_r() (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/bin/eventhandler_android.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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 81 }
82 FDUtils::SetBlocking(fd); 82 FDUtils::SetBlocking(fd);
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 FATAL1("Failed adding debugger socket to kqueue: %s\n", strerror(errno)); 91 const int kBufferSize = 1024;
92 char error_message[kBufferSize];
93 strerror_r(errno, error_message, kBufferSize);
94 FATAL1("Failed adding debugger socket to kqueue: %s\n", error_message);
92 } 95 }
93 */ 96 */
94 } else if (ident == wakeup_fds_[0]) { 97 } else if (ident == wakeup_fds_[0]) {
95 Message msg; 98 Message msg;
96 if (ReceiveMessage(&msg)) { 99 if (ReceiveMessage(&msg)) {
97 Log::Print("Received sync message id %d.\n", msg.msg_id); 100 Log::Print("Received sync message id %d.\n", msg.msg_id);
98 } 101 }
99 } else { 102 } else {
100 Log::Print("unexpected: receiving debugger connection event.\n"); 103 Log::Print("unexpected: receiving debugger connection event.\n");
101 UNIMPLEMENTED(); 104 UNIMPLEMENTED();
102 } 105 }
103 } 106 }
104 107
105 108
106 void DebuggerConnectionImpl::Handler(uword args) { 109 void DebuggerConnectionImpl::Handler(uword args) {
107 static const intptr_t kMaxEvents = 4; 110 static const intptr_t kMaxEvents = 4;
108 struct kevent events[kMaxEvents]; 111 struct kevent events[kMaxEvents];
109 112
110 while (1) { 113 while (1) {
111 // Wait indefinitely for an event. 114 // Wait indefinitely for an event.
112 int result = TEMP_FAILURE_RETRY( 115 int result = TEMP_FAILURE_RETRY(
113 kevent(kqueue_fd_, NULL, 0, events, kMaxEvents, NULL)); 116 kevent(kqueue_fd_, NULL, 0, events, kMaxEvents, NULL));
114 if (result == -1) { 117 if (result == -1) {
115 FATAL1("kevent failed %s\n", strerror(errno)); 118 const int kBufferSize = 1024;
119 char error_message[kBufferSize];
120 strerror_r(errno, error_message, kBufferSize);
121 FATAL1("kevent failed %s\n", error_message);
116 } else { 122 } else {
117 ASSERT(result <= kMaxEvents); 123 ASSERT(result <= kMaxEvents);
118 for (int i = 0; i < result; i++) { 124 for (int i = 0; i < result; i++) {
119 HandleEvent(&events[i]); 125 HandleEvent(&events[i]);
120 } 126 }
121 } 127 }
122 } 128 }
123 Log::Print("shutting down debugger thread\n"); 129 Log::Print("shutting down debugger thread\n");
124 } 130 }
125 131
126 132
127 void DebuggerConnectionImpl::SetupPollQueue() { 133 void DebuggerConnectionImpl::SetupPollQueue() {
128 int result; 134 int result;
129 result = TEMP_FAILURE_RETRY(pipe(wakeup_fds_)); 135 result = TEMP_FAILURE_RETRY(pipe(wakeup_fds_));
130 if (result != 0) { 136 if (result != 0) {
131 FATAL1("Pipe creation failed with error %d\n", result); 137 FATAL1("Pipe creation failed with error %d\n", result);
132 } 138 }
133 FDUtils::SetNonBlocking(wakeup_fds_[0]); 139 FDUtils::SetNonBlocking(wakeup_fds_[0]);
134 140
135 kqueue_fd_ = TEMP_FAILURE_RETRY(kqueue()); 141 kqueue_fd_ = TEMP_FAILURE_RETRY(kqueue());
136 if (kqueue_fd_ == -1) { 142 if (kqueue_fd_ == -1) {
137 FATAL("Failed creating kqueue\n"); 143 FATAL("Failed creating kqueue\n");
138 } 144 }
139 // Register the wakeup_fd_ with the kqueue. 145 // Register the wakeup_fd_ with the kqueue.
140 struct kevent event; 146 struct kevent event;
141 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);
142 int status = TEMP_FAILURE_RETRY(kevent(kqueue_fd_, &event, 1, NULL, 0, NULL)); 148 int status = TEMP_FAILURE_RETRY(kevent(kqueue_fd_, &event, 1, NULL, 0, NULL));
143 if (status == -1) { 149 if (status == -1) {
144 FATAL1("Failed adding wakeup pipe fd to kqueue: %s\n", strerror(errno)); 150 const int kBufferSize = 1024;
151 char error_message[kBufferSize];
152 strerror_r(errno, error_message, kBufferSize);
153 FATAL1("Failed adding wakeup pipe fd to kqueue: %s\n", error_message);
145 } 154 }
146 155
147 // Register the listening socket. 156 // Register the listening socket.
148 EV_SET(&event, DebuggerConnectionHandler::listener_fd_, 157 EV_SET(&event, DebuggerConnectionHandler::listener_fd_,
149 EVFILT_READ, EV_ADD, 0, 0, NULL); 158 EVFILT_READ, EV_ADD, 0, 0, NULL);
150 status = TEMP_FAILURE_RETRY(kevent(kqueue_fd_, &event, 1, NULL, 0, NULL)); 159 status = TEMP_FAILURE_RETRY(kevent(kqueue_fd_, &event, 1, NULL, 0, NULL));
151 if (status == -1) { 160 if (status == -1) {
152 FATAL1("Failed adding listener socket to kqueue: %s\n", strerror(errno)); 161 const int kBufferSize = 1024;
162 char error_message[kBufferSize];
163 strerror_r(errno, error_message, kBufferSize);
164 FATAL1("Failed adding listener socket to kqueue: %s\n", error_message);
153 } 165 }
154 } 166 }
155 167
156 168
157 void DebuggerConnectionImpl::StartHandler(int port_number) { 169 void DebuggerConnectionImpl::StartHandler(int port_number) {
158 ASSERT(DebuggerConnectionHandler::listener_fd_ != -1); 170 ASSERT(DebuggerConnectionHandler::listener_fd_ != -1);
159 SetupPollQueue(); 171 SetupPollQueue();
160 int result = dart::Thread::Start(&DebuggerConnectionImpl::Handler, 0); 172 int result = dart::Thread::Start(&DebuggerConnectionImpl::Handler, 0);
161 if (result != 0) { 173 if (result != 0) {
162 FATAL1("Failed to start debugger connection handler thread: %d\n", result); 174 FATAL1("Failed to start debugger connection handler thread: %d\n", result);
163 } 175 }
164 } 176 }
165 177
166 178
167 intptr_t DebuggerConnectionImpl::Send(intptr_t socket, 179 intptr_t DebuggerConnectionImpl::Send(intptr_t socket,
168 const char* buf, 180 const char* buf,
169 int len) { 181 int len) {
170 return TEMP_FAILURE_RETRY(write(socket, buf, len)); 182 return TEMP_FAILURE_RETRY(write(socket, buf, len));
171 } 183 }
172 184
173 185
174 intptr_t DebuggerConnectionImpl::Receive(intptr_t socket, char* buf, int len) { 186 intptr_t DebuggerConnectionImpl::Receive(intptr_t socket, char* buf, int len) {
175 return TEMP_FAILURE_RETRY(read(socket, buf, len)); 187 return TEMP_FAILURE_RETRY(read(socket, buf, len));
176 } 188 }
177 189
178 } // namespace bin 190 } // namespace bin
179 } // namespace dart 191 } // namespace dart
180 192
181 #endif // defined(TARGET_OS_MACOS) 193 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/eventhandler_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698