OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 ASSERT(buffer->size() >= m_readPosition); | 47 ASSERT(buffer->size() >= m_readPosition); |
48 Vector<RefPtr<SharedBuffer>> newBufferQueue; | 48 Vector<RefPtr<SharedBuffer>> newBufferQueue; |
49 | 49 |
50 const char* segment = 0; | 50 const char* segment = 0; |
51 while (size_t length = buffer->getSomeData(segment, m_readPosition)) { | 51 while (size_t length = buffer->getSomeData(segment, m_readPosition)) { |
52 m_readPosition += length; | 52 m_readPosition += length; |
53 newBufferQueue.append(SharedBuffer::create(segment, length)); | 53 newBufferQueue.append(SharedBuffer::create(segment, length)); |
54 } | 54 } |
55 | 55 |
56 MutexLocker locker(m_mutex); | 56 MutexLocker locker(m_mutex); |
57 if (m_allDataReceived && newBufferQueue.size()) { | |
chrishtr
2015/12/03 17:51:51
Is this code reachable in one of your testcases? N
aleksandar.stojiljkovic
2015/12/03 18:04:14
No, it is not reachable and it mustn't be. It wasn
chrishtr
2015/12/03 18:32:00
If it is not something that can happen, just put i
aleksandar.stojiljkovic
2015/12/03 21:17:09
Done.
| |
58 // This prevents from unexisting use case now - if all data was previous ly | |
59 // received, don't append more to it. | |
60 ASSERT(false); | |
61 newBufferQueue.clear(); | |
62 return; | |
63 } | |
64 | |
57 m_newBufferQueue.appendVector(newBufferQueue); | 65 m_newBufferQueue.appendVector(newBufferQueue); |
58 newBufferQueue.clear(); | 66 newBufferQueue.clear(); |
59 m_allDataReceived = allDataReceived; | 67 m_allDataReceived = allDataReceived; |
60 } | 68 } |
61 | 69 |
62 void ThreadSafeDataTransport::data(SharedBuffer** buffer, bool* allDataReceived) | 70 void ThreadSafeDataTransport::data(SharedBuffer** buffer, bool* allDataReceived) |
63 { | 71 { |
64 ASSERT(buffer); | 72 ASSERT(buffer); |
65 ASSERT(allDataReceived); | 73 ASSERT(allDataReceived); |
66 Vector<RefPtr<SharedBuffer>> newBufferQueue; | 74 Vector<RefPtr<SharedBuffer>> newBufferQueue; |
67 { | 75 { |
68 MutexLocker lock(m_mutex); | 76 MutexLocker lock(m_mutex); |
69 m_newBufferQueue.swap(newBufferQueue); | 77 m_newBufferQueue.swap(newBufferQueue); |
70 *allDataReceived = m_allDataReceived; | 78 *allDataReceived = m_allDataReceived; |
71 } | 79 } |
72 for (size_t i = 0; i < newBufferQueue.size(); ++i) | 80 for (size_t i = 0; i < newBufferQueue.size(); ++i) |
73 m_readBuffer->append(newBufferQueue[i].get()); | 81 m_readBuffer->append(newBufferQueue[i].get()); |
74 *buffer = m_readBuffer.get(); | 82 *buffer = m_readBuffer.get(); |
75 } | 83 } |
76 | 84 |
77 bool ThreadSafeDataTransport::hasNewData() | 85 bool ThreadSafeDataTransport::hasNewData() |
78 { | 86 { |
79 MutexLocker lock(m_mutex); | 87 MutexLocker lock(m_mutex); |
80 return !m_newBufferQueue.isEmpty(); | 88 return !m_newBufferQueue.isEmpty(); |
81 } | 89 } |
82 | 90 |
83 } // namespace blink | 91 } // namespace blink |
OLD | NEW |