1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Execution Server
3 * ---------------------------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 *//*--------------------------------------------------------------------*/
24 #include "xsPosixFileReader.hpp"
33 FileReader::FileReader (int blockSize, int numBlocks)
35 , m_buf (blockSize, numBlocks)
40 FileReader::~FileReader (void)
44 void FileReader::start (const char* filename)
46 DE_ASSERT(!m_isRunning);
48 m_file = deFile_create(filename, DE_FILEMODE_OPEN|DE_FILEMODE_READ);
51 #if (DE_OS != DE_OS_IOS)
52 // Set to non-blocking mode.
53 if (!deFile_setFlags(m_file, DE_FILE_NONBLOCKING))
55 deFile_destroy(m_file);
57 XS_FAIL("Failed to set non-blocking mode");
66 void FileReader::run (void)
68 std::vector<deUint8> tmpBuf (FILEREADER_TMP_BUFFER_SIZE);
71 while (!m_buf.isCanceled())
73 deFileResult result = deFile_read(m_file, &tmpBuf[0], (deInt64)tmpBuf.size(), &numRead);
75 if (result == DE_FILERESULT_SUCCESS)
80 m_buf.write((int)numRead, &tmpBuf[0]);
83 catch (const ThreadedByteBuffer::CanceledException&)
89 else if (result == DE_FILERESULT_END_OF_FILE ||
90 result == DE_FILERESULT_WOULD_BLOCK)
92 // Wait for more data.
93 deSleep(FILEREADER_IDLE_SLEEP);
100 void FileReader::stop (void)
103 return; // Nothing to do.
111 deFile_destroy(m_file);