r17674 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17673‎ | r17674 | r17675 >
Date:16:31, 14 November 2006
Author:river
Status:old
Tags:
Comment:
socket spigot bug fixes
Modified paths:
  • /trunk/willow/src/willow/flowio.cc (modified) (history)

Diff [purge]

Index: trunk/willow/src/willow/flowio.cc
@@ -118,7 +118,10 @@
119119 /* _off was increased by the previous send, reduce _saved
120120 * appropriately
121121 */
122 - _saved -= _off;
 122+ if (_off >= _saved)
 123+ _saved = _off = 0;
 124+ else
 125+ _saved -= _off;
123126
124127 if (_saved) {
125128 switch (this->_maybe_dio_send(_off, _savebuf, _saved, _off)) {
@@ -139,7 +142,7 @@
140143 if (_off >= _saved)
141144 _off = _saved = 0;
142145
143 - read = s->read(_savebuf + _off + _saved, DIOBUFSZ);
 146+ read = s->read(_savebuf + _off + _saved, DIOBUFSZ - (_off + _saved));
144147 if (read == 0) {
145148 sp_cork();
146149 switch (this->_sp_data_empty()) {
@@ -189,59 +192,69 @@
190193 sink_result
191194 socket_sink::data_ready(char const *buf, size_t len, ssize_t &discard)
192195 {
193 -ssize_t off = 0;
194 -
195 - while (off < len) {
196 - ssize_t wrote;
197 - switch (wrote = _socket->write(buf + off, len - off)) {
198 - case -1:
199 - if (errno == EAGAIN) {
200 - _sink_spigot->sp_cork();
201 - if (!_reg) {
202 - _socket->writeback(polycaller<wsocket *, int>(
203 - *this, &socket_sink::_socketcall), 0);
204 - _reg = true;
205 - }
206 - return sink_result_blocked;
 196+ssize_t wrote;
 197+ if ((wrote = _socket->write(buf + off, len - off)) == -1) {
 198+ if (errno == EAGAIN) {
 199+ _sink_spigot->sp_cork();
 200+ if (!_reg) {
 201+ _socket->writeback(polycaller<wsocket *, int>(
 202+ *this, &socket_sink::_socketcall), 0);
 203+ _reg = true;
207204 }
208 - _sink_spigot->sp_cork();
209 - return sink_result_error;
210 - break;
 205+ return sink_result_blocked;
211206 }
212 - discard += wrote;
213 - _counter += wrote;
214 - off += wrote;
 207+ _sink_spigot->sp_cork();
 208+ return sink_result_error;
215209 }
216 - return sink_result_okay;
 210+
 211+ discard += wrote;
 212+ _counter += wrote;
 213+
 214+ if (len == wrote) {
 215+ return sink_result_okay;
 216+ } else {
 217+ _sink_spigot->sp_cork();
 218+ if (!_reg) {
 219+ _socket->writeback(polycaller<wsocket *, int>(
 220+ *this, &socket_sink::_socketcall), 0);
 221+ _reg = true;
 222+ }
 223+ return sink_result_blocked;
 224+ }
217225 }
218226
219227 sink_result
220228 socket_sink::dio_ready(int fd, off_t off, size_t len, ssize_t &discard)
221229 {
222 -ssize_t got = 0;
223 -
224 - while (got < len) {
225 - ssize_t wrote;
226 - switch (wrote = _socket->sendfile(fd, &off, len)) {
227 - case -1:
228 - if (errno == EAGAIN) {
229 - _sink_spigot->sp_cork();
230 - if (!_reg) {
231 - _socket->writeback(polycaller<wsocket *, int>(
232 - *this, &socket_sink::_socketcall), 0);
233 - _reg = true;
234 - }
235 - return sink_result_blocked;
 230+ssize_t wrote;
 231+ if ((wrote = _socket->sendfile(fd, &off, len)) == -1) {
 232+ if (errno == EAGAIN) {
 233+ _sink_spigot->sp_cork();
 234+ if (!_reg) {
 235+ _socket->writeback(polycaller<wsocket *, int>(
 236+ *this, &socket_sink::_socketcall), 0);
 237+ _reg = true;
236238 }
237 - _sink_spigot->sp_cork();
238 - return sink_result_error;
239 - break;
 239+ return sink_result_blocked;
240240 }
241 - discard += wrote;
242 - _counter += wrote;
243 - got += wrote;
 241+ _sink_spigot->sp_cork();
 242+ return sink_result_error;
 243+ break;
244244 }
245 - return sink_result_okay;
 245+ discard += wrote;
 246+ _counter += wrote;
 247+
 248+ if (len == wrote) {
 249+ return sink_result_okay;
 250+ } else {
 251+ _sink_spigot->sp_cork();
 252+ if (!_reg) {
 253+ _socket->writeback(polycaller<wsocket *, int>(
 254+ *this, &socket_sink::_socketcall), 0);
 255+ _reg = true;
 256+ }
 257+ return sink_result_blocked;
 258+ }
246259 }
247260
248261 tss<file_spigot::cache_map> file_spigot::_cache;