Index: trunk/switchboard/fcgi_record_writer.h |
— | — | @@ -49,6 +49,7 @@ |
50 | 50 | boost::function <void(asio::error_code)>); |
51 | 51 | void write_noflush(fcgi::recordp record); |
52 | 52 | void flush(boost::function<void (asio::error_code)>); |
| 53 | + void close(); |
53 | 54 | |
54 | 55 | private: |
55 | 56 | sbcontext &context_; |
— | — | @@ -56,6 +57,7 @@ |
57 | 58 | std::vector<record_writer_detail::pending_record> inflight_; |
58 | 59 | std::vector<record_writer_detail::pending_record> waiting_; |
59 | 60 | std::vector<asio::mutable_buffer> buffers_; |
| 61 | + bool alive_; |
60 | 62 | |
61 | 63 | void write_done( |
62 | 64 | asio::error_code error, |
— | — | @@ -76,13 +78,13 @@ |
77 | 79 | typedef boost::shared_ptr<fcgi_record_writer<asio::ip::tcp::socket> > fcgi_record_writer_tcpp; |
78 | 80 | typedef boost::shared_ptr<fcgi_record_writer<asio::local::stream_protocol::socket> > fcgi_record_writer_unixp; |
79 | 81 | |
80 | | - |
81 | 82 | template<typename Socket> |
82 | 83 | fcgi_record_writer<Socket>::fcgi_record_writer( |
83 | 84 | sbcontext &context, |
84 | 85 | Socket &socket) |
85 | 86 | : context_(context) |
86 | 87 | , socket_(socket) |
| 88 | + , alive_(true) |
87 | 89 | , logger(log4cxx::Logger::getLogger("switchboard.fcgi_record_writer")) |
88 | 90 | { |
89 | 91 | LOG4CXX_DEBUG(logger, boost::format("record_writer@%p: created") % this); |
— | — | @@ -90,10 +92,20 @@ |
91 | 93 | |
92 | 94 | template<typename Socket> |
93 | 95 | void |
| 96 | +fcgi_record_writer<Socket>::close() |
| 97 | +{ |
| 98 | + alive_ = false; |
| 99 | +} |
| 100 | + |
| 101 | +template<typename Socket> |
| 102 | +void |
94 | 103 | fcgi_record_writer<Socket>::write_noflush(fcgi::recordp record) |
95 | 104 | { |
96 | 105 | LOG4CXX_DEBUG(logger, boost::format("record_writer@%p: write_noflush()") % this); |
97 | 106 | |
| 107 | + if (!alive_) |
| 108 | + return; |
| 109 | + |
98 | 110 | record_writer_detail::pending_record pend = { |
99 | 111 | record, |
100 | 112 | { |
— | — | @@ -112,6 +124,9 @@ |
113 | 125 | fcgi::recordp record, |
114 | 126 | boost::function<void (asio::error_code)> func) |
115 | 127 | { |
| 128 | + if (!alive_) |
| 129 | + return; |
| 130 | + |
116 | 131 | assert(socket_.native() != -1); |
117 | 132 | LOG4CXX_DEBUG(logger, boost::format("record_writer@%p: write()") % this); |
118 | 133 | |
— | — | @@ -124,6 +139,9 @@ |
125 | 140 | void |
126 | 141 | fcgi_record_writer<Socket>::flush(boost::function<void (asio::error_code)> func) |
127 | 142 | { |
| 143 | + if (!alive_) |
| 144 | + return; |
| 145 | + |
128 | 146 | assert(socket_.native() != -1); |
129 | 147 | if (!inflight_.empty() || waiting_.empty()) { |
130 | 148 | func(asio::error_code()); |
— | — | @@ -159,6 +177,9 @@ |
160 | 178 | std::size_t bytes, |
161 | 179 | boost::function<void (asio::error_code)> func) |
162 | 180 | { |
| 181 | + if (!alive_) |
| 182 | + return; |
| 183 | + |
163 | 184 | if (error) { |
164 | 185 | func(error); |
165 | 186 | return; |
Index: trunk/switchboard/fcgi_server_connection.h |
— | — | @@ -67,7 +67,6 @@ |
68 | 68 | { |
69 | 69 | } |
70 | 70 | |
71 | | - //boost::shared_ptr<fcgi_socket<typename Protocol::socket> > &socket(); |
72 | 71 | fcgi_socket_basep socket() { |
73 | 72 | return boost::static_pointer_cast<fcgi_socket<typename Protocol::socket> >(socket_); |
74 | 73 | } |
Index: trunk/switchboard/fcgi_socket.h |
— | — | @@ -118,6 +118,7 @@ |
119 | 119 | |
120 | 120 | alive_ = false; |
121 | 121 | close_sig_(); |
| 122 | + writer_->close(); |
122 | 123 | writer_.reset(); |
123 | 124 | socket_.close(); |
124 | 125 | } |