Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix an unreply problem with ssl socket

  • Loading branch information...
commit 971c2d451e659ee737712a7ca1d34fbe8da6cce9 1 parent d88ce06
@yaoweibin authored
View
50 modules/ngx_tcp_generic_proxy_module.c
@@ -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;
@@ -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",
@@ -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;
+ }
}
}
View
11 modules/ngx_tcp_websocket_proxy_module.c
@@ -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);
}
Please sign in to comment.
Something went wrong with that request. Please try again.