+ n = 0;
+
+ p = pt->serv_buf;
+
+#if defined(LWS_WITH_RANGES)
+ if (wsi->u.http.range.count_ranges && !wsi->u.http.range.inside) {
+
+ lwsl_notice("%s: doing range start %llu\n", __func__, wsi->u.http.range.start);
+
+ if ((long)lws_vfs_file_seek_cur(wsi->u.http.fop_fd,
+ wsi->u.http.range.start -
+ wsi->u.http.filepos) < 0)
+ goto file_had_it;
+
+ wsi->u.http.filepos = wsi->u.http.range.start;
+
+ if (wsi->u.http.range.count_ranges > 1) {
+ n = lws_snprintf((char *)p, context->pt_serv_buf_size,
+ "_lws\x0d\x0a"
+ "Content-Type: %s\x0d\x0a"
+ "Content-Range: bytes %llu-%llu/%llu\x0d\x0a"
+ "\x0d\x0a",
+ wsi->u.http.multipart_content_type,
+ wsi->u.http.range.start,
+ wsi->u.http.range.end,
+ wsi->u.http.range.extent);
+ p += n;
+ }
+
+ wsi->u.http.range.budget = wsi->u.http.range.end -
+ wsi->u.http.range.start + 1;
+ wsi->u.http.range.inside = 1;
+ }
+#endif
+
+ poss = context->pt_serv_buf_size - n;
+
+ /*
+ * if there is a hint about how much we will do well to send at one time,
+ * restrict ourselves to only trying to send that.
+ */
+ if (wsi->protocol->tx_packet_size && poss > wsi->protocol->tx_packet_size)
+ poss = wsi->protocol->tx_packet_size;
+
+#if defined(LWS_WITH_RANGES)
+ if (wsi->u.http.range.count_ranges) {
+ if (wsi->u.http.range.count_ranges > 1)
+ poss -= 7; /* allow for final boundary */
+ if (poss > wsi->u.http.range.budget)
+ poss = wsi->u.http.range.budget;
+ }
+#endif
+ if (wsi->sending_chunked) {
+ /* we need to drop the chunk size in here */
+ p += 10;
+ /* allow for the chunk to grow by 128 in translation */
+ poss -= 10 + 128;
+ }
+
+ if (lws_vfs_file_read(wsi->u.http.fop_fd, &amount, p, poss) < 0)
+ goto file_had_it; /* caller will close */
+
+ //lwsl_notice("amount %ld\n", amount);