OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/tools/flip_server/sm_connection.h" | 5 #include "net/tools/flip_server/sm_connection.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <netinet/tcp.h> | 8 #include <netinet/tcp.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 ssl_state_(ssl_state), | 47 ssl_state_(ssl_state), |
48 memory_cache_(memory_cache), | 48 memory_cache_(memory_cache), |
49 acceptor_(acceptor), | 49 acceptor_(acceptor), |
50 read_buffer_(kSpdySegmentSize * 40), | 50 read_buffer_(kSpdySegmentSize * 40), |
51 sm_spdy_interface_(NULL), | 51 sm_spdy_interface_(NULL), |
52 sm_http_interface_(NULL), | 52 sm_http_interface_(NULL), |
53 sm_streamer_interface_(NULL), | 53 sm_streamer_interface_(NULL), |
54 sm_interface_(NULL), | 54 sm_interface_(NULL), |
55 log_prefix_(log_prefix), | 55 log_prefix_(log_prefix), |
56 max_bytes_sent_per_dowrite_(4096), | 56 max_bytes_sent_per_dowrite_(4096), |
57 ssl_(NULL) {} | 57 ssl_(NULL) { |
| 58 } |
58 | 59 |
59 SMConnection::~SMConnection() { | 60 SMConnection::~SMConnection() { |
60 if (initialized()) | 61 if (initialized()) |
61 Reset(); | 62 Reset(); |
62 } | 63 } |
63 | 64 |
64 EpollServer* SMConnection::epoll_server() { return epoll_server_; } | 65 EpollServer* SMConnection::epoll_server() { |
| 66 return epoll_server_; |
| 67 } |
65 | 68 |
66 void SMConnection::ReadyToSend() { | 69 void SMConnection::ReadyToSend() { |
67 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT | 70 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT |
68 << "Setting ready to send: EPOLLIN | EPOLLOUT"; | 71 << "Setting ready to send: EPOLLIN | EPOLLOUT"; |
69 epoll_server_->SetFDReady(fd_, EPOLLIN | EPOLLOUT); | 72 epoll_server_->SetFDReady(fd_, EPOLLIN | EPOLLOUT); |
70 } | 73 } |
71 | 74 |
72 void SMConnection::EnqueueDataFrame(DataFrame* df) { | 75 void SMConnection::EnqueueDataFrame(DataFrame* df) { |
73 output_list_.push_back(df); | 76 output_list_.push_back(df); |
74 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "EnqueueDataFrame: " | 77 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "EnqueueDataFrame: " |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 if (!DoWrite()) | 294 if (!DoWrite()) |
292 goto handle_close_or_error; | 295 goto handle_close_or_error; |
293 } | 296 } |
294 | 297 |
295 if (events_ & (EPOLLHUP | EPOLLERR)) { | 298 if (events_ & (EPOLLHUP | EPOLLERR)) { |
296 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "!!! Got HUP or ERR"; | 299 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "!!! Got HUP or ERR"; |
297 goto handle_close_or_error; | 300 goto handle_close_or_error; |
298 } | 301 } |
299 return; | 302 return; |
300 | 303 |
301 handle_close_or_error: | 304 handle_close_or_error: |
302 Cleanup("HandleEvents"); | 305 Cleanup("HandleEvents"); |
303 } | 306 } |
304 | 307 |
305 // Decide if SPDY was negotiated. | 308 // Decide if SPDY was negotiated. |
306 bool SMConnection::WasSpdyNegotiated(SpdyMajorVersion* version_negotiated) { | 309 bool SMConnection::WasSpdyNegotiated(SpdyMajorVersion* version_negotiated) { |
307 *version_negotiated = SPDY3; | 310 *version_negotiated = SPDY3; |
308 if (force_spdy()) | 311 if (force_spdy()) |
309 return true; | 312 return true; |
310 | 313 |
311 // If this is an SSL connection, check if NPN specifies SPDY. | 314 // If this is an SSL connection, check if NPN specifies SPDY. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 read_buffer_.AdvanceWritablePtr(bytes_read); | 477 read_buffer_.AdvanceWritablePtr(bytes_read); |
475 if (!DoConsumeReadData()) | 478 if (!DoConsumeReadData()) |
476 goto error_or_close; | 479 goto error_or_close; |
477 continue; | 480 continue; |
478 } else { // bytes_read == 0 | 481 } else { // bytes_read == 0 |
479 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT | 482 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT |
480 << "0 bytes read with recv call."; | 483 << "0 bytes read with recv call."; |
481 } | 484 } |
482 goto error_or_close; | 485 goto error_or_close; |
483 } | 486 } |
484 done: | 487 done: |
485 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "DoRead done!"; | 488 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "DoRead done!"; |
486 return true; | 489 return true; |
487 | 490 |
488 error_or_close: | 491 error_or_close: |
489 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT | 492 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT |
490 << "DoRead(): error_or_close. " | 493 << "DoRead(): error_or_close. " |
491 << "Cleaning up, then returning false"; | 494 << "Cleaning up, then returning false"; |
492 Cleanup("DoRead"); | 495 Cleanup("DoRead"); |
493 return false; | 496 return false; |
494 } | 497 } |
495 | 498 |
496 bool SMConnection::DoConsumeReadData() { | 499 bool SMConnection::DoConsumeReadData() { |
497 char* bytes; | 500 char* bytes; |
498 int size; | 501 int size; |
(...skipping 17 matching lines...) Expand all Loading... |
516 << sm_interface_->ErrorAsString(); | 519 << sm_interface_->ErrorAsString(); |
517 // this causes everything to be closed/cleaned up. | 520 // this causes everything to be closed/cleaned up. |
518 events_ |= EPOLLOUT; | 521 events_ |= EPOLLOUT; |
519 return false; | 522 return false; |
520 } | 523 } |
521 read_buffer_.GetReadablePtr(&bytes, &size); | 524 read_buffer_.GetReadablePtr(&bytes, &size); |
522 } | 525 } |
523 return true; | 526 return true; |
524 } | 527 } |
525 | 528 |
526 void SMConnection::HandleResponseFullyRead() { sm_interface_->Cleanup(); } | 529 void SMConnection::HandleResponseFullyRead() { |
| 530 sm_interface_->Cleanup(); |
| 531 } |
527 | 532 |
528 bool SMConnection::DoWrite() { | 533 bool SMConnection::DoWrite() { |
529 size_t bytes_sent = 0; | 534 size_t bytes_sent = 0; |
530 int flags = MSG_NOSIGNAL | MSG_DONTWAIT; | 535 int flags = MSG_NOSIGNAL | MSG_DONTWAIT; |
531 if (fd_ == -1) { | 536 if (fd_ == -1) { |
532 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT | 537 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT |
533 << "DoWrite: fd == -1. Returning false."; | 538 << "DoWrite: fd == -1. Returning false."; |
534 return false; | 539 return false; |
535 } | 540 } |
536 if (output_list_.empty()) { | 541 if (output_list_.empty()) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 continue; | 608 continue; |
604 } else if (bytes_written == -2) { | 609 } else if (bytes_written == -2) { |
605 // -2 handles SSL_ERROR_WANT_* errors | 610 // -2 handles SSL_ERROR_WANT_* errors |
606 events_ &= ~EPOLLOUT; | 611 events_ &= ~EPOLLOUT; |
607 goto done; | 612 goto done; |
608 } | 613 } |
609 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT | 614 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT |
610 << "0 bytes written with send call."; | 615 << "0 bytes written with send call."; |
611 goto error_or_close; | 616 goto error_or_close; |
612 } | 617 } |
613 done: | 618 done: |
614 UncorkSocket(); | 619 UncorkSocket(); |
615 return true; | 620 return true; |
616 | 621 |
617 error_or_close: | 622 error_or_close: |
618 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT | 623 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT |
619 << "DoWrite: error_or_close. Returning false " | 624 << "DoWrite: error_or_close. Returning false " |
620 << "after cleaning up"; | 625 << "after cleaning up"; |
621 Cleanup("DoWrite"); | 626 Cleanup("DoWrite"); |
622 UncorkSocket(); | 627 UncorkSocket(); |
623 return false; | 628 return false; |
624 } | 629 } |
625 | 630 |
626 void SMConnection::Reset() { | 631 void SMConnection::Reset() { |
627 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "Resetting"; | 632 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "Resetting"; |
(...skipping 29 matching lines...) Expand all Loading... |
657 SMConnection* SMConnection::NewSMConnection(EpollServer* epoll_server, | 662 SMConnection* SMConnection::NewSMConnection(EpollServer* epoll_server, |
658 SSLState* ssl_state, | 663 SSLState* ssl_state, |
659 MemoryCache* memory_cache, | 664 MemoryCache* memory_cache, |
660 FlipAcceptor* acceptor, | 665 FlipAcceptor* acceptor, |
661 std::string log_prefix) { | 666 std::string log_prefix) { |
662 return new SMConnection( | 667 return new SMConnection( |
663 epoll_server, ssl_state, memory_cache, acceptor, log_prefix); | 668 epoll_server, ssl_state, memory_cache, acceptor, log_prefix); |
664 } | 669 } |
665 | 670 |
666 } // namespace net | 671 } // namespace net |
OLD | NEW |