Show
Ignore:
Timestamp:
08/30/08 15:15:48 (4 months ago)
Author:
frsyuki
Message:

lang/c/mpio: added mp::iothreads::reader and mp::iothreads::writer

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/c/mpio/trunk/mp/multiplex_impl.pre.h

    r18340 r18476  
    5757manager::cb_t::cb_t(handler* h, short ev) : 
    5858        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} 
    6063 
    6164manager::cb_t::~cb_t() 
     
    98101                m_used = 0; 
    99102        } else { 
    100                 std::memmove(m_wbuffer, m_wbuffer+len, len); 
     103                std::memmove(m_wbuffer, m_wbuffer+len, m_used-len); 
    101104        } 
    102105} 
     
    169172void manager::send_data_impl(int fd, const char* buf, size_t len) 
    170173{ 
    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); 
    172177} 
    173178 
     
    196201        while(!m_end_flag) { 
    197202                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(); 
    206203                        if( event & EV_READ ) { 
    207204                                try_read(*pcb); 
     
    211208                        } 
    212209                } 
     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(); 
    213218                if( (ret = m_ev.wait()) < 0 ) { return ret; } 
    214219        } 
     
    229234bool manager::try_write(cb_t& cb) 
    230235{ 
     236        if(cb.length() == 0) { return false; } 
    231237        ssize_t len = ::write(cb.get().fd(), cb.wbuffer(), cb.length()); 
    232238        if(len < 0) {