Changeset 18476 for lang/c/mpio/trunk/mp/multiplex_impl.pre.h
- Timestamp:
- 08/30/08 15:15:48 (4 months ago)
- Files:
-
- 1 modified
-
lang/c/mpio/trunk/mp/multiplex_impl.pre.h (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/c/mpio/trunk/mp/multiplex_impl.pre.h
r18340 r18476 57 57 manager::cb_t::cb_t(handler* h, short ev) : 58 58 m_handler(h), m_event(ev), 59 m_wbuffer(NULL), m_allocated(0), m_used(0) {} 59 m_wbuffer((char*)malloc(2048)), m_allocated(2048), m_used(0) 60 { 61 if(!m_wbuffer) { throw std::bad_alloc(); } 62 } 60 63 61 64 manager::cb_t::~cb_t() … … 98 101 m_used = 0; 99 102 } else { 100 std::memmove(m_wbuffer, m_wbuffer+len, len);103 std::memmove(m_wbuffer, m_wbuffer+len, m_used-len); 101 104 } 102 105 } … … 169 172 void manager::send_data_impl(int fd, const char* buf, size_t len) 170 173 { 171 m_ev.data(fd).append_buffer(buf, len); 174 cb_t& cb( m_ev.data(fd) ); 175 cb.append_buffer(buf, len); 176 m_wswitch_ctx.push_back(&cb); 172 177 } 173 178 … … 196 201 while(!m_end_flag) { 197 202 while( m_ev.next(&fd, &event, &pcb) ) { 198 for(wswitch_ctx_t::iterator it(m_wswitch_ctx.begin()), it_end(m_wswitch_ctx.end());199 it != it_end;200 ++it) {201 if( try_write(*pcb) ) {202 wswitch(*pcb);203 }204 }205 m_wswitch_ctx.clear();206 203 if( event & EV_READ ) { 207 204 try_read(*pcb); … … 211 208 } 212 209 } 210 for(wswitch_ctx_t::iterator it(m_wswitch_ctx.begin()), it_end(m_wswitch_ctx.end()); 211 it != it_end; 212 ++it) { 213 if( try_write(*pcb) ) { 214 wswitch(*pcb); 215 } 216 } 217 m_wswitch_ctx.clear(); 213 218 if( (ret = m_ev.wait()) < 0 ) { return ret; } 214 219 } … … 229 234 bool manager::try_write(cb_t& cb) 230 235 { 236 if(cb.length() == 0) { return false; } 231 237 ssize_t len = ::write(cb.get().fd(), cb.wbuffer(), cb.length()); 232 238 if(len < 0) {
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)