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

Side by Side Diff: remoting/host/linux/audio_pipe_reader.cc

Issue 820123002: Use O_NONBLOCK when opening audio pipe on linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 12 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
« no previous file with comments | « no previous file | no next file » | 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 Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "remoting/host/linux/audio_pipe_reader.h" 5 #include "remoting/host/linux/audio_pipe_reader.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 LOG(ERROR) << "File watcher returned an error."; 100 LOG(ERROR) << "File watcher returned an error.";
101 return; 101 return;
102 } 102 }
103 103
104 TryOpenPipe(); 104 TryOpenPipe();
105 } 105 }
106 106
107 void AudioPipeReader::TryOpenPipe() { 107 void AudioPipeReader::TryOpenPipe() {
108 DCHECK(task_runner_->BelongsToCurrentThread()); 108 DCHECK(task_runner_->BelongsToCurrentThread());
109 109
110 base::File new_pipe; 110 base::File new_pipe(
111 new_pipe.Initialize( 111 HANDLE_EINTR(open(pipe_path_.value().c_str(), O_RDONLY | O_NONBLOCK)));
112 pipe_path_,
113 base::File::FLAG_OPEN | base::File::FLAG_READ | base::File::FLAG_ASYNC);
114 112
115 // If both |pipe_| and |new_pipe| are valid then compare inodes for the two 113 // If both |pipe_| and |new_pipe| are valid then compare inodes for the two
116 // file descriptors. Don't need to do anything if inode hasn't changed. 114 // file descriptors. Don't need to do anything if inode hasn't changed.
117 if (new_pipe.IsValid() && pipe_.IsValid()) { 115 if (new_pipe.IsValid() && pipe_.IsValid()) {
118 struct stat old_stat; 116 struct stat old_stat;
119 struct stat new_stat; 117 struct stat new_stat;
120 if (fstat(pipe_.GetPlatformFile(), &old_stat) == 0 && 118 if (fstat(pipe_.GetPlatformFile(), &old_stat) == 0 &&
121 fstat(new_pipe.GetPlatformFile(), &new_stat) == 0 && 119 fstat(new_pipe.GetPlatformFile(), &new_stat) == 0 &&
122 old_stat.st_ino == new_stat.st_ino) { 120 old_stat.st_ino == new_stat.st_ino) {
123 return; 121 return;
124 } 122 }
125 } 123 }
126 124
127 file_descriptor_watcher_.StopWatchingFileDescriptor(); 125 file_descriptor_watcher_.StopWatchingFileDescriptor();
128 timer_.Stop(); 126 timer_.Stop();
129 127
130 pipe_ = new_pipe.Pass(); 128 pipe_ = new_pipe.Pass();
131 129
132 if (pipe_.IsValid()) { 130 if (pipe_.IsValid()) {
133 // Set O_NONBLOCK flag.
134 if (HANDLE_EINTR(fcntl(pipe_.GetPlatformFile(), F_SETFL, O_NONBLOCK)) < 0) {
135 PLOG(ERROR) << "fcntl";
136 pipe_.Close();
137 return;
138 }
139
140 // Set buffer size for the pipe. 131 // Set buffer size for the pipe.
141 if (HANDLE_EINTR(fcntl( 132 if (HANDLE_EINTR(fcntl(
142 pipe_.GetPlatformFile(), F_SETPIPE_SZ, kPipeBufferSizeBytes)) < 0) { 133 pipe_.GetPlatformFile(), F_SETPIPE_SZ, kPipeBufferSizeBytes)) < 0) {
143 PLOG(ERROR) << "fcntl"; 134 PLOG(ERROR) << "fcntl";
144 } 135 }
145 136
146 WaitForPipeReadable(); 137 WaitForPipeReadable();
147 } 138 }
148 } 139 }
149 140
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 pipe_.GetPlatformFile(), false, base::MessageLoopForIO::WATCH_READ, 208 pipe_.GetPlatformFile(), false, base::MessageLoopForIO::WATCH_READ,
218 &file_descriptor_watcher_, this); 209 &file_descriptor_watcher_, this);
219 } 210 }
220 211
221 // static 212 // static
222 void AudioPipeReaderTraits::Destruct(const AudioPipeReader* audio_pipe_reader) { 213 void AudioPipeReaderTraits::Destruct(const AudioPipeReader* audio_pipe_reader) {
223 audio_pipe_reader->task_runner_->DeleteSoon(FROM_HERE, audio_pipe_reader); 214 audio_pipe_reader->task_runner_->DeleteSoon(FROM_HERE, audio_pipe_reader);
224 } 215 }
225 216
226 } // namespace remoting 217 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698