]> prime8.dev >> repos - ttyd.git/commitdiff
http: remove hack for old libwebsocket versions
authorShuanglei Tao <tsl0922@gmail.com>
Thu, 20 Jun 2019 14:14:58 +0000 (22:14 +0800)
committerShuanglei Tao <tsl0922@gmail.com>
Sat, 22 Jun 2019 07:23:24 +0000 (15:23 +0800)
src/http.c
src/protocol.c

index cda1c8d39327804180a6f990903086c841e4457f..e5d702614da3672efecbb004eed4c15d393dbd7f 100644 (file)
@@ -97,16 +97,12 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, voi
                     return 1;
                 if (lws_write(wsi, buffer + LWS_PRE, p - (buffer + LWS_PRE), LWS_WRITE_HTTP_HEADERS) < 0)
                     return 1;
-#if LWS_LIBRARY_VERSION_MAJOR < 3
-                if (n > 0 && lws_write_http(wsi, buf, n) < 0)
-                    return 1;
-#else
                 if (n > 0) {
                     pss->buffer = pss->ptr = strdup(buf);
                     pss->len = n;
                     lws_callback_on_writable(wsi);
+                    break;
                 }
-#endif
                 goto try_to_reuse;
             }
 
@@ -131,16 +127,9 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, voi
                     return 1;
                 if (lws_write(wsi, buffer + LWS_PRE, p - (buffer + LWS_PRE), LWS_WRITE_HTTP_HEADERS) < 0)
                     return 1;
-#if LWS_LIBRARY_VERSION_MAJOR < 3
-                if (lws_write_http(wsi, index_html, index_html_len) < 0)
-                    return 1;
-                goto try_to_reuse;
-#else
                 pss->buffer = pss->ptr = (char *) index_html;
                 pss->len = index_html_len;
                 lws_callback_on_writable(wsi);
-                return 0;
-#endif
             }
             break;
 
index dab0d3a2f20e5c6f6619b73dd910f15efb2607e2..cba239dd405b50d23cc45160fbf7d6fc54bb1ff3 100644 (file)
@@ -312,22 +312,24 @@ callback_tty(struct lws *wsi, enum lws_callback_reasons reason,
                     break;
                 }
                 if (send_initial_message(wsi, client->initial_cmd_index) < 0) {
+                    lwsl_err("failed to send initial message, index: %d\n", client->initial_cmd_index);
                     lws_close_reason(wsi, LWS_CLOSE_STATUS_UNEXPECTED_CONDITION, NULL, 0);
                     return -1;
                 }
                 client->initial_cmd_index++;
                 lws_callback_on_writable(wsi);
-                return 0;
+                break;
             }
             if (client->state != STATE_READY)
                 break;
 
             // read error or client exited, close connection
-            if (client->pty_len <= 0) {
-                lws_close_reason(wsi,
-                                 client->pty_len == 0 ? LWS_CLOSE_STATUS_NORMAL
-                                                       : LWS_CLOSE_STATUS_UNEXPECTED_CONDITION,
-                                 NULL, 0);
+            if (client->pty_len == 0) {
+                lws_close_reason(wsi, LWS_CLOSE_STATUS_NORMAL, NULL, 0);
+                return 1;
+            } else if (client->pty_len < 0) {
+                lwsl_err("read error: %d (%s)\n", errno, strerror(errno));
+                lws_close_reason(wsi, LWS_CLOSE_STATUS_UNEXPECTED_CONDITION, NULL, 0);
                 return -1;
             }