Skip to content

Commit

Permalink
fix an unreply problem with ssl socket
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoweibin committed Jan 30, 2012
1 parent d88ce06 commit 971c2d4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
50 changes: 31 additions & 19 deletions modules/ngx_tcp_generic_proxy_module.c
Expand Up @@ -308,7 +308,7 @@ ngx_tcp_proxy_handler(ngx_event_t *ev)
ssize_t n;
ngx_buf_t *b;
ngx_err_t err;
ngx_uint_t do_write;
ngx_uint_t do_write, first_read;
ngx_connection_t *c, *src, *dst;
ngx_tcp_session_t *s;
ngx_tcp_proxy_conf_t *pcf;
Expand Down Expand Up @@ -372,6 +372,14 @@ ngx_tcp_proxy_handler(ngx_event_t *ev)
}

do_write = ev->write ? 1 : 0;
/* SSL Need this */
#if (NGX_TCP_SSL)
if (s->connection->ssl) {
first_read = 1;
}
#else
first_read = 0;
#endif

ngx_log_debug4(NGX_LOG_DEBUG_TCP, ev->log, 0,
"tcp proxy handler: %d, #%d > #%d, time:%ui",
Expand Down Expand Up @@ -415,31 +423,35 @@ ngx_tcp_proxy_handler(ngx_event_t *ev)

size = b->end - b->last;

if (size && src->read->ready) {
c->log->action = recv_action;
if (size) {
if (src->read->ready || first_read) {

n = src->recv(src, b->last, size);
err = ngx_socket_errno;
first_read = 0;
c->log->action = recv_action;

ngx_log_debug1(NGX_LOG_DEBUG_TCP, ev->log, 0, "tcp proxy handler recv:%d", n);

if (n == NGX_AGAIN || n == 0) {
break;
}
n = src->recv(src, b->last, size);
err = ngx_socket_errno;

if (n > 0) {
do_write = 1;
b->last += n;
ngx_log_debug1(NGX_LOG_DEBUG_TCP, ev->log, 0, "tcp proxy handler recv:%d", n);

if (read_bytes) {
*read_bytes += n;
if (n == NGX_AGAIN || n == 0) {
break;
}

continue;
}
if (n > 0) {
do_write = 1;
b->last += n;

if (read_bytes) {
*read_bytes += n;
}

if (n == NGX_ERROR) {
src->read->eof = 1;
continue;
}

if (n == NGX_ERROR) {
src->read->eof = 1;
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions modules/ngx_tcp_websocket_proxy_module.c
Expand Up @@ -195,6 +195,17 @@ ngx_tcp_websocket_init_session(ngx_tcp_session_t *s)
ngx_tcp_finalize_session(s);
}

#if (NGX_TCP_SSL)

/* The ssl connection with client may not trigger the read event again,
* So I trigger it in this function. */
if (c->ssl) {
ngx_tcp_websocket_init_protocol(c->read);
return;
}

#endif

if (c->read->ready) {
ngx_tcp_websocket_init_protocol(c->read);
}
Expand Down

0 comments on commit 971c2d4

Please sign in to comment.