Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: net/tools/flip_server/sm_connection.cc

Issue 93793004: Format and Refactor Flip Server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/tools/flip_server/sm_connection.h ('k') | net/tools/flip_server/sm_interface.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
59 58
60 SMConnection::~SMConnection() { 59 SMConnection::~SMConnection() {
61 if (initialized()) 60 if (initialized())
62 Reset(); 61 Reset();
63 } 62 }
64 63
65 EpollServer* SMConnection::epoll_server() { 64 EpollServer* SMConnection::epoll_server() { return epoll_server_; }
66 return epoll_server_;
67 }
68 65
69 void SMConnection::ReadyToSend() { 66 void SMConnection::ReadyToSend() {
70 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 67 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
71 << "Setting ready to send: EPOLLIN | EPOLLOUT"; 68 << "Setting ready to send: EPOLLIN | EPOLLOUT";
72 epoll_server_->SetFDReady(fd_, EPOLLIN | EPOLLOUT); 69 epoll_server_->SetFDReady(fd_, EPOLLIN | EPOLLOUT);
73 } 70 }
74 71
75 void SMConnection::EnqueueDataFrame(DataFrame* df) { 72 void SMConnection::EnqueueDataFrame(DataFrame* df) {
76 output_list_.push_back(df); 73 output_list_.push_back(df);
77 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "EnqueueDataFrame: " 74 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "EnqueueDataFrame: "
(...skipping 19 matching lines...) Expand all
97 if (fd == -1) { 94 if (fd == -1) {
98 // If fd == -1, then we are initializing a new connection that will 95 // If fd == -1, then we are initializing a new connection that will
99 // connect to the backend. 96 // connect to the backend.
100 // 97 //
101 // ret: -1 == error 98 // ret: -1 == error
102 // 0 == connection in progress 99 // 0 == connection in progress
103 // 1 == connection complete 100 // 1 == connection complete
104 // TODO(kelindsay): is_numeric_host_address value needs to be detected 101 // TODO(kelindsay): is_numeric_host_address value needs to be detected
105 server_ip_ = server_ip; 102 server_ip_ = server_ip;
106 server_port_ = server_port; 103 server_port_ = server_port;
107 int ret = CreateConnectedSocket(&fd_, 104 int ret = CreateConnectedSocket(
108 server_ip, 105 &fd_, server_ip, server_port, true, acceptor_->disable_nagle_);
109 server_port,
110 true,
111 acceptor_->disable_nagle_);
112 106
113 if (ret < 0) { 107 if (ret < 0) {
114 LOG(ERROR) << "-1 Could not create connected socket"; 108 LOG(ERROR) << "-1 Could not create connected socket";
115 return; 109 return;
116 } else if (ret == 1) { 110 } else if (ret == 1) {
117 DCHECK_NE(-1, fd_); 111 DCHECK_NE(-1, fd_);
118 connection_complete_ = true; 112 connection_complete_ = true;
119 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 113 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
120 << "Connection complete to: " << server_ip_ << ":" 114 << "Connection complete to: " << server_ip_ << ":" << server_port_
121 << server_port_ << " "; 115 << " ";
122 } 116 }
123 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 117 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
124 << "Connecting to server: " << server_ip_ << ":" 118 << "Connecting to server: " << server_ip_ << ":" << server_port_
125 << server_port_ << " "; 119 << " ";
126 } else { 120 } else {
127 // If fd != -1 then we are initializing a connection that has just been 121 // If fd != -1 then we are initializing a connection that has just been
128 // accepted from the listen socket. 122 // accepted from the listen socket.
129 connection_complete_ = true; 123 connection_complete_ = true;
130 if (epoll_server_ && registered_in_epoll_server_ && fd_ != -1) { 124 if (epoll_server_ && registered_in_epoll_server_ && fd_ != -1) {
131 epoll_server_->UnregisterFD(fd_); 125 epoll_server_->UnregisterFD(fd_);
132 } 126 }
133 if (fd_ != -1) { 127 if (fd_ != -1) {
134 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 128 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
135 << "Closing pre-existing fd"; 129 << "Closing pre-existing fd";
136 close(fd_); 130 close(fd_);
137 fd_ = -1; 131 fd_ = -1;
138 } 132 }
139 133
140 fd_ = fd; 134 fd_ = fd;
141 } 135 }
142 136
143 registered_in_epoll_server_ = false; 137 registered_in_epoll_server_ = false;
144 // Set the last read time here as the idle checker will start from 138 // Set the last read time here as the idle checker will start from
145 // now. 139 // now.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 return; 248 return;
255 Reset(); 249 Reset();
256 if (connection_pool_) 250 if (connection_pool_)
257 connection_pool_->SMConnectionDone(this); 251 connection_pool_->SMConnectionDone(this);
258 if (sm_interface_) 252 if (sm_interface_)
259 sm_interface_->ResetForNewConnection(); 253 sm_interface_->ResetForNewConnection();
260 last_read_time_ = 0; 254 last_read_time_ = 0;
261 } 255 }
262 256
263 void SMConnection::HandleEvents() { 257 void SMConnection::HandleEvents() {
264 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "Received: " 258 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
265 << EpollServer::EventMaskToString(events_).c_str(); 259 << "Received: " << EpollServer::EventMaskToString(events_).c_str();
266 260
267 if (events_ & EPOLLIN) { 261 if (events_ & EPOLLIN) {
268 if (!DoRead()) 262 if (!DoRead())
269 goto handle_close_or_error; 263 goto handle_close_or_error;
270 } 264 }
271 265
272 if (events_ & EPOLLOUT) { 266 if (events_ & EPOLLOUT) {
273 // Check if we have connected or not 267 // Check if we have connected or not
274 if (connection_complete_ == false) { 268 if (connection_complete_ == false) {
275 int sock_error; 269 int sock_error;
276 socklen_t sock_error_len = sizeof(sock_error); 270 socklen_t sock_error_len = sizeof(sock_error);
277 int ret = getsockopt(fd_, SOL_SOCKET, SO_ERROR, &sock_error, 271 int ret =
278 &sock_error_len); 272 getsockopt(fd_, SOL_SOCKET, SO_ERROR, &sock_error, &sock_error_len);
279 if (ret != 0) { 273 if (ret != 0) {
280 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 274 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
281 << "getsockopt error: " << errno << ": " << strerror(errno); 275 << "getsockopt error: " << errno << ": " << strerror(errno);
282 goto handle_close_or_error; 276 goto handle_close_or_error;
283 } 277 }
284 if (sock_error == 0) { 278 if (sock_error == 0) {
285 connection_complete_ = true; 279 connection_complete_ = true;
286 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 280 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
287 << "Connection complete to " << server_ip_ << ":" 281 << "Connection complete to " << server_ip_ << ":"
288 << server_port_ << " "; 282 << server_port_ << " ";
289 } else if (sock_error == EINPROGRESS) { 283 } else if (sock_error == EINPROGRESS) {
290 return; 284 return;
291 } else { 285 } else {
292 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 286 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
293 << "error connecting to server"; 287 << "error connecting to server";
294 goto handle_close_or_error; 288 goto handle_close_or_error;
295 } 289 }
296 } 290 }
297 if (!DoWrite()) 291 if (!DoWrite())
298 goto handle_close_or_error; 292 goto handle_close_or_error;
299 } 293 }
300 294
301 if (events_ & (EPOLLHUP | EPOLLERR)) { 295 if (events_ & (EPOLLHUP | EPOLLERR)) {
302 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "!!! Got HUP or ERR"; 296 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "!!! Got HUP or ERR";
303 goto handle_close_or_error; 297 goto handle_close_or_error;
304 } 298 }
305 return; 299 return;
306 300
307 handle_close_or_error: 301 handle_close_or_error:
308 Cleanup("HandleEvents"); 302 Cleanup("HandleEvents");
309 } 303 }
310 304
311 // Decide if SPDY was negotiated. 305 // Decide if SPDY was negotiated.
312 bool SMConnection::WasSpdyNegotiated() { 306 bool SMConnection::WasSpdyNegotiated() {
313 if (force_spdy()) 307 if (force_spdy())
314 return true; 308 return true;
315 309
316 // If this is an SSL connection, check if NPN specifies SPDY. 310 // If this is an SSL connection, check if NPN specifies SPDY.
317 if (ssl_) { 311 if (ssl_) {
318 const unsigned char *npn_proto; 312 const unsigned char* npn_proto;
319 unsigned int npn_proto_len; 313 unsigned int npn_proto_len;
320 SSL_get0_next_proto_negotiated(ssl_, &npn_proto, &npn_proto_len); 314 SSL_get0_next_proto_negotiated(ssl_, &npn_proto, &npn_proto_len);
321 if (npn_proto_len > 0) { 315 if (npn_proto_len > 0) {
322 std::string npn_proto_str((const char *)npn_proto, npn_proto_len); 316 std::string npn_proto_str((const char*)npn_proto, npn_proto_len);
323 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 317 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
324 << "NPN protocol detected: " << npn_proto_str; 318 << "NPN protocol detected: " << npn_proto_str;
325 if (!strncmp(reinterpret_cast<const char*>(npn_proto), 319 if (!strncmp(reinterpret_cast<const char*>(npn_proto),
326 "spdy/2", npn_proto_len)) 320 "spdy/2",
321 npn_proto_len))
327 return true; 322 return true;
328 } 323 }
329 } 324 }
330 325
331 return false; 326 return false;
332 } 327 }
333 328
334 bool SMConnection::SetupProtocolInterfaces() { 329 bool SMConnection::SetupProtocolInterfaces() {
335 DCHECK(!protocol_detected_); 330 DCHECK(!protocol_detected_);
336 protocol_detected_ = true; 331 protocol_detected_ = true;
337 332
338 bool spdy_negotiated = WasSpdyNegotiated(); 333 bool spdy_negotiated = WasSpdyNegotiated();
339 bool using_ssl = ssl_ != NULL; 334 bool using_ssl = ssl_ != NULL;
340 335
341 if (using_ssl) 336 if (using_ssl)
342 VLOG(1) << (SSL_session_reused(ssl_) ? "Resumed" : "Renegotiated") 337 VLOG(1) << (SSL_session_reused(ssl_) ? "Resumed" : "Renegotiated")
343 << " SSL Session."; 338 << " SSL Session.";
344 339
345 if (acceptor_->spdy_only_ && !spdy_negotiated) { 340 if (acceptor_->spdy_only_ && !spdy_negotiated) {
346 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 341 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
347 << "SPDY proxy only, closing HTTPS connection."; 342 << "SPDY proxy only, closing HTTPS connection.";
348 return false; 343 return false;
349 } 344 }
350 345
351 switch (acceptor_->flip_handler_type_) { 346 switch (acceptor_->flip_handler_type_) {
352 case FLIP_HANDLER_HTTP_SERVER: 347 case FLIP_HANDLER_HTTP_SERVER: {
353 { 348 DCHECK(!spdy_negotiated);
354 DCHECK(!spdy_negotiated); 349 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
355 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 350 << (sm_http_interface_ ? "Creating" : "Reusing")
356 << (sm_http_interface_ ? "Creating" : "Reusing") 351 << " HTTP interface.";
357 << " HTTP interface."; 352 if (!sm_http_interface_)
358 if (!sm_http_interface_) 353 sm_http_interface_ = new HttpSM(this, NULL, memory_cache_, acceptor_);
359 sm_http_interface_ = new HttpSM(this, 354 sm_interface_ = sm_http_interface_;
360 NULL, 355 } break;
tyoshino (SeeGerritForStatus) 2013/12/09 06:54:06 put this inside braces?
yhirano 2013/12/09 07:41:00 Done.
361 memory_cache_, 356 case FLIP_HANDLER_PROXY: {
362 acceptor_); 357 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
363 sm_interface_ = sm_http_interface_; 358 << (sm_streamer_interface_ ? "Creating" : "Reusing")
359 << " PROXY Streamer interface.";
360 if (!sm_streamer_interface_) {
361 sm_streamer_interface_ =
362 new StreamerSM(this, NULL, epoll_server_, acceptor_);
363 sm_streamer_interface_->set_is_request();
364 } 364 }
365 break; 365 sm_interface_ = sm_streamer_interface_;
366 case FLIP_HANDLER_PROXY: 366 // If spdy is not negotiated, the streamer interface will proxy all
367 { 367 // data to the origin server.
368 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 368 if (!spdy_negotiated)
369 << (sm_streamer_interface_ ? "Creating" : "Reusing") 369 break;
370 << " PROXY Streamer interface."; 370 }
371 if (!sm_streamer_interface_) { 371 // Otherwise fall through into the case below.
372 sm_streamer_interface_ = new StreamerSM(this, 372 case FLIP_HANDLER_SPDY_SERVER: {
373 NULL, 373 DCHECK(spdy_negotiated);
374 epoll_server_, 374 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
375 acceptor_); 375 << (sm_spdy_interface_ ? "Creating" : "Reusing")
376 sm_streamer_interface_->set_is_request(); 376 << " SPDY interface.";
377 } 377 if (!sm_spdy_interface_)
378 sm_interface_ = sm_streamer_interface_; 378 sm_spdy_interface_ = new SpdySM(
379 // If spdy is not negotiated, the streamer interface will proxy all 379 this, NULL, epoll_server_, memory_cache_, acceptor_, SPDY2);
380 // data to the origin server. 380 sm_interface_ = sm_spdy_interface_;
381 if (!spdy_negotiated) 381 } break;
tyoshino (SeeGerritForStatus) 2013/12/09 06:54:06 ditto
yhirano 2013/12/09 07:41:00 Done.
382 break;
383 }
384 // Otherwise fall through into the case below.
385 case FLIP_HANDLER_SPDY_SERVER:
386 {
387 DCHECK(spdy_negotiated);
388 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
389 << (sm_spdy_interface_ ? "Creating" : "Reusing")
390 << " SPDY interface.";
391 if (!sm_spdy_interface_)
392 sm_spdy_interface_ = new SpdySM(this,
393 NULL,
394 epoll_server_,
395 memory_cache_,
396 acceptor_,
397 SPDY2);
398 sm_interface_ = sm_spdy_interface_;
399 }
400 break;
401 } 382 }
402 383
403 CorkSocket(); 384 CorkSocket();
404 if (!sm_interface_->PostAcceptHook()) 385 if (!sm_interface_->PostAcceptHook())
405 return false; 386 return false;
406 387
407 return true; 388 return true;
408 } 389 }
409 390
410 bool SMConnection::DoRead() { 391 bool SMConnection::DoRead() {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 429 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
449 << "Got EAGAIN while reading"; 430 << "Got EAGAIN while reading";
450 goto done; 431 goto done;
451 case EINTR: 432 case EINTR:
452 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 433 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
453 << "Got EINTR while reading"; 434 << "Got EINTR while reading";
454 continue; 435 continue;
455 default: 436 default:
456 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 437 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
457 << "While calling recv, got error: " 438 << "While calling recv, got error: "
458 << (ssl_?"(ssl error)":strerror(stored_errno)); 439 << (ssl_ ? "(ssl error)" : strerror(stored_errno));
459 goto error_or_close; 440 goto error_or_close;
460 } 441 }
461 } else if (bytes_read > 0) { 442 } else if (bytes_read > 0) {
462 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "read " << bytes_read 443 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "read " << bytes_read
463 << " bytes"; 444 << " bytes";
464 last_read_time_ = time(NULL); 445 last_read_time_ = time(NULL);
465 // If the protocol hasn't been detected yet, set up the handlers 446 // If the protocol hasn't been detected yet, set up the handlers
466 // we'll need. 447 // we'll need.
467 if (!protocol_detected_) { 448 if (!protocol_detected_) {
468 if (!SetupProtocolInterfaces()) { 449 if (!SetupProtocolInterfaces()) {
469 LOG(ERROR) << "Error setting up protocol interfaces."; 450 LOG(ERROR) << "Error setting up protocol interfaces.";
470 goto error_or_close; 451 goto error_or_close;
471 } 452 }
472 } 453 }
473 read_buffer_.AdvanceWritablePtr(bytes_read); 454 read_buffer_.AdvanceWritablePtr(bytes_read);
474 if (!DoConsumeReadData()) 455 if (!DoConsumeReadData())
475 goto error_or_close; 456 goto error_or_close;
476 continue; 457 continue;
477 } else { // bytes_read == 0 458 } else { // bytes_read == 0
478 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 459 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
479 << "0 bytes read with recv call."; 460 << "0 bytes read with recv call.";
480 } 461 }
481 goto error_or_close; 462 goto error_or_close;
482 } 463 }
483 done: 464 done:
484 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "DoRead done!"; 465 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "DoRead done!";
485 return true; 466 return true;
486 467
487 error_or_close: 468 error_or_close:
488 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 469 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
489 << "DoRead(): error_or_close. " 470 << "DoRead(): error_or_close. "
490 << "Cleaning up, then returning false"; 471 << "Cleaning up, then returning false";
491 Cleanup("DoRead"); 472 Cleanup("DoRead");
492 return false; 473 return false;
493 } 474 }
494 475
495 bool SMConnection::DoConsumeReadData() { 476 bool SMConnection::DoConsumeReadData() {
496 char* bytes; 477 char* bytes;
497 int size; 478 int size;
(...skipping 17 matching lines...) Expand all
515 << sm_interface_->ErrorAsString(); 496 << sm_interface_->ErrorAsString();
516 // this causes everything to be closed/cleaned up. 497 // this causes everything to be closed/cleaned up.
517 events_ |= EPOLLOUT; 498 events_ |= EPOLLOUT;
518 return false; 499 return false;
519 } 500 }
520 read_buffer_.GetReadablePtr(&bytes, &size); 501 read_buffer_.GetReadablePtr(&bytes, &size);
521 } 502 }
522 return true; 503 return true;
523 } 504 }
524 505
525 void SMConnection::HandleResponseFullyRead() { 506 void SMConnection::HandleResponseFullyRead() { sm_interface_->Cleanup(); }
526 sm_interface_->Cleanup();
527 }
528 507
529 bool SMConnection::DoWrite() { 508 bool SMConnection::DoWrite() {
530 size_t bytes_sent = 0; 509 size_t bytes_sent = 0;
531 int flags = MSG_NOSIGNAL | MSG_DONTWAIT; 510 int flags = MSG_NOSIGNAL | MSG_DONTWAIT;
532 if (fd_ == -1) { 511 if (fd_ == -1) {
533 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 512 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
534 << "DoWrite: fd == -1. Returning false."; 513 << "DoWrite: fd == -1. Returning false.";
535 return false; 514 return false;
536 } 515 }
537 if (output_list_.empty()) { 516 if (output_list_.empty()) {
538 VLOG(2) << log_prefix_ << "DoWrite: Output list empty."; 517 VLOG(2) << log_prefix_ << "DoWrite: Output list empty.";
539 if (sm_interface_) { 518 if (sm_interface_) {
540 sm_interface_->GetOutput(); 519 sm_interface_->GetOutput();
541 } 520 }
542 if (output_list_.empty()) { 521 if (output_list_.empty()) {
543 events_ &= ~EPOLLOUT; 522 events_ &= ~EPOLLOUT;
544 } 523 }
545 } 524 }
546 while (!output_list_.empty()) { 525 while (!output_list_.empty()) {
547 VLOG(2) << log_prefix_ << "DoWrite: Items in output list: " 526 VLOG(2) << log_prefix_
548 << output_list_.size(); 527 << "DoWrite: Items in output list: " << output_list_.size();
549 if (bytes_sent >= max_bytes_sent_per_dowrite_) { 528 if (bytes_sent >= max_bytes_sent_per_dowrite_) {
550 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 529 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
551 << " byte sent >= max bytes sent per write: Setting EPOLLOUT: " 530 << " byte sent >= max bytes sent per write: Setting EPOLLOUT: "
552 << bytes_sent; 531 << bytes_sent;
553 events_ |= EPOLLOUT; 532 events_ |= EPOLLOUT;
554 break; 533 break;
555 } 534 }
556 if (sm_interface_ && output_list_.size() < 2) { 535 if (sm_interface_ && output_list_.size() < 2) {
557 sm_interface_->GetOutput(); 536 sm_interface_->GetOutput();
558 } 537 }
559 DataFrame* data_frame = output_list_.front(); 538 DataFrame* data_frame = output_list_.front();
560 const char* bytes = data_frame->data; 539 const char* bytes = data_frame->data;
561 int size = data_frame->size; 540 int size = data_frame->size;
562 bytes += data_frame->index; 541 bytes += data_frame->index;
563 size -= data_frame->index; 542 size -= data_frame->index;
564 DCHECK_GE(size, 0); 543 DCHECK_GE(size, 0);
565 if (size <= 0) { 544 if (size <= 0) {
566 output_list_.pop_front(); 545 output_list_.pop_front();
567 delete data_frame; 546 delete data_frame;
568 continue; 547 continue;
569 } 548 }
570 549
(...skipping 14 matching lines...) Expand all
585 events_ &= ~EPOLLOUT; 564 events_ &= ~EPOLLOUT;
586 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 565 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
587 << "Got EAGAIN while writing"; 566 << "Got EAGAIN while writing";
588 goto done; 567 goto done;
589 case EINTR: 568 case EINTR:
590 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 569 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
591 << "Got EINTR while writing"; 570 << "Got EINTR while writing";
592 continue; 571 continue;
593 default: 572 default:
594 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 573 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
595 << "While calling send, got error: " << stored_errno 574 << "While calling send, got error: " << stored_errno << ": "
596 << ": " << (ssl_?"":strerror(stored_errno)); 575 << (ssl_ ? "" : strerror(stored_errno));
597 goto error_or_close; 576 goto error_or_close;
598 } 577 }
599 } else if (bytes_written > 0) { 578 } else if (bytes_written > 0) {
600 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "Wrote: " 579 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
601 << bytes_written << " bytes"; 580 << "Wrote: " << bytes_written << " bytes";
602 data_frame->index += bytes_written; 581 data_frame->index += bytes_written;
603 bytes_sent += bytes_written; 582 bytes_sent += bytes_written;
604 continue; 583 continue;
605 } else if (bytes_written == -2) { 584 } else if (bytes_written == -2) {
606 // -2 handles SSL_ERROR_WANT_* errors 585 // -2 handles SSL_ERROR_WANT_* errors
607 events_ &= ~EPOLLOUT; 586 events_ &= ~EPOLLOUT;
608 goto done; 587 goto done;
609 } 588 }
610 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT 589 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
611 << "0 bytes written with send call."; 590 << "0 bytes written with send call.";
(...skipping 27 matching lines...) Expand all
639 } 618 }
640 if (fd_ >= 0) { 619 if (fd_ >= 0) {
641 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "Closing connection"; 620 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "Closing connection";
642 close(fd_); 621 close(fd_);
643 fd_ = -1; 622 fd_ = -1;
644 } 623 }
645 read_buffer_.Clear(); 624 read_buffer_.Clear();
646 initialized_ = false; 625 initialized_ = false;
647 protocol_detected_ = false; 626 protocol_detected_ = false;
648 events_ = 0; 627 events_ = 0;
649 for (std::list<DataFrame*>::iterator i = 628 for (std::list<DataFrame*>::iterator i = output_list_.begin();
650 output_list_.begin();
651 i != output_list_.end(); 629 i != output_list_.end();
652 ++i) { 630 ++i) {
653 delete *i; 631 delete *i;
654 } 632 }
655 output_list_.clear(); 633 output_list_.clear();
656 } 634 }
657 635
658 // static 636 // static
659 SMConnection* SMConnection::NewSMConnection(EpollServer* epoll_server, 637 SMConnection* SMConnection::NewSMConnection(EpollServer* epoll_server,
660 SSLState *ssl_state, 638 SSLState* ssl_state,
661 MemoryCache* memory_cache, 639 MemoryCache* memory_cache,
662 FlipAcceptor *acceptor, 640 FlipAcceptor* acceptor,
663 std::string log_prefix) { 641 std::string log_prefix) {
664 return new SMConnection(epoll_server, ssl_state, memory_cache, 642 return new SMConnection(
665 acceptor, log_prefix); 643 epoll_server, ssl_state, memory_cache, acceptor, log_prefix);
666 } 644 }
667 645
668 } // namespace net 646 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/flip_server/sm_connection.h ('k') | net/tools/flip_server/sm_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698