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

Side by Side Diff: src/platform-posix.cc

Issue 6062002: Merge 6006:6095 from bleeding_edge to experimental/gc branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: Created 10 years 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 | « src/platform-nullos.cc ('k') | src/platform-win32.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 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 135
136 void OS::VPrint(const char* format, va_list args) { 136 void OS::VPrint(const char* format, va_list args) {
137 #if defined(ANDROID) 137 #if defined(ANDROID)
138 LOG_PRI_VA(ANDROID_LOG_INFO, LOG_TAG, format, args); 138 LOG_PRI_VA(ANDROID_LOG_INFO, LOG_TAG, format, args);
139 #else 139 #else
140 vprintf(format, args); 140 vprintf(format, args);
141 #endif 141 #endif
142 } 142 }
143 143
144 144
145 void OS::FPrint(FILE* out, const char* format, ...) {
146 va_list args;
147 va_start(args, format);
148 VFPrint(out, format, args);
149 va_end(args);
150 }
151
152
153 void OS::VFPrint(FILE* out, const char* format, va_list args) {
154 #if defined(ANDROID)
155 LOG_PRI_VA(ANDROID_LOG_INFO, LOG_TAG, format, args);
156 #else
157 vfprintf(out, format, args);
158 #endif
159 }
160
161
145 void OS::PrintError(const char* format, ...) { 162 void OS::PrintError(const char* format, ...) {
146 va_list args; 163 va_list args;
147 va_start(args, format); 164 va_start(args, format);
148 VPrintError(format, args); 165 VPrintError(format, args);
149 va_end(args); 166 va_end(args);
150 } 167 }
151 168
152 169
153 void OS::VPrintError(const char* format, va_list args) { 170 void OS::VPrintError(const char* format, va_list args) {
154 #if defined(ANDROID) 171 #if defined(ANDROID)
(...skipping 11 matching lines...) Expand all
166 va_end(args); 183 va_end(args);
167 return result; 184 return result;
168 } 185 }
169 186
170 187
171 int OS::VSNPrintF(Vector<char> str, 188 int OS::VSNPrintF(Vector<char> str,
172 const char* format, 189 const char* format,
173 va_list args) { 190 va_list args) {
174 int n = vsnprintf(str.start(), str.length(), format, args); 191 int n = vsnprintf(str.start(), str.length(), format, args);
175 if (n < 0 || n >= str.length()) { 192 if (n < 0 || n >= str.length()) {
176 str[str.length() - 1] = '\0'; 193 // If the length is zero, the assignment fails.
194 if (str.length() > 0)
195 str[str.length() - 1] = '\0';
177 return -1; 196 return -1;
178 } else { 197 } else {
179 return n; 198 return n;
180 } 199 }
181 } 200 }
182 201
183 202
184 // ---------------------------------------------------------------------------- 203 // ----------------------------------------------------------------------------
185 // POSIX string support. 204 // POSIX string support.
186 // 205 //
(...skipping 10 matching lines...) Expand all
197 216
198 // ---------------------------------------------------------------------------- 217 // ----------------------------------------------------------------------------
199 // POSIX socket support. 218 // POSIX socket support.
200 // 219 //
201 220
202 class POSIXSocket : public Socket { 221 class POSIXSocket : public Socket {
203 public: 222 public:
204 explicit POSIXSocket() { 223 explicit POSIXSocket() {
205 // Create the socket. 224 // Create the socket.
206 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 225 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
226 if (IsValid()) {
227 // Allow rapid reuse.
228 static const int kOn = 1;
229 int ret = setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR,
230 &kOn, sizeof(kOn));
231 ASSERT(ret == 0);
232 USE(ret);
233 }
207 } 234 }
208 explicit POSIXSocket(int socket): socket_(socket) { } 235 explicit POSIXSocket(int socket): socket_(socket) { }
209 virtual ~POSIXSocket() { Shutdown(); } 236 virtual ~POSIXSocket() { Shutdown(); }
210 237
211 // Server initialization. 238 // Server initialization.
212 bool Bind(const int port); 239 bool Bind(const int port);
213 bool Listen(int backlog) const; 240 bool Listen(int backlog) const;
214 Socket* Accept() const; 241 Socket* Accept() const;
215 242
216 // Client initialization. 243 // Client initialization.
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 return ntohl(value); 385 return ntohl(value);
359 } 386 }
360 387
361 388
362 Socket* OS::CreateSocket() { 389 Socket* OS::CreateSocket() {
363 return new POSIXSocket(); 390 return new POSIXSocket();
364 } 391 }
365 392
366 393
367 } } // namespace v8::internal 394 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-nullos.cc ('k') | src/platform-win32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698