- Timestamp:
- 10/11/08 23:06:14 (8 weeks ago)
- Location:
- lang/c/mpio/trunk
- Files:
-
- 2 modified
-
mp/iothreads/reader.pre.h (modified) (4 diffs)
-
src/iothreads_reader.cc (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/c/mpio/trunk/mp/iothreads/reader.pre.h
r19504 r21142 61 61 MP_ARGS_END 62 62 63 static void close(int fd); 64 63 65 typedef function<void (handler&)> message_t; 64 66 static void send_message(int fd, message_t* msg); … … 89 91 void add(int fd, MP_ARGS_PARAMS); 90 92 MP_ARGS_END 93 94 void close(int fd); 91 95 92 96 void send_message(int fd, message_t* msg); … … 119 123 } 120 124 MP_ARGS_END 125 126 inline void reader::close(int fd) 127 { 128 instance().close(fd); 129 } 121 130 122 131 inline void reader::send_message(int fd, message_t* msg) … … 163 172 MP_ARGS_END 164 173 174 inline void close(int fd) 175 { 176 reader::close(fd); 177 } 165 178 166 179 MP_ARGS_BEGIN -
lang/c/mpio/trunk/src/iothreads_reader.cc
r20335 r21142 36 36 public: 37 37 void add(handler* h); 38 void close(int fd); 38 39 void send_message(int fd, message_t* msg); 39 40 … … 46 47 private: 47 48 typedef enum { 48 HANDLER, 49 ADD_HANDLER, 50 CLOSE_HANDLER, 49 51 MESSAGE, 50 52 } notify_type_t; … … 53 55 notify_type_t type; 54 56 union { 55 handler* h; 56 struct { 57 handler* h; // ADD_HANDLER 58 int fd; // CLOSE_HANDLER 59 struct { // MESSAGE 57 60 message_t* func; 58 61 int fd; … … 65 68 66 69 private: 70 void add_handler(handler* h); 71 void close_handler(handler* h); 72 73 private: 67 74 typedef event<handler*> ev_t; 68 75 ev_t m_ev; … … 105 112 } 106 113 114 void reader::impl::close(int fd) 115 { 116 worker_of(fd).close(fd); 117 } 118 107 119 void reader::impl::send_message(int fd, message_t* msg) 108 120 { … … 126 138 inline void reader::impl::worker::add(handler* h) 127 139 { 128 notify_entry e = { HANDLER };140 notify_entry e = { ADD_HANDLER }; 129 141 e.as.h = h; 142 m_notify.send(e); 143 } 144 145 inline void reader::impl::worker::close(int fd) 146 { 147 notify_entry e = { CLOSE_HANDLER }; 148 e.as.fd = fd; 130 149 m_notify.send(e); 131 150 } … … 179 198 h->read_event(); 180 199 } catch (...) { 181 int fd = h->fd(); 182 m_ev.remove(fd, EV_READ); 183 // FIXME closeはロジックスレッドで 184 // fdに対してイベント到着 185 // 直後にclose 186 // 直後にaccept 187 // イベントに対して返信 188 // 期待とは異なるfdに返信される 189 //::close(fd); 190 try { 191 iothreads::submit(close_delete, fd, h); 192 } catch (...) { 193 ::close(fd); 194 delete h; 195 } 200 close_handler(h); 196 201 } 197 202 } … … 199 204 inline void reader::impl::worker::notify_impl(notify_entry& e) 200 205 { 201 if(e.type == HANDLER) {206 if(e.type == ADD_HANDLER) { 202 207 handler* h = e.as.h; 203 try {204 m_ev.add(h->fd(), EV_READ, h); 205 } catch (...) {206 ::close(h->fd());207 delete h;208 }209 210 } else { 208 add_handler(h); 209 210 } else if(e.type == CLOSE_HANDLER) { 211 int fd = e.as.fd; 212 if(!m_ev.test(fd)) { return; } 213 close_handler(m_ev.data(fd)); 214 215 } else { // e.type == MESSAGE 211 216 int fd = e.as.m.fd; 212 217 if(!m_ev.test(fd)) { return; } 213 218 message_t* func = e.as.m.func; 214 219 try { 215 // FIXME check m_ev.test(fd);216 220 (*func)(*m_ev.data(fd)); 217 221 } catch (...) { … … 223 227 } 224 228 229 inline void reader::impl::worker::add_handler(handler* h) 230 { 231 try { 232 m_ev.add(h->fd(), EV_READ, h); 233 } catch (...) { 234 ::close(h->fd()); 235 delete h; 236 } 237 } 238 239 inline void reader::impl::worker::close_handler(handler* h) 240 { 241 m_ev.remove(h->fd(), EV_READ); 242 //::close(fd); // FIXME closeはロジックスレッドで 243 // 1. fdに対してイベント到着 244 // 2. 直後にclose 245 // 3. 直後にaccept, closeしたfdと同じ番号になり得る 246 // 4. イベントに対して返信するためにsend_data 247 // 5. 期待とは異なるfdに返信されてしまう 248 try { 249 iothreads::submit(close_delete, h->fd(), h); 250 } catch (...) { 251 ::close(h->fd()); 252 delete h; 253 } 254 } 255 225 256 226 257 } // namespace iothreads
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)