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

Side by Side Diff: base/shared_memory_posix.cc

Issue 391009: Don't do work in the SharedIOBuffer constructor; use an Init method instead. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/renderer_host/async_resource_handler.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/shared_memory.h" 5 #include "base/shared_memory.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <sys/mman.h> 9 #include <sys/mman.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 file_closer.reset(fp); // close when we go out of scope 196 file_closer.reset(fp); // close when we go out of scope
197 197
198 // Make sure the (new) file is the right size. 198 // Make sure the (new) file is the right size.
199 if (size && (posix_flags & (O_RDWR | O_CREAT))) { 199 if (size && (posix_flags & (O_RDWR | O_CREAT))) {
200 // Get current size. 200 // Get current size.
201 struct stat stat; 201 struct stat stat;
202 if (fstat(fileno(fp), &stat) != 0) 202 if (fstat(fileno(fp), &stat) != 0)
203 return false; 203 return false;
204 const size_t current_size = stat.st_size; 204 const size_t current_size = stat.st_size;
205 if (current_size != size) { 205 if (current_size != size) {
206 // TODO(hawk): When finished with bug 16371, revert this CHECK() to: 206 if (ftruncate(fileno(fp), size) != 0)
207 // if (ftruncate(fileno(fp), size) != 0) 207 return false;
208 // return false;
209 CHECK(!ftruncate(fileno(fp), size));
210 if (fseeko(fp, size, SEEK_SET) != 0) 208 if (fseeko(fp, size, SEEK_SET) != 0)
211 return false; 209 return false;
212 } 210 }
213 } 211 }
214 212
215 mapped_file_ = dup(fileno(fp)); 213 mapped_file_ = dup(fileno(fp));
216 if (mapped_file_ == -1) { 214 if (mapped_file_ == -1) {
217 if (errno == EMFILE) { 215 if (errno == EMFILE) {
218 LOG(WARNING) << "Shared memory creation failed; out of file descriptors"; 216 LOG(WARNING) << "Shared memory creation failed; out of file descriptors";
219 return false; 217 return false;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 302
305 void SharedMemory::Unlock() { 303 void SharedMemory::Unlock() {
306 LockOrUnlockCommon(F_ULOCK); 304 LockOrUnlockCommon(F_ULOCK);
307 } 305 }
308 306
309 SharedMemoryHandle SharedMemory::handle() const { 307 SharedMemoryHandle SharedMemory::handle() const {
310 return FileDescriptor(mapped_file_, false); 308 return FileDescriptor(mapped_file_, false);
311 } 309 }
312 310
313 } // namespace base 311 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/renderer_host/async_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698