99{
100 if (m_buf == NULL) return 0;
101 m_header.nreader++;
102 unsigned int nword = 0;
103 while (true) {
104 unsigned int i_w = m_header.nword_in % m_nword;
105 unsigned int i_r = m_header.nword_out % m_nword;
106 nword = m_buf[i_r];
107 if (nword > 0) {
108 if (m_header.nword_in - m_header.nword_out >= (nword + 1)) {
109 if (i_w > i_r) {
110 memcpy(buf, (m_buf + i_r + 1), sizeof(int) * nword);
111 break;
112 } else if (i_w < i_r) {
113 if (m_nword - i_r > nword) {
114 memcpy(buf, (m_buf + i_r + 1), sizeof(int) * nword);
115 break;
116 } else {
117 unsigned int count = m_nword - i_r;
118 memcpy(buf, (m_buf + i_r + 1), sizeof(int) * count);
119 if (nword > count) {
120 memcpy(buf + count, m_buf, sizeof(int) * (nword - count));
121 }
122 break;
123 }
124 }
125 }
126 }
127 }
128 m_header.nword_out += nword + 1;
129 unsigned int count = ++m_header.count_out;
130 m_header.nreader--;
131 if (hdr != NULL) {
132 memcpy(hdr, &m_header, sizeof(EventBuffer::Header));
133 }
134 return count;
135}